Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (empty($image)) return true;
- $dir_upload = COption::GetOptionString("main","upload_dir");
- $docroot = $_SERVER["DOCUMENT_ROOT"];
- $hash = md5(microtime());
- $wm_path = "{$docroot}/local/php_interface/watermark.png";
- $wm = imagecreatefrompng($wm_path);
- $wm_w = imagesx($wm);
- $wm_h = imagesy($wm);
- $wm_a = $wm_w / $wm_h;
- $im = imagecreatefromjpeg($image);
- $im_w = imagesx($im);
- $im_h = imagesy($im);
- $im_a = $im_w / $im_h;
- $image = "{$docroot}/{$dir_upload}/tmp/{$hash}.jpg";
- $ratio = ($im_a > $wm_a) ? $im_w / $wm_w : $im_h / $wm_h;
- imagecopyresampled(
- $im,
- $wm,
- ($im_w - ($wm_w * $ratio)) / 2,
- ($im_h - ($wm_h * $ratio)) / 2,
- 0,
- 0,
- $wm_w * $ratio,
- $wm_h * $ratio,
- $wm_w,
- $wm_h
- );
- imagejpeg($im, $image, 90);
- imagedestroy($im);
- imagedestroy($wm);
- if (!empty($debug)) {
- global $APPLICATION;
- $APPLICATION->throwException( print_r($debug, true) );
- return false;
- }
- return true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement