Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. if (empty($image)) return true;
  2.  
  3.             $dir_upload = COption::GetOptionString("main","upload_dir");
  4.             $docroot = $_SERVER["DOCUMENT_ROOT"];
  5.             $hash = md5(microtime());
  6.  
  7.             $wm_path = "{$docroot}/local/php_interface/watermark.png";
  8.             $wm = imagecreatefrompng($wm_path);
  9.             $wm_w = imagesx($wm);
  10.             $wm_h = imagesy($wm);
  11.             $wm_a = $wm_w / $wm_h;
  12.  
  13.             $im = imagecreatefromjpeg($image);
  14.             $im_w = imagesx($im);
  15.             $im_h = imagesy($im);
  16.             $im_a = $im_w / $im_h;
  17.             $image = "{$docroot}/{$dir_upload}/tmp/{$hash}.jpg";
  18.  
  19.             $ratio = ($im_a > $wm_a) ? $im_w / $wm_w : $im_h / $wm_h;
  20.  
  21.             imagecopyresampled(
  22.                 $im,
  23.                 $wm,
  24.                 ($im_w - ($wm_w * $ratio)) / 2,
  25.                 ($im_h - ($wm_h * $ratio)) / 2,
  26.                 0,
  27.                 0,
  28.                 $wm_w * $ratio,
  29.                 $wm_h * $ratio,
  30.                 $wm_w,
  31.                 $wm_h
  32.             );
  33.  
  34.             imagejpeg($im, $image, 90);
  35.  
  36.             imagedestroy($im);
  37.             imagedestroy($wm);
  38.  
  39.             if (!empty($debug)) {
  40.                 global $APPLICATION;
  41.                 $APPLICATION->throwException( print_r($debug, true) );
  42.                 return false;
  43.             }
  44.             return true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement