Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: Сжатие фото и наложение водяного знака
Форумы портала PHP.SU » » Графика в PHP » Сжатие фото и наложение водяного знака

Страниц (1): [1]
 

1. alexfor - 29 Марта, 2013 - 18:56:53 - перейти к сообщению
Доброго времени суток!
Есть функция copyright_image наложение водяного знака. Происходит ресайз фото и наложение водяного знака. Все работает отлично. Но в этой функции параметры ширины и высоты постоянные. Происходит искажение при загрузке вертикальных фотографий. Подскажите, пожалуйста, как обработать параметры высоты и ширины.

PHP:
скопировать код в буфер обмена
  1.  
  2. $source_of_image = "../images/logo.png";
  3.  
  4. function copyright_image($old_name_of_image, $new_name_of_image)
  5. {
  6.     global $source_of_image;
  7.     list($old_width,$old_height) = getimagesize($old_name_of_image);
  8.     $width_of_image = 500;
  9.     $height_of_image = 375;
  10.     $new = imagecreatetruecolor($width_of_image, $height_of_image);
  11.     $image_source = imagecreatefromjpeg($old_name_of_image);
  12.     imagecopyresampled($new, $image_source, 0, 0, 0, 0, $width_of_image,$height_of_image, $old_width, $old_height);
  13.     $copyright = imagecreatefrompng($source_of_image);
  14.     list($w_width, $w_height) = getimagesize($source_of_image);
  15.     $x_pos = $width_of_image - $w_width;
  16.     $y_pos = $height_of_image - $w_height;
  17.     imagecopy($new, $copyright, $x_pos, $y_pos, 0, 0, $w_width, $w_height);
  18.     imagejpeg($new, $new_name_of_image, 80);
  19.     imagedestroy($new);
  20.     unlink($old_name_of_image);
  21.     //добавил условия обработки
  22.     return true;
  23. }
  24.  
2. IllusionMH - 29 Марта, 2013 - 19:09:32 - перейти к сообщению
заглядывайте в примеры и комментарии к стандартным функциям, там уже многое написалаи до вас
http://php.net/manual/en/functio...opyresampled.php
Пример #2
3. alexfor - 29 Марта, 2013 - 19:43:59 - перейти к сообщению
Я так понял что обработка это:
list($width_orig, $height_orig) = getimagesize($filename);

$ratio_orig = $width_orig/$height_orig;

if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}

Применительно к моему коду куда добавить...
4. IllusionMH - 29 Марта, 2013 - 19:48:01 - перейти к сообщению
alexfor, где-то перед
PHP:
скопировать код в буфер обмена
  1.   $new = imagecreatetruecolor($width_of_image, $height_of_image);

и подставить соответствующий пересчитанные значения
5. alexfor - 29 Марта, 2013 - 19:54:44 - перейти к сообщению
IllusionMH пишет:
alexfor, где-то перед
PHP:
скопировать код в буфер обмена
  1.   $new = imagecreatetruecolor($width_of_image, $height_of_image);

и подставить соответствующий пересчитанные значения


....и поменять имена переменных, естественно. Буду пробывать!
(Добавление)
IllusionMH
Получилось!, все ресайзится корректно, но возник еще один трабл. Фото подается в галерею. Фото соответствует по высоте, по ширине естественно меньше. Отображение в галерее горизонтальных фото - норма. Отображение вертикальных - увеличенное, не соответствует контейнеру, там тоже жестко задаются параметры. Галерея сторонний скрипт. Вряд ли там можно включить такую обработку.
Я слышал, что как-то можно залить недостающие размеры фото слева и справа для того, чтобы подогнать фото под контейнер.
Подскажите, пожалуйста как применительно к этому коду можно применить заливку?
Код рабочий:
PHP:
скопировать код в буфер обмена
  1.  
  2. function copyright_image($filename, $new_name_of_image)
  3. {
  4.    
  5.        
  6.         global $source_of_image;
  7.         $width = 500;
  8.         $height = 375;
  9.        
  10.         list($width_orig,$height_orig) = getimagesize($filename);
  11.         $ratio_orig = $width_orig/$height_orig;
  12.                 if ($width/$height > $ratio_orig) {
  13.                 $width = $height*$ratio_orig;
  14.                 } else {
  15.                 $height = $width/$ratio_orig;
  16.                 }
  17.         $new = imagecreatetruecolor($width, $height);
  18.     $image_source = imagecreatefromjpeg($filename);
  19.        
  20.     imagecopyresampled($new, $image_source, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
  21.     //start_watermark///
  22.         $copyright = imagecreatefrompng($source_of_image);
  23.     list($w_width, $w_height) = getimagesize($source_of_image);
  24.     $x_pos = ($width - $w_width)/2;
  25.     $y_pos = $height - $w_height;
  26.     imagecopy($new, $copyright, $x_pos, $y_pos, 0, 0, $w_width, $w_height);
  27.         //end_watermark
  28.     imagejpeg($new, $new_name_of_image, 80);
  29.     imagedestroy($new);
  30.     unlink($filename);
  31.     return true;
  32. }
  33.  
6. IllusionMH - 29 Марта, 2013 - 21:44:13 - перейти к сообщению
alexfor, ИМХО всегда можно переопределить стили(в CSS), для контейнеров изображений в галереи.
7. alexfor - 29 Марта, 2013 - 21:58:44 - перейти к сообщению
IllusionMH
Да нет, в css размеры изображения не настраиваются. Там несколько свойств, бекраунды, границы и т.д. Там рулит ява, а вызов скрипта идет через:
CODE (javascript):
скопировать код в буфер обмена
  1.  
  2. <script type="text/javascript">
  3.         $(function(){
  4.                 $('#myGallery').galleryView({
  5.                 transition_speed: 1000,                 //INT - duration of panel/frame transition (in milliseconds)
  6.                 transition_interval: 4000,              //INT - delay between panel/frame transitions (in milliseconds)
  7.                 easing: 'swing',                                //STRING - easing method to use for animations (jQuery provides 'swing' or 'linear', more available with jQuery UI or Easing plugin)
  8.                 show_panels: true,                              //BOOLEAN - flag to show or hide panel portion of gallery
  9.                 show_panel_nav: true,                   //BOOLEAN - flag to show or hide panel navigation buttons
  10.                 enable_overlays: false,                 //BOOLEAN - flag to show or hide panel overlays - панель со значком I - туда можно писать инфу
  11.                
  12.                 panel_width: 500,                               //INT - width of gallery panel (in pixels)
  13.                 panel_height: 375,                              //INT - height of gallery panel (in pixels)
  14.                 panel_animation: 'crossfade',   //STRING - animation method for panel transitions (crossfade,fade,slide,none)
  15.                 panel_scale: 'crop',                    //STRING - cropping option for panel images (crop = scale image and fit to aspect ratio determined by panel_width and panel_height, fit = scale image and preserve original aspect ratio)
  16.                 overlay_position: 'bottom',     //STRING - position of panel overlay (bottom, top)
  17.                 pan_images: true,                               //BOOLEAN - flag to allow user to grab/drag oversized images within gallery
  18.                 pan_style: 'track',                             //STRING - panning method (drag = user clicks and drags image to pan, track = image automatically pans based on mouse position
  19.                 pan_smoothness: 15,                             //INT - determines smoothness of tracking pan animation (higher number = smoother)
  20.                 start_frame: 1,                                 //INT - index of panel/frame to show first when gallery loads
  21.                 show_filmstrip: true,                   //BOOLEAN - flag to show or hide filmstrip portion of gallery
  22.                 show_filmstrip_nav: true,               //BOOLEAN - flag indicating whether to display navigation buttons
  23.                 enable_slideshow: true,                 //BOOLEAN - flag indicating whether to display slideshow play/pause button
  24.                 autoplay: true,                             //BOOLEAN - flag to start slideshow on gallery load
  25.                 show_captions: false,                   //BOOLEAN - flag to show or hide frame captions
  26.                 filmstrip_size: 3,                              //INT - number of frames to show in filmstrip-only gallery
  27.                 filmstrip_style: 'scroll',              //STRING - type of filmstrip to use (scroll = display one line of frames, scroll filmstrip if necessary, showall = display multiple rows of frames if necessary)
  28.                 filmstrip_position: 'bottom',   //STRING - position of filmstrip within gallery (bottom, top, left, right)
  29.                 frame_width: 100,                               //INT - width of filmstrip frames (in pixels)
  30.                 frame_height: 100,                              //INT - width of filmstrip frames (in pixels)
  31.                 frame_opacity: 0.5,                     //FLOAT - transparency of non-active frames (1.0 = opaque, 0.0 = transparent, 0.5 - было)
  32.                 frame_scale: 'crop',                    //STRING - cropping option for filmstrip images (same as above). Options are 'crop', 'fit'.
  33.                 frame_gap: 5,                                   //INT - spacing between frames within filmstrip (in pixels)
  34.                 show_infobar: true,                             //BOOLEAN - flag to show or hide infobar
  35.                 infobar_opacity: 1                              //FLOAT - transparency for info bar
  36.                 });
  37.         });
  38. </script>
  39.  

(Добавление)
Решение есть в двух вариантах: (благодарю IllusionMH за помощь). Кнопку нажать не могу, не так много сообщений.

 

Powered by ExBB FM 1.0 RC1