3047 $this->processed =
true;
3048 $return_mode =
false;
3049 $return_content =
null;
3052 $this->file_dst_path =
'';
3053 $this->file_dst_pathname =
'';
3054 $this->file_dst_name =
'';
3055 $this->file_dst_name_body =
'';
3056 $this->file_dst_name_ext =
'';
3059 $this->file_max_size = $this->
getsize($this->file_max_size);
3060 $this->jpeg_size = $this->
getsize($this->jpeg_size);
3067 if (!$this->uploaded) {
3068 $this->error = $this->
translate(
'file_not_uploaded');
3069 $this->processed =
false;
3072 if ($this->processed) {
3073 if (empty($server_path) || is_null($server_path)) {
3074 $this->log .=
'<b>process file and return the content</b><br />';
3075 $return_mode =
true;
3077 if(strtolower(substr(PHP_OS, 0, 3)) ===
'win') {
3078 if (substr($server_path, -1, 1) !=
'\\') $server_path = $server_path .
'\\';
3080 if (substr($server_path, -1, 1) !=
'/') $server_path = $server_path .
'/';
3082 $this->log .=
'<b>process file to ' . $server_path .
'</b><br />';
3086 if ($this->processed) {
3088 if ($this->file_src_size > $this->file_max_size) {
3089 $this->processed =
false;
3092 $this->log .=
'- file size OK<br />';
3096 if ($this->processed) {
3100 if ($this->no_script) {
3103 if ($key = array_search($this->file_src_mime, $this->mime_types)) {
3110 if ((((substr($this->file_src_mime, 0, 5) ==
'text/' && $this->file_src_mime !=
'text/rtf') || strpos($this->file_src_mime,
'javascript') !==
false) && (substr(
$file_src_name, -4) !=
'.txt'))
3111 || preg_match(
'/\.(' . implode(
'|', $this->dangerous) .
')/i', $this->file_src_name)
3113 $this->file_src_mime =
'text/plain';
3121 if ($this->mime_check && empty($this->file_src_mime)) {
3122 $this->processed =
false;
3123 $this->error = $this->
translate(
'no_mime');
3124 }
else if ($this->mime_check && !empty($this->file_src_mime) && strpos($this->file_src_mime,
'/') !==
false) {
3125 list($m1, $m2) = explode(
'/', $this->file_src_mime);
3128 if (!is_array($this->allowed)) $this->allowed = array($this->allowed);
3129 foreach($this->allowed as $k => $v) {
3130 if (strpos($v,
'/') ==
false) {
3136 list($v1, $v2) = explode(
'/', $v);
3137 if (($v1 ==
'*' && $v2 ==
'*') || ($v1 == $m1 && ($v2 == $m2 || $v2 ==
'*'))) {
3143 if (!
$allowed) $this->log .=
'- MIME type and/or extension is not allowed !<br />';
3145 if (!is_array($this->forbidden)) $this->forbidden = array($this->forbidden);
3146 foreach($this->forbidden as $k => $v) {
3147 if (strpos($v,
'/') ==
false) {
3150 $this->log .=
'- extension ' . $v .
' is forbidden !<br />';
3154 list($v1, $v2) = explode(
'/', $v);
3155 if (($v1 ==
'*' && $v2 ==
'*') || ($v1 == $m1 && ($v2 == $m2 || $v2 ==
'*'))) {
3157 $this->log .=
'- MIME type ' . $v .
' is forbidden !<br />';
3163 $this->processed =
false;
3164 $this->error = $this->
translate(
'incorrect_file');
3166 $this->log .=
'- file mime OK : ' . $this->file_src_mime .
'<br />';
3170 $this->log .=
'- file mime (not checked) : ' . $this->file_src_mime .
'<br />';
3175 if ($this->file_is_image) {
3176 if (is_numeric($this->image_src_x) && is_numeric($this->image_src_y)) {
3178 if (!is_null($this->image_max_width) && $this->image_src_x > $this->image_max_width) {
3179 $this->processed =
false;
3180 $this->error = $this->
translate(
'image_too_wide');
3182 if (!is_null($this->image_min_width) && $this->image_src_x < $this->image_min_width) {
3183 $this->processed =
false;
3184 $this->error = $this->
translate(
'image_too_narrow');
3186 if (!is_null($this->image_max_height) && $this->image_src_y > $this->image_max_height) {
3187 $this->processed =
false;
3188 $this->error = $this->
translate(
'image_too_high');
3190 if (!is_null($this->image_min_height) && $this->image_src_y < $this->image_min_height) {
3191 $this->processed =
false;
3192 $this->error = $this->
translate(
'image_too_short');
3194 if (!is_null($this->image_max_ratio) && $ratio > $this->image_max_ratio) {
3195 $this->processed =
false;
3196 $this->error = $this->
translate(
'ratio_too_high');
3198 if (!is_null($this->image_min_ratio) && $ratio < $this->image_min_ratio) {
3199 $this->processed =
false;
3200 $this->error = $this->
translate(
'ratio_too_low');
3202 if (!is_null($this->image_max_pixels) && $this->image_src_pixels > $this->image_max_pixels) {
3203 $this->processed =
false;
3204 $this->error = $this->
translate(
'too_many_pixels');
3206 if (!is_null($this->image_min_pixels) && $this->image_src_pixels < $this->image_min_pixels) {
3207 $this->processed =
false;
3208 $this->error = $this->
translate(
'not_enough_pixels');
3211 $this->log .=
'- no image properties available, can\'t enforce dimension checks : ' . $this->file_src_mime .
'<br />';
3216 if ($this->processed) {
3217 $this->file_dst_path = $server_path;
3223 if ($this->file_overwrite) $this->file_auto_rename =
false;
3225 if ($this->image_convert && $this->file_is_image) {
3227 $this->log .=
'- new file name ext : ' . $this->file_dst_name_ext .
'<br />';
3229 if (!is_null($this->file_new_name_body)) {
3231 $this->log .=
'- new file name body : ' . $this->file_new_name_body .
'<br />';
3233 if (!is_null($this->file_new_name_ext)) {
3235 $this->log .=
'- new file name ext : ' . $this->file_new_name_ext .
'<br />';
3237 if (!is_null($this->file_name_body_add)) {
3239 $this->log .=
'- file name body append : ' . $this->file_name_body_add .
'<br />';
3241 if (!is_null($this->file_name_body_pre)) {
3243 $this->log .=
'- file name body prepend : ' . $this->file_name_body_pre .
'<br />';
3245 if ($this->file_safe_name) {
3246 $this->file_dst_name_body = $this->
sanitize($this->file_dst_name_body);
3247 $this->log .=
'- file name safe format<br />';
3250 $this->log .=
'- destination variables<br />';
3251 if (empty($this->file_dst_path) || is_null($this->file_dst_path)) {
3252 $this->log .=
' file_dst_path : n/a<br />';
3254 $this->log .=
' file_dst_path : ' . $this->file_dst_path .
'<br />';
3256 $this->log .=
' file_dst_name_body : ' . $this->file_dst_name_body .
'<br />';
3257 $this->log .=
' file_dst_name_ext : ' . $this->file_dst_name_ext .
'<br />';
3260 $this->file_dst_name = $this->file_dst_name_body . (!empty($this->file_dst_name_ext) ?
'.' . $this->file_dst_name_ext :
'');
3262 if (!$return_mode) {
3263 if (!$this->file_auto_rename) {
3264 $this->log .=
'- no auto_rename if same filename exists<br />';
3267 $this->log .=
'- checking for auto_rename<br />';
3273 if (substr($this->file_dst_name_body, -1 - strlen($this->file_src_name_ext)) ==
'.' . $this->file_src_name_ext) {
3274 $body = substr($this->file_dst_name_body, 0, strlen($this->file_dst_name_body) - 1 - strlen($this->file_src_name_ext));
3279 while (@file_exists($this->file_dst_pathname)) {
3280 $this->file_dst_name_body = $body .
'_' . $cpt . $ext;
3281 $this->file_dst_name = $this->file_dst_name_body . (!empty($this->file_dst_name_ext) ?
'.' . $this->file_dst_name_ext :
'');
3285 if ($cpt>1) $this->log .=
' auto_rename to ' . $this->file_dst_name .
'<br />';
3288 $this->log .=
'- destination file details<br />';
3289 $this->log .=
' file_dst_name : ' . $this->file_dst_name .
'<br />';
3290 $this->log .=
' file_dst_pathname : ' . $this->file_dst_pathname .
'<br />';
3292 if ($this->file_overwrite) {
3293 $this->log .=
'- no overwrite checking<br />';
3295 if (@file_exists($this->file_dst_pathname)) {
3296 $this->processed =
false;
3297 $this->error = $this->
translate(
'already_exists', array($this->file_dst_name));
3299 $this->log .=
'- ' . $this->file_dst_name .
' doesn\'t exist already<br />';
3305 if ($this->processed) {
3307 if (!empty($this->file_src_temp)) {
3308 $this->log .=
'- use the temp file instead of the original file since it is a second process<br />';
3310 if (!file_exists($this->file_src_pathname)) {
3311 $this->processed =
false;
3312 $this->error = $this->
translate(
'temp_file_missing');
3315 }
else if (!$this->no_upload_check) {
3316 if (!is_uploaded_file($this->file_src_pathname)) {
3317 $this->processed =
false;
3318 $this->error = $this->
translate(
'source_missing');
3322 if (!file_exists($this->file_src_pathname)) {
3323 $this->processed =
false;
3324 $this->error = $this->
translate(
'source_missing');
3329 if (!$return_mode) {
3330 if ($this->processed && !file_exists($this->file_dst_path)) {
3331 if ($this->dir_auto_create) {
3332 $this->log .=
'- ' . $this->file_dst_path .
' doesn\'t exist. Attempting creation:';
3333 if (!$this->
rmkdir($this->file_dst_path, $this->dir_chmod)) {
3334 $this->log .=
' failed<br />';
3335 $this->processed =
false;
3336 $this->error = $this->
translate(
'destination_dir');
3338 $this->log .=
' success<br />';
3341 $this->error = $this->
translate(
'destination_dir_missing');
3345 if ($this->processed && !is_dir($this->file_dst_path)) {
3346 $this->processed =
false;
3347 $this->error = $this->
translate(
'destination_path_not_dir');
3351 $hash = md5($this->file_dst_name_body . rand(1, 1000));
3352 if ($this->processed && !($f = @fopen($this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ?
'.' . $this->file_dst_name_ext :
''),
'a+'))) {
3353 if ($this->dir_auto_chmod) {
3354 $this->log .=
'- ' . $this->file_dst_path .
' is not writeable. Attempting chmod:';
3355 if (!@chmod($this->file_dst_path, $this->dir_chmod)) {
3356 $this->log .=
' failed<br />';
3357 $this->processed =
false;
3358 $this->error = $this->
translate(
'destination_dir_write');
3360 $this->log .=
' success<br />';
3361 if (!($f = @fopen($this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ?
'.' . $this->file_dst_name_ext :
''),
'a+'))) {
3362 $this->processed =
false;
3363 $this->error = $this->
translate(
'destination_dir_write');
3369 $this->processed =
false;
3370 $this->error = $this->
translate(
'destination_path_write');
3373 if ($this->processed) @fclose($f);
3374 @unlink($this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ?
'.' . $this->file_dst_name_ext :
''));
3381 if (!$this->no_upload_check && empty($this->file_src_temp) && !@file_exists($this->file_src_pathname)) {
3382 $this->log .=
'- attempting to use a temp file:';
3383 $hash = md5($this->file_dst_name_body . rand(1, 1000));
3384 if (move_uploaded_file($this->file_src_pathname, $this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ?
'.' . $this->file_dst_name_ext :
''))) {
3385 $this->file_src_pathname = $this->file_dst_path . $hash . (!empty($this->file_dst_name_ext) ?
'.' . $this->file_dst_name_ext :
'');
3387 $this->log .=
' file created<br />';
3388 $this->log .=
' temp file is: ' . $this->file_src_temp .
'<br />';
3390 $this->log .=
' failed<br />';
3391 $this->processed =
false;
3392 $this->error = $this->
translate(
'temp_file');
3398 if ($this->processed) {
3403 if ($this->file_is_image && $this->image_auto_rotate && $this->image_src_type ==
'jpg' && $this->
function_enabled(
'exif_read_data')) {
3404 $exif = @exif_read_data($this->file_src_pathname);
3405 if (is_array($exif) && isset($exif[
'Orientation'])) {
3406 $orientation = $exif[
'Orientation'];
3407 switch($orientation) {
3409 $this->log .=
'- EXIF orientation = 1 : default<br />';
3413 $this->log .=
'- EXIF orientation = 2 : vertical flip<br />';
3417 $this->log .=
'- EXIF orientation = 3 : 180 rotate left<br />';
3421 $this->log .=
'- EXIF orientation = 4 : horizontal flip<br />';
3426 $this->log .=
'- EXIF orientation = 5 : horizontal flip + 90 rotate right<br />';
3430 $this->log .=
'- EXIF orientation = 6 : 90 rotate right<br />';
3435 $this->log .=
'- EXIF orientation = 7 : vertical flip + 90 rotate right<br />';
3439 $this->log .=
'- EXIF orientation = 8 : 90 rotate left<br />';
3442 $this->log .=
'- EXIF orientation = '.$orientation.
' : unknown<br />';
3446 $this->log .=
'- EXIF data is invalid or missing<br />';
3449 if (!$this->image_auto_rotate) {
3450 $this->log .=
'- auto-rotate deactivated<br />';
3451 }
else if (!$this->image_src_type ==
'jpg') {
3452 $this->log .=
'- auto-rotate applies only to JPEG images<br />';
3454 $this->log .=
'- auto-rotate requires function exif_read_data to be enabled<br />';
3459 $image_manipulation = ($this->file_is_image && (
3461 || $this->image_convert !=
''
3462 || is_numeric($this->image_brightness)
3463 || is_numeric($this->image_contrast)
3464 || is_numeric($this->image_opacity)
3465 || is_numeric($this->image_threshold)
3466 || !empty($this->image_tint_color)
3467 || !empty($this->image_overlay_color)
3468 || $this->image_pixelate
3469 || $this->image_unsharp
3470 || !empty($this->image_text)
3471 || $this->image_greyscale
3472 || $this->image_negative
3473 || !empty($this->image_watermark)
3474 || $auto_rotate || $auto_flip
3475 || is_numeric($this->image_rotate)
3476 || is_numeric($this->jpeg_size)
3477 || !empty($this->image_flip)
3478 || !empty($this->image_crop)
3479 || !empty($this->image_precrop)
3480 || !empty($this->image_border)
3481 || !empty($this->image_border_transparent)
3482 || $this->image_frame > 0
3483 || $this->image_bevel > 0
3488 if ($image_manipulation && !@getimagesize($this->file_src_pathname)) {
3489 $this->log .=
'- the file is not an image!<br />';
3490 $image_manipulation =
false;
3493 if ($image_manipulation) {
3496 @ini_set(
"gd.jpeg_ignore_warning", 1);
3499 if ($this->processed && !($f = @fopen($this->file_src_pathname,
'r'))) {
3500 $this->processed =
false;
3501 $this->error = $this->
translate(
'source_not_readable');
3507 $this->log .=
'- image resizing or conversion wanted<br />';
3509 switch($this->image_src_type) {
3512 $this->processed =
false;
3513 $this->error = $this->
translate(
'no_create_support', array(
'JPEG'));
3515 $image_src = @imagecreatefromjpeg($this->file_src_pathname);
3517 $this->processed =
false;
3518 $this->error = $this->
translate(
'create_error', array(
'JPEG'));
3520 $this->log .=
'- source image is JPEG<br />';
3526 $this->processed =
false;
3527 $this->error = $this->
translate(
'no_create_support', array(
'PNG'));
3529 $image_src = @imagecreatefrompng($this->file_src_pathname);
3531 $this->processed =
false;
3532 $this->error = $this->
translate(
'create_error', array(
'PNG'));
3534 $this->log .=
'- source image is PNG<br />';
3540 $this->processed =
false;
3541 $this->error = $this->
translate(
'no_create_support', array(
'WEBP'));
3543 $image_src = @imagecreatefromwebp($this->file_src_pathname);
3545 $this->processed =
false;
3546 $this->error = $this->
translate(
'create_error', array(
'WEBP'));
3548 $this->log .=
'- source image is WEBP<br />';
3554 $this->processed =
false;
3555 $this->error = $this->
translate(
'no_create_support', array(
'GIF'));
3557 $image_src = @imagecreatefromgif($this->file_src_pathname);
3559 $this->processed =
false;
3560 $this->error = $this->
translate(
'create_error', array(
'GIF'));
3562 $this->log .=
'- source image is GIF<br />';
3567 if (!method_exists($this,
'imagecreatefrombmp')) {
3568 $this->processed =
false;
3569 $this->error = $this->
translate(
'no_create_support', array(
'BMP'));
3573 $this->processed =
false;
3574 $this->error = $this->
translate(
'create_error', array(
'BMP'));
3576 $this->log .=
'- source image is BMP<br />';
3581 $this->processed =
false;
3582 $this->error = $this->
translate(
'source_invalid');
3585 $this->processed =
false;
3586 $this->error = $this->
translate(
'gd_missing');
3589 if ($this->processed && $image_src) {
3592 if (empty($this->image_convert)) {
3593 $this->log .=
'- setting destination file type to ' . $this->image_src_type .
'<br />';
3596 $this->log .=
'- requested destination file type is ' . $this->image_convert .
'<br />';
3599 if (!in_array($this->image_convert, $this->image_supported)) {
3600 $this->log .=
'- destination file type ' . $this->image_convert .
' is not supported; switching to jpg<br />';
3601 $this->image_convert =
'jpg';
3605 if ($this->image_convert !=
'png' && $this->image_convert !=
'webp' && $this->image_convert !=
'gif' && !empty($this->image_default_color) && empty($this->image_background_color)) $this->image_background_color =
$this->image_default_color;
3607 if (empty($this->image_default_color)) $this->image_default_color =
'#FFFFFF';
3609 $this->image_src_x = imagesx($image_src);
3610 $this->image_src_y = imagesy($image_src);
3614 if (!imageistruecolor($image_src)) {
3615 $this->log .=
'- image is detected as having a palette<br />';
3616 $this->image_is_palette =
true;
3617 $this->image_transparent_color = imagecolortransparent($image_src);
3618 if ($this->image_transparent_color >= 0 && imagecolorstotal($image_src) > $this->image_transparent_color) {
3619 $this->image_is_transparent =
true;
3620 $this->log .=
' palette image is detected as transparent<br />';
3623 $this->log .=
' convert palette image to true color<br />';
3624 $true_color = imagecreatetruecolor($this->image_src_x, $this->image_src_y);
3625 imagealphablending($true_color,
false);
3626 imagesavealpha($true_color,
true);
3629 if ($this->image_transparent_color >= 0 && imagecolorat($image_src, $x, $y) == $this->image_transparent_color) {
3630 imagesetpixel($true_color, $x, $y, 127 << 24);
3632 $rgb = imagecolorsforindex($image_src, imagecolorat($image_src, $x, $y));
3633 imagesetpixel($true_color, $x, $y, ($rgb[
'alpha'] << 24) | ($rgb[
'red'] << 16) | ($rgb[
'green'] << 8) | $rgb[
'blue']);
3638 imagealphablending($image_src,
false);
3639 imagesavealpha($image_src,
true);
3640 $this->image_is_palette =
false;
3643 $image_dst = & $image_src;
3646 if ($gd_version >= 2 && !empty($auto_flip)) {
3647 $this->log .=
'- auto-flip image : ' . ($auto_flip ==
'v' ?
'vertical' :
'horizontal') .
'<br />';
3648 $tmp = $this->
imagecreatenew($this->image_src_x, $this->image_src_y);
3651 if (strpos($auto_flip,
'v') !==
false) {
3652 imagecopy($tmp, $image_dst, $this->image_src_x - $x - 1, $y, $x, $y, 1, 1);
3654 imagecopy($tmp, $image_dst, $x, $this->image_src_y - $y - 1, $x, $y, 1, 1);
3663 if ($gd_version >= 2 && is_numeric($auto_rotate)) {
3664 if (!in_array($auto_rotate, array(0, 90, 180, 270))) $auto_rotate = 0;
3665 if ($auto_rotate != 0) {
3666 if ($auto_rotate == 90 || $auto_rotate == 270) {
3667 $tmp = $this->
imagecreatenew($this->image_src_y, $this->image_src_x);
3669 $tmp = $this->
imagecreatenew($this->image_src_x, $this->image_src_y);
3671 $this->log .=
'- auto-rotate image : ' . $auto_rotate .
'<br />';
3674 if ($auto_rotate == 90) {
3675 imagecopy($tmp, $image_dst, $y, $x, $x, $this->image_src_y - $y - 1, 1, 1);
3676 }
else if ($auto_rotate == 180) {
3677 imagecopy($tmp, $image_dst, $x, $y, $this->image_src_x - $x - 1, $this->image_src_y - $y - 1, 1, 1);
3678 }
else if ($auto_rotate == 270) {
3679 imagecopy($tmp, $image_dst, $y, $x, $this->image_src_x - $x - 1, $y, 1, 1);
3681 imagecopy($tmp, $image_dst, $x, $y, $x, $y, 1, 1);
3685 if ($auto_rotate == 90 || $auto_rotate == 270) {
3688 $this->image_src_x = $t;
3696 if ((!empty($this->image_precrop))) {
3697 list($ct, $cr, $cb, $cl) = $this->
getoffsets($this->image_precrop, $this->image_src_x, $this->image_src_y,
true,
true);
3698 $this->log .=
'- pre-crop image : ' . $ct .
' ' . $cr .
' ' . $cb .
' ' . $cl .
' <br />';
3699 $this->image_src_x = $this->image_src_x - $cl - $cr;
3700 $this->image_src_y = $this->image_src_y - $ct - $cb;
3701 if ($this->image_src_x < 1) $this->image_src_x = 1;
3702 if ($this->image_src_y < 1) $this->image_src_y = 1;
3703 $tmp = $this->
imagecreatenew($this->image_src_x, $this->image_src_y);
3706 imagecopy($tmp, $image_dst, 0, 0, $cl, $ct, $this->image_src_x, $this->image_src_y);
3709 if ($ct < 0 || $cr < 0 || $cb < 0 || $cl < 0 ) {
3711 if (!empty($this->image_background_color)) {
3712 list($red, $green, $blue) = $this->
getcolors($this->image_background_color);
3713 $fill = imagecolorallocate($tmp, $red, $green, $blue);
3715 $fill = imagecolorallocatealpha($tmp, 0, 0, 0, 127);
3718 if ($ct < 0) imagefilledrectangle($tmp, 0, 0, $this->image_src_x, -$ct, $fill);
3719 if ($cr < 0) imagefilledrectangle($tmp, $this->image_src_x + $cr, 0, $this->image_src_x, $this->image_src_y, $fill);
3720 if ($cb < 0) imagefilledrectangle($tmp, 0, $this->image_src_y + $cb, $this->image_src_x, $this->image_src_y, $fill);
3721 if ($cl < 0) imagefilledrectangle($tmp, 0, 0, -$cl, $this->image_src_y, $fill);
3729 if ($this->image_resize) {
3730 $this->log .=
'- resizing...<br />';
3735 if ($this->image_ratio_no_zoom_in) {
3736 $this->image_ratio =
true;
3737 $this->image_no_enlarging =
true;
3738 }
else if ($this->image_ratio_no_zoom_out) {
3739 $this->image_ratio =
true;
3740 $this->image_no_shrinking =
true;
3744 if ($this->image_ratio_x) {
3745 $this->log .=
' calculate x size<br />';
3746 $this->image_dst_x = round(($this->image_src_x * $this->image_y) / $this->image_src_y);
3750 }
else if ($this->image_ratio_y) {
3751 $this->log .=
' calculate y size<br />';
3753 $this->image_dst_y = round(($this->image_src_y * $this->image_x) / $this->image_src_x);
3756 }
else if (is_numeric($this->image_ratio_pixels)) {
3757 $this->log .=
' calculate x/y size to match a number of pixels<br />';
3759 $diff = sqrt($this->image_ratio_pixels / $pixels);
3760 $this->image_dst_x = round($this->image_src_x * $diff);
3761 $this->image_dst_y = round($this->image_src_y * $diff);
3764 }
else if ($this->image_ratio_crop) {
3765 if (!is_string($this->image_ratio_crop)) $this->image_ratio_crop =
'';
3766 $this->image_ratio_crop = strtolower($this->image_ratio_crop);
3767 if (($this->image_src_x/$this->image_x) > ($this->image_src_y/$this->image_y)) {
3769 $this->image_dst_x = intval($this->image_src_x*($this->image_y / $this->image_src_y));
3770 $ratio_crop = array();
3772 if (strpos($this->image_ratio_crop,
'l') !==
false) {
3773 $ratio_crop[
'l'] = 0;
3774 $ratio_crop[
'r'] = $ratio_crop[
'x'];
3775 }
else if (strpos($this->image_ratio_crop,
'r') !==
false) {
3776 $ratio_crop[
'l'] = $ratio_crop[
'x'];
3777 $ratio_crop[
'r'] = 0;
3779 $ratio_crop[
'l'] = round($ratio_crop[
'x']/2);
3780 $ratio_crop[
'r'] = $ratio_crop[
'x'] - $ratio_crop[
'l'];
3782 $this->log .=
' ratio_crop_x : ' . $ratio_crop[
'x'] .
' (' . $ratio_crop[
'l'] .
';' . $ratio_crop[
'r'] .
')<br />';
3783 if (is_null($this->image_crop)) $this->image_crop = array(0, 0, 0, 0);
3786 $this->image_dst_y = intval($this->image_src_y*($this->image_x / $this->image_src_x));
3787 $ratio_crop = array();
3789 if (strpos($this->image_ratio_crop,
't') !==
false) {
3790 $ratio_crop[
't'] = 0;
3791 $ratio_crop[
'b'] = $ratio_crop[
'y'];
3792 }
else if (strpos($this->image_ratio_crop,
'b') !==
false) {
3793 $ratio_crop[
't'] = $ratio_crop[
'y'];
3794 $ratio_crop[
'b'] = 0;
3796 $ratio_crop[
't'] = round($ratio_crop[
'y']/2);
3797 $ratio_crop[
'b'] = $ratio_crop[
'y'] - $ratio_crop[
't'];
3799 $this->log .=
' ratio_crop_y : ' . $ratio_crop[
'y'] .
' (' . $ratio_crop[
't'] .
';' . $ratio_crop[
'b'] .
')<br />';
3800 if (is_null($this->image_crop)) $this->image_crop = array(0, 0, 0, 0);
3804 }
else if ($this->image_ratio_fill) {
3805 if (!is_string($this->image_ratio_fill)) $this->image_ratio_fill =
'';
3806 $this->image_ratio_fill = strtolower($this->image_ratio_fill);
3807 if (($this->image_src_x/$this->image_x) < ($this->image_src_y/$this->image_y)) {
3809 $this->image_dst_x = intval($this->image_src_x*($this->image_y / $this->image_src_y));
3810 $ratio_crop = array();
3812 if (strpos($this->image_ratio_fill,
'l') !==
false) {
3813 $ratio_crop[
'l'] = 0;
3814 $ratio_crop[
'r'] = $ratio_crop[
'x'];
3815 }
else if (strpos($this->image_ratio_fill,
'r') !==
false) {
3816 $ratio_crop[
'l'] = $ratio_crop[
'x'];
3817 $ratio_crop[
'r'] = 0;
3819 $ratio_crop[
'l'] = round($ratio_crop[
'x']/2);
3820 $ratio_crop[
'r'] = $ratio_crop[
'x'] - $ratio_crop[
'l'];
3822 $this->log .=
' ratio_fill_x : ' . $ratio_crop[
'x'] .
' (' . $ratio_crop[
'l'] .
';' . $ratio_crop[
'r'] .
')<br />';
3823 if (is_null($this->image_crop)) $this->image_crop = array(0, 0, 0, 0);
3826 $this->image_dst_y = intval($this->image_src_y*($this->image_x / $this->image_src_x));
3827 $ratio_crop = array();
3829 if (strpos($this->image_ratio_fill,
't') !==
false) {
3830 $ratio_crop[
't'] = 0;
3831 $ratio_crop[
'b'] = $ratio_crop[
'y'];
3832 }
else if (strpos($this->image_ratio_fill,
'b') !==
false) {
3833 $ratio_crop[
't'] = $ratio_crop[
'y'];
3834 $ratio_crop[
'b'] = 0;
3836 $ratio_crop[
't'] = round($ratio_crop[
'y']/2);
3837 $ratio_crop[
'b'] = $ratio_crop[
'y'] - $ratio_crop[
't'];
3839 $this->log .=
' ratio_fill_y : ' . $ratio_crop[
'y'] .
' (' . $ratio_crop[
't'] .
';' . $ratio_crop[
'b'] .
')<br />';
3840 if (is_null($this->image_crop)) $this->image_crop = array(0, 0, 0, 0);
3844 }
else if ($this->image_ratio) {
3845 if (($this->image_src_x/$this->image_x) > ($this->image_src_y/$this->image_y)) {
3847 $this->image_dst_y = intval($this->image_src_y*($this->image_x / $this->image_src_x));
3850 $this->image_dst_x = intval($this->image_src_x*($this->image_y / $this->image_src_y));
3855 $this->log .=
' use plain sizes<br />';
3860 if ($this->image_dst_x < 1) $this->image_dst_x = 1;
3861 if ($this->image_dst_y < 1) $this->image_dst_y = 1;
3862 $this->log .=
' image_src_x y : ' . $this->image_src_x .
' x ' . $this->image_src_y .
'<br />';
3863 $this->log .=
' image_dst_x y : ' . $this->image_dst_x .
' x ' . $this->image_dst_y .
'<br />';
3866 if ($this->image_no_enlarging && ($this->image_src_x < $this->image_dst_x || $this->image_src_y < $this->image_dst_y)) {
3867 $this->log .=
' cancel resizing, as it would enlarge the image!<br />';
3874 if ($this->image_no_shrinking && ($this->image_src_x > $this->image_dst_x || $this->image_src_y > $this->image_dst_y)) {
3875 $this->log .=
' cancel resizing, as it would shrink the image!<br />';
3882 if ($this->image_dst_x != $this->image_src_x || $this->image_dst_y != $this->image_src_y) {
3883 $this->image_dst_x = (int) $this->image_dst_x;
3884 $this->image_dst_y = (int) $this->image_dst_y;
3885 $tmp = $this->
imagecreatenew($this->image_dst_x, $this->image_dst_y);
3887 if ($gd_version >= 2) {
3888 $res = imagecopyresampled($tmp, $image_src, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_src_x, $this->image_src_y);
3890 $res = imagecopyresized($tmp, $image_src, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_src_x, $this->image_src_y);
3893 $this->log .=
' resized image object created<br />';
3904 if ((!empty($this->image_crop) || !is_null($ratio_crop))) {
3905 list($ct, $cr, $cb, $cl) = $this->
getoffsets($this->image_crop, $this->image_dst_x, $this->image_dst_y,
true,
true);
3907 if (!is_null($ratio_crop)) {
3908 if (array_key_exists(
't', $ratio_crop)) $ct += $ratio_crop[
't'];
3909 if (array_key_exists(
'r', $ratio_crop)) $cr += $ratio_crop[
'r'];
3910 if (array_key_exists(
'b', $ratio_crop)) $cb += $ratio_crop[
'b'];
3911 if (array_key_exists(
'l', $ratio_crop)) $cl += $ratio_crop[
'l'];
3913 if ($ct != 0 || $cr != 0 || $cb != 0 || $cl != 0) {
3914 $this->log .=
'- crop image : ' . $ct .
' ' . $cr .
' ' . $cb .
' ' . $cl .
' <br />';
3915 $this->image_dst_x = $this->image_dst_x - $cl - $cr;
3916 $this->image_dst_y = $this->image_dst_y - $ct - $cb;
3917 if ($this->image_dst_x < 1) $this->image_dst_x = 1;
3918 if ($this->image_dst_y < 1) $this->image_dst_y = 1;
3919 $tmp = $this->
imagecreatenew($this->image_dst_x, $this->image_dst_y);
3922 imagecopy($tmp, $image_dst, 0, 0, $cl, $ct, $this->image_dst_x, $this->image_dst_y);
3925 if ($ct < 0 || $cr < 0 || $cb < 0 || $cl < 0 ) {
3927 if (!empty($this->image_background_color)) {
3928 list($red, $green, $blue) = $this->
getcolors($this->image_background_color);
3929 $fill = imagecolorallocate($tmp, $red, $green, $blue);
3931 $fill = imagecolorallocatealpha($tmp, 0, 0, 0, 127);
3934 if ($ct < 0) imagefilledrectangle($tmp, 0, 0, $this->image_dst_x, -$ct-1, $fill);
3935 if ($cr < 0) imagefilledrectangle($tmp, $this->image_dst_x + $cr, 0, $this->image_dst_x, $this->image_dst_y, $fill);
3936 if ($cb < 0) imagefilledrectangle($tmp, 0, $this->image_dst_y + $cb, $this->image_dst_x, $this->image_dst_y, $fill);
3937 if ($cl < 0) imagefilledrectangle($tmp, 0, 0, -$cl-1, $this->image_dst_y, $fill);
3946 if ($gd_version >= 2 && !empty($this->image_flip)) {
3947 $this->image_flip = strtolower($this->image_flip);
3948 $this->log .=
'- flip image : ' . $this->image_flip .
'<br />';
3949 $tmp = $this->
imagecreatenew($this->image_dst_x, $this->image_dst_y);
3952 if (strpos($this->image_flip,
'v') !==
false) {
3953 imagecopy($tmp, $image_dst, $this->image_dst_x - $x - 1, $y, $x, $y, 1, 1);
3955 imagecopy($tmp, $image_dst, $x, $this->image_dst_y - $y - 1, $x, $y, 1, 1);
3964 if ($gd_version >= 2 && is_numeric($this->image_rotate)) {
3965 if (!in_array($this->image_rotate, array(0, 90, 180, 270))) $this->image_rotate = 0;
3966 if ($this->image_rotate != 0) {
3967 if ($this->image_rotate == 90 || $this->image_rotate == 270) {
3968 $tmp = $this->
imagecreatenew($this->image_dst_y, $this->image_dst_x);
3970 $tmp = $this->
imagecreatenew($this->image_dst_x, $this->image_dst_y);
3972 $this->log .=
'- rotate image : ' . $this->image_rotate .
'<br />';
3975 if ($this->image_rotate == 90) {
3976 imagecopy($tmp, $image_dst, $y, $x, $x, $this->image_dst_y - $y - 1, 1, 1);
3977 }
else if ($this->image_rotate == 180) {
3978 imagecopy($tmp, $image_dst, $x, $y, $this->image_dst_x - $x - 1, $this->image_dst_y - $y - 1, 1, 1);
3979 }
else if ($this->image_rotate == 270) {
3980 imagecopy($tmp, $image_dst, $y, $x, $this->image_dst_x - $x - 1, $y, 1, 1);
3982 imagecopy($tmp, $image_dst, $x, $y, $x, $y, 1, 1);
3986 if ($this->image_rotate == 90 || $this->image_rotate == 270) {
3989 $this->image_dst_x = $t;
3997 if ((is_numeric($this->image_pixelate) && $this->image_pixelate > 0)) {
3998 $this->log .=
'- pixelate image (' . $this->image_pixelate .
'px)<br />';
3999 $filter = $this->
imagecreatenew($this->image_dst_x, $this->image_dst_y);
4000 if ($gd_version >= 2) {
4001 imagecopyresampled($filter, $image_dst, 0, 0, 0, 0, round($this->image_dst_x / $this->image_pixelate), round($this->image_dst_y / $this->image_pixelate), $this->image_dst_x, $this->image_dst_y);
4002 imagecopyresampled($image_dst, $filter, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, round($this->image_dst_x / $this->image_pixelate), round($this->image_dst_y / $this->image_pixelate));
4004 imagecopyresized($filter, $image_dst, 0, 0, 0, 0, round($this->image_dst_x / $this->image_pixelate), round($this->image_dst_y / $this->image_pixelate), $this->image_dst_x, $this->image_dst_y);
4005 imagecopyresized($image_dst, $filter, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, round($this->image_dst_x / $this->image_pixelate), round($this->image_dst_y / $this->image_pixelate));
4011 if ($gd_version >= 2 && $this->image_unsharp && is_numeric($this->image_unsharp_amount) && is_numeric($this->image_unsharp_radius) && is_numeric($this->image_unsharp_threshold)) {
4016 if ($this->image_unsharp_amount > 500) $this->image_unsharp_amount = 500;
4017 $this->image_unsharp_amount = $this->image_unsharp_amount * 0.016;
4018 if ($this->image_unsharp_radius > 50) $this->image_unsharp_radius = 50;
4019 $this->image_unsharp_radius = $this->image_unsharp_radius * 2;
4020 if ($this->image_unsharp_threshold > 255) $this->image_unsharp_threshold = 255;
4021 $this->image_unsharp_radius = abs(round($this->image_unsharp_radius));
4022 if ($this->image_unsharp_radius != 0) {
4023 $this->image_dst_x = imagesx($image_dst); $this->image_dst_y = imagesy($image_dst);
4024 $canvas = $this->
imagecreatenew($this->image_dst_x, $this->image_dst_y,
false,
true);
4025 $blur = $this->
imagecreatenew($this->image_dst_x, $this->image_dst_y,
false,
true);
4027 $matrix = array(array( 1, 2, 1 ), array( 2, 4, 2 ), array( 1, 2, 1 ));
4028 imagecopy($blur, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y);
4029 imageconvolution($blur, $matrix, 16, 0);
4032 imagecopy($blur, $image_dst, 0, 0, 1, 0, $this->image_dst_x - 1, $this->image_dst_y);
4033 $this->
imagecopymergealpha($blur, $image_dst, 1, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, 50);
4034 $this->
imagecopymergealpha($blur, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, 50);
4035 imagecopy($canvas, $blur, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y);
4036 $this->
imagecopymergealpha($blur, $canvas, 0, 0, 0, 1, $this->image_dst_x, $this->image_dst_y - 1, 33.33333 );
4037 $this->
imagecopymergealpha($blur, $canvas, 0, 1, 0, 0, $this->image_dst_x, $this->image_dst_y, 25);
4041 if($this->image_unsharp_threshold>0) {
4042 for ($x = 0; $x < $this->image_dst_x-1; $x++) {
4044 $p_orig = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4045 $p_blur = imagecolorsforindex($blur, imagecolorat($blur, $x, $y));
4046 $p_new[
'red'] = (abs($p_orig[
'red'] - $p_blur[
'red']) >=
$this->image_unsharp_threshold) ? max(0, min(255, ($this->image_unsharp_amount * ($p_orig[
'red'] - $p_blur[
'red'])) + $p_orig[
'red'])) : $p_orig[
'red'];
4047 $p_new[
'green'] = (abs($p_orig[
'green'] - $p_blur[
'green']) >=
$this->image_unsharp_threshold) ? max(0, min(255, ($this->image_unsharp_amount * ($p_orig[
'green'] - $p_blur[
'green'])) + $p_orig[
'green'])) : $p_orig[
'green'];
4048 $p_new[
'blue'] = (abs($p_orig[
'blue'] - $p_blur[
'blue']) >=
$this->image_unsharp_threshold) ? max(0, min(255, ($this->image_unsharp_amount * ($p_orig[
'blue'] - $p_blur[
'blue'])) + $p_orig[
'blue'])) : $p_orig[
'blue'];
4049 $p_new[
'alpha'] = max(-127, min(127, $p_orig[
'alpha']));
4050 if (($p_orig[
'red'] != $p_new[
'red']) || ($p_orig[
'green'] != $p_new[
'green']) || ($p_orig[
'blue'] != $p_new[
'blue'])) {
4051 $color = imagecolorallocatealpha($image_dst, (
int) $p_new[
'red'], (
int) $p_new[
'green'], (
int) $p_new[
'blue'], (
int) $p_new[
'alpha']);
4052 imagesetpixel($image_dst, $x, $y, $color);
4059 $p_orig = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4060 $p_blur = imagecolorsforindex($blur, imagecolorat($blur, $x, $y));
4061 $p_new[
'red'] = ($this->image_unsharp_amount * ($p_orig[
'red'] - $p_blur[
'red'])) + $p_orig[
'red'];
4062 if ($p_new[
'red']>255) { $p_new[
'red']=255; } elseif ($p_new[
'red']<0) { $p_new[
'red']=0; }
4063 $p_new[
'green'] = ($this->image_unsharp_amount * ($p_orig[
'green'] - $p_blur[
'green'])) + $p_orig[
'green'];
4064 if ($p_new[
'green']>255) { $p_new[
'green']=255; } elseif ($p_new[
'green']<0) { $p_new[
'green']=0; }
4065 $p_new[
'blue'] = ($this->image_unsharp_amount * ($p_orig[
'blue'] - $p_blur[
'blue'])) + $p_orig[
'blue'];
4066 if ($p_new[
'blue']>255) { $p_new[
'blue']=255; } elseif ($p_new[
'blue']<0) { $p_new[
'blue']=0; }
4067 $p_new[
'alpha'] = round(max(-127, min(127, $p_orig[
'alpha'])));
4068 $color = imagecolorallocatealpha($image_dst, (
int) $p_new[
'red'], (
int) $p_new[
'green'], (
int) $p_new[
'blue'], (
int) $p_new[
'alpha']);
4069 imagesetpixel($image_dst, $x, $y, $color);
4079 if ($gd_version >= 2 && (is_numeric($this->image_overlay_opacity) && $this->image_overlay_opacity > 0 && !empty($this->image_overlay_color))) {
4080 $this->log .=
'- apply color overlay<br />';
4081 list($red, $green, $blue) = $this->
getcolors($this->image_overlay_color);
4082 $filter = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
4083 $color = imagecolorallocate($filter, $red, $green, $blue);
4084 imagefilledrectangle($filter, 0, 0, $this->image_dst_x, $this->image_dst_y, $color);
4085 $this->
imagecopymergealpha($image_dst, $filter, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_overlay_opacity);
4090 if ($gd_version >= 2 && ($this->image_negative || $this->image_greyscale || is_numeric($this->image_threshold)|| is_numeric($this->image_brightness) || is_numeric($this->image_contrast) || !empty($this->image_tint_color))) {
4091 $this->log .=
'- apply tint, light, contrast correction, negative, greyscale and threshold<br />';
4092 if (!empty($this->image_tint_color)) list($tint_red, $tint_green, $tint_blue) = $this->
getcolors($this->image_tint_color);
4096 if ($this->image_greyscale) {
4097 $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4098 $r = $g = $b = round((0.2125 * $pixel[
'red']) + (0.7154 * $pixel[
'green']) + (0.0721 * $pixel[
'blue']));
4099 $alpha = round(max(-127, min(127, $pixel[
'alpha'])));
4100 $color = imagecolorallocatealpha($image_dst, (
int) $r, (
int) $g, (
int) $b, (
int) $alpha);
4101 imagesetpixel($image_dst, $x, $y, $color);
4102 unset($color); unset($pixel);
4104 if (is_numeric($this->image_threshold)) {
4105 $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4106 $c = (round($pixel[
'red'] + $pixel[
'green'] + $pixel[
'blue']) / 3) - 127;
4107 $r = $g = $b = ($c > $this->image_threshold ? 255 : 0);
4108 $alpha = round(max(-127, min(127, $pixel[
'alpha'])));
4109 $color = imagecolorallocatealpha($image_dst, (
int) $r, (
int) $g, (
int) $b, (
int) $alpha);
4110 imagesetpixel($image_dst, $x, $y, $color);
4111 unset($color); unset($pixel);
4113 if (is_numeric($this->image_brightness)) {
4114 $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4115 $r = max(min(round($pixel[
'red'] + (($this->image_brightness * 2))), 255), 0);
4116 $g = max(min(round($pixel[
'green'] + (($this->image_brightness * 2))), 255), 0);
4117 $b = max(min(round($pixel[
'blue'] + (($this->image_brightness * 2))), 255), 0);
4118 $alpha = round(max(-127, min(127, $pixel[
'alpha'])));
4119 $color = imagecolorallocatealpha($image_dst, (
int) $r, (
int) $g, (
int) $b, (
int) $alpha);
4120 imagesetpixel($image_dst, $x, $y, $color);
4121 unset($color); unset($pixel);
4123 if (is_numeric($this->image_contrast)) {
4124 $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4125 $r = max(min(round(($this->image_contrast + 128) * $pixel[
'red'] / 128), 255), 0);
4126 $g = max(min(round(($this->image_contrast + 128) * $pixel[
'green'] / 128), 255), 0);
4127 $b = max(min(round(($this->image_contrast + 128) * $pixel[
'blue'] / 128), 255), 0);
4128 $alpha = round(max(-127, min(127, $pixel[
'alpha'])));
4129 $color = imagecolorallocatealpha($image_dst, (
int) $r, (
int) $g, (
int) $b, (
int) $alpha);
4130 imagesetpixel($image_dst, $x, $y, $color);
4131 unset($color); unset($pixel);
4133 if (!empty($this->image_tint_color)) {
4134 $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4135 $r = min(round($tint_red * $pixel[
'red'] / 169), 255);
4136 $g = min(round($tint_green * $pixel[
'green'] / 169), 255);
4137 $b = min(round($tint_blue * $pixel[
'blue'] / 169), 255);
4138 $alpha = round(max(-127, min(127, $pixel[
'alpha'])));
4139 $color = imagecolorallocatealpha($image_dst, (
int) $r, (
int) $g, (
int) $b, (
int) $alpha);
4140 imagesetpixel($image_dst, $x, $y, $color);
4141 unset($color); unset($pixel);
4143 if (!empty($this->image_negative)) {
4144 $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4145 $r = round(255 - $pixel[
'red']);
4146 $g = round(255 - $pixel[
'green']);
4147 $b = round(255 - $pixel[
'blue']);
4148 $alpha = round(max(-127, min(127, $pixel[
'alpha'])));
4149 $color = imagecolorallocatealpha($image_dst, (
int) $r, (
int) $g, (
int) $b, (
int) $alpha);
4150 imagesetpixel($image_dst, $x, $y, $color);
4151 unset($color); unset($pixel);
4158 if ($gd_version >= 2 && !empty($this->image_border)) {
4159 list($ct, $cr, $cb, $cl) = $this->
getoffsets($this->image_border, $this->image_dst_x, $this->image_dst_y,
true,
false);
4160 $this->log .=
'- add border : ' . $ct .
' ' . $cr .
' ' . $cb .
' ' . $cl .
'<br />';
4161 $this->image_dst_x = $this->image_dst_x + $cl + $cr;
4162 $this->image_dst_y = $this->image_dst_y + $ct + $cb;
4163 if (!empty($this->image_border_color)) list($red, $green, $blue) = $this->
getcolors($this->image_border_color);
4164 $opacity = (is_numeric($this->image_border_opacity) ? (int) (127 - $this->image_border_opacity / 100 * 127): 0);
4166 $tmp = $this->
imagecreatenew($this->image_dst_x, $this->image_dst_y);
4167 $background = imagecolorallocatealpha($tmp, $red, $green, $blue, $opacity);
4168 imagefilledrectangle($tmp, 0, 0, $this->image_dst_x, $this->image_dst_y, $background);
4170 imagecopy($tmp, $image_dst, $cl, $ct, 0, 0, $this->image_dst_x - $cr - $cl, $this->image_dst_y - $cb - $ct);
4176 if ($gd_version >= 2 && !empty($this->image_border_transparent)) {
4177 list($ct, $cr, $cb, $cl) = $this->
getoffsets($this->image_border_transparent, $this->image_dst_x, $this->image_dst_y,
true,
false);
4178 $this->log .=
'- add transparent border : ' . $ct .
' ' . $cr .
' ' . $cb .
' ' . $cl .
'<br />';
4180 $tmp = $this->
imagecreatenew($this->image_dst_x, $this->image_dst_y);
4182 imagecopy($tmp, $image_dst, $cl, $ct, $cl, $ct, $this->image_dst_x - $cr - $cl, $this->image_dst_y - $cb - $ct);
4185 for ($y = $ct - 1; $y >= 0; $y--) {
4186 $il = (int) ($ct > 0 ? ($cl * ($y / $ct)) : 0);
4187 $ir = (int) ($ct > 0 ? ($cr * ($y / $ct)) : 0);
4188 for ($x = $il; $x < $this->image_dst_x - $ir; $x++) {
4189 $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4190 $alpha = (1 - ($pixel[
'alpha'] / 127)) * $opacity / 100;
4192 if ($alpha > 1) $alpha = 1;
4193 $color = imagecolorallocatealpha($tmp, $pixel[
'red'] , $pixel[
'green'], $pixel[
'blue'], round((1 - $alpha) * 127));
4194 imagesetpixel($tmp, $x, $y, $color);
4197 if ($opacity > 0) $opacity = $opacity - (100 / $ct);
4202 $it = (int) ($cr > 0 ? ($ct * (($this->image_dst_x - $x - 1) / $cr)) : 0);
4203 $ib = (int) ($cr > 0 ? ($cb * (($this->image_dst_x - $x - 1) / $cr)) : 0);
4204 for ($y = $it; $y < $this->image_dst_y - $ib; $y++) {
4205 $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4206 $alpha = (1 - ($pixel[
'alpha'] / 127)) * $opacity / 100;
4208 if ($alpha > 1) $alpha = 1;
4209 $color = imagecolorallocatealpha($tmp, $pixel[
'red'] , $pixel[
'green'], $pixel[
'blue'], round((1 - $alpha) * 127));
4210 imagesetpixel($tmp, $x, $y, $color);
4213 if ($opacity > 0) $opacity = $opacity - (100 / $cr);
4218 $il = (int) ($cb > 0 ? ($cl * (($this->image_dst_y - $y - 1) / $cb)) : 0);
4219 $ir = (int) ($cb > 0 ? ($cr * (($this->image_dst_y - $y - 1) / $cb)) : 0);
4220 for ($x = $il; $x < $this->image_dst_x - $ir; $x++) {
4221 $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4222 $alpha = (1 - ($pixel[
'alpha'] / 127)) * $opacity / 100;
4224 if ($alpha > 1) $alpha = 1;
4225 $color = imagecolorallocatealpha($tmp, $pixel[
'red'] , $pixel[
'green'], $pixel[
'blue'], round((1 - $alpha) * 127));
4226 imagesetpixel($tmp, $x, $y, $color);
4229 if ($opacity > 0) $opacity = $opacity - (100 / $cb);
4233 for ($x = $cl - 1; $x >= 0; $x--) {
4234 $it = (int) ($cl > 0 ? ($ct * ($x / $cl)) : 0);
4235 $ib = (int) ($cl > 0 ? ($cb * ($x / $cl)) : 0);
4236 for ($y = $it; $y < $this->image_dst_y - $ib; $y++) {
4237 $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4238 $alpha = (1 - ($pixel[
'alpha'] / 127)) * $opacity / 100;
4240 if ($alpha > 1) $alpha = 1;
4241 $color = imagecolorallocatealpha($tmp, $pixel[
'red'] , $pixel[
'green'], $pixel[
'blue'], round((1 - $alpha) * 127));
4242 imagesetpixel($tmp, $x, $y, $color);
4245 if ($opacity > 0) $opacity = $opacity - (100 / $cl);
4252 if ($gd_version >= 2 && is_numeric($this->image_frame)) {
4253 if (is_array($this->image_frame_colors)) {
4255 $this->log .=
'- add frame : ' . implode(
' ', $this->image_frame_colors) .
'<br />';
4257 $this->log .=
'- add frame : ' . $this->image_frame_colors .
'<br />';
4258 $vars = explode(
' ', $this->image_frame_colors);
4260 $nb =
sizeof($vars);
4261 $this->image_dst_x = $this->image_dst_x + ($nb * 2);
4262 $this->image_dst_y = $this->image_dst_y + ($nb * 2);
4263 $tmp = $this->
imagecreatenew($this->image_dst_x, $this->image_dst_y);
4264 imagecopy($tmp, $image_dst, $nb, $nb, 0, 0, $this->image_dst_x - ($nb * 2), $this->image_dst_y - ($nb * 2));
4265 $opacity = (is_numeric($this->image_frame_opacity) ? (int) (127 - $this->image_frame_opacity / 100 * 127): 0);
4266 for ($i=0; $i<$nb; $i++) {
4267 list($red, $green, $blue) = $this->
getcolors($vars[$i]);
4268 $c = imagecolorallocatealpha($tmp, $red, $green, $blue, $opacity);
4269 if ($this->image_frame == 1) {
4270 imageline($tmp, $i, $i, $this->image_dst_x - $i -1, $i, $c);
4271 imageline($tmp, $this->image_dst_x - $i -1, $this->image_dst_y - $i -1, $this->image_dst_x - $i -1, $i, $c);
4272 imageline($tmp, $this->image_dst_x - $i -1, $this->image_dst_y - $i -1, $i, $this->image_dst_y - $i -1, $c);
4273 imageline($tmp, $i, $i, $i, $this->image_dst_y - $i -1, $c);
4275 imageline($tmp, $i, $i, $this->image_dst_x - $i -1, $i, $c);
4276 imageline($tmp, $this->image_dst_x - $nb + $i, $this->image_dst_y - $nb + $i, $this->image_dst_x - $nb + $i, $nb - $i, $c);
4277 imageline($tmp, $this->image_dst_x - $nb + $i, $this->image_dst_y - $nb + $i, $nb - $i, $this->image_dst_y - $nb + $i, $c);
4278 imageline($tmp, $i, $i, $i, $this->image_dst_y - $i -1, $c);
4286 if ($gd_version >= 2 && $this->image_bevel > 0) {
4287 if (empty($this->image_bevel_color1)) $this->image_bevel_color1 =
'#FFFFFF';
4288 if (empty($this->image_bevel_color2)) $this->image_bevel_color2 =
'#000000';
4289 list($red1, $green1, $blue1) = $this->
getcolors($this->image_bevel_color1);
4290 list($red2, $green2, $blue2) = $this->
getcolors($this->image_bevel_color2);
4291 $tmp = $this->
imagecreatenew($this->image_dst_x, $this->image_dst_y);
4292 imagecopy($tmp, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y);
4293 imagealphablending($tmp,
true);
4295 $alpha = round(($i / $this->image_bevel) * 127);
4296 $c1 = imagecolorallocatealpha($tmp, $red1, $green1, $blue1, $alpha);
4297 $c2 = imagecolorallocatealpha($tmp, $red2, $green2, $blue2, $alpha);
4298 imageline($tmp, $i, $i, $this->image_dst_x - $i -1, $i, $c1);
4299 imageline($tmp, $this->image_dst_x - $i -1, $this->image_dst_y - $i, $this->image_dst_x - $i -1, $i, $c2);
4300 imageline($tmp, $this->image_dst_x - $i -1, $this->image_dst_y - $i -1, $i, $this->image_dst_y - $i -1, $c2);
4301 imageline($tmp, $i, $i, $i, $this->image_dst_y - $i -1, $c1);
4308 if ($this->image_watermark!=
'' && file_exists($this->image_watermark)) {
4309 $this->log .=
'- add watermark<br />';
4310 $this->image_watermark_position = strtolower((
string) $this->image_watermark_position);
4311 $watermark_info = getimagesize($this->image_watermark);
4312 $watermark_type = (array_key_exists(2, $watermark_info) ? $watermark_info[2] :
null);
4313 $watermark_checked =
false;
4314 if ($watermark_type == IMAGETYPE_GIF) {
4316 $this->error = $this->
translate(
'watermark_no_create_support', array(
'GIF'));
4318 $filter = @imagecreatefromgif($this->image_watermark);
4320 $this->error = $this->
translate(
'watermark_create_error', array(
'GIF'));
4322 $this->log .=
' watermark source image is GIF<br />';
4323 $watermark_checked =
true;
4326 }
else if ($watermark_type == IMAGETYPE_JPEG) {
4328 $this->error = $this->
translate(
'watermark_no_create_support', array(
'JPEG'));
4330 $filter = @imagecreatefromjpeg($this->image_watermark);
4332 $this->error = $this->
translate(
'watermark_create_error', array(
'JPEG'));
4334 $this->log .=
' watermark source image is JPEG<br />';
4335 $watermark_checked =
true;
4338 }
else if ($watermark_type == IMAGETYPE_PNG) {
4340 $this->error = $this->
translate(
'watermark_no_create_support', array(
'PNG'));
4342 $filter = @imagecreatefrompng($this->image_watermark);
4344 $this->error = $this->
translate(
'watermark_create_error', array(
'PNG'));
4346 $this->log .=
' watermark source image is PNG<br />';
4347 $watermark_checked =
true;
4350 }
else if ($watermark_type == IMAGETYPE_WEBP) {
4352 $this->error = $this->
translate(
'watermark_no_create_support', array(
'WEBP'));
4354 $filter = @imagecreatefromwebp($this->image_watermark);
4356 $this->error = $this->
translate(
'watermark_create_error', array(
'WEBP'));
4358 $this->log .=
' watermark source image is WEBP<br />';
4359 $watermark_checked =
true;
4362 }
else if ($watermark_type == IMAGETYPE_BMP) {
4363 if (!method_exists($this,
'imagecreatefrombmp')) {
4364 $this->error = $this->
translate(
'watermark_no_create_support', array(
'BMP'));
4368 $this->error = $this->
translate(
'watermark_create_error', array(
'BMP'));
4370 $this->log .=
' watermark source image is BMP<br />';
4371 $watermark_checked =
true;
4375 $this->error = $this->
translate(
'watermark_invalid');
4377 if ($watermark_checked) {
4378 $watermark_dst_width = $watermark_src_width = imagesx($filter);
4379 $watermark_dst_height = $watermark_src_height = imagesy($filter);
4382 if ((!$this->image_watermark_no_zoom_out && ($watermark_dst_width > $this->image_dst_x || $watermark_dst_height > $this->image_dst_y))
4383 || (!$this->image_watermark_no_zoom_in && $watermark_dst_width < $this->image_dst_x && $watermark_dst_height < $this->image_dst_y)) {
4384 $canvas_width = $this->image_dst_x - abs((
int) $this->image_watermark_x);
4385 $canvas_height = $this->image_dst_y - abs((
int) $this->image_watermark_y);
4386 if (($watermark_src_width/$canvas_width) > ($watermark_src_height/$canvas_height)) {
4387 $watermark_dst_width = $canvas_width;
4388 $watermark_dst_height = intval($watermark_src_height*($canvas_width / $watermark_src_width));
4390 $watermark_dst_height = $canvas_height;
4391 $watermark_dst_width = intval($watermark_src_width*($canvas_height / $watermark_src_height));
4393 $this->log .=
' watermark resized from '.$watermark_src_width.
'x'.$watermark_src_height.
' to '.$watermark_dst_width.
'x'.$watermark_dst_height.
'<br />';
4399 if (is_numeric($this->image_watermark_x)) {
4400 if ($this->image_watermark_x < 0) {
4406 if (strpos($this->image_watermark_position,
'r') !==
false) {
4407 $watermark_x = $this->image_dst_x - $watermark_dst_width;
4408 }
else if (strpos($this->image_watermark_position,
'l') !==
false) {
4411 $watermark_x = ($this->image_dst_x - $watermark_dst_width) / 2;
4414 if (is_numeric($this->image_watermark_y)) {
4415 if ($this->image_watermark_y < 0) {
4421 if (strpos($this->image_watermark_position,
'b') !==
false) {
4422 $watermark_y = $this->image_dst_y - $watermark_dst_height;
4423 }
else if (strpos($this->image_watermark_position,
't') !==
false) {
4426 $watermark_y = ($this->image_dst_y - $watermark_dst_height) / 2;
4429 imagealphablending($image_dst,
true);
4430 imagecopyresampled($image_dst, $filter, $watermark_x, $watermark_y, 0, 0, $watermark_dst_width, $watermark_dst_height, $watermark_src_width, $watermark_src_height);
4432 $this->error = $this->
translate(
'watermark_invalid');
4437 if (!empty($this->image_text)) {
4438 $this->log .=
'- add text<br />';
4441 $src_size = $this->file_src_size / 1024;
4442 $src_size_mb = number_format($src_size / 1024, 1,
".",
" ");
4443 $src_size_kb = number_format($src_size, 1,
".",
" ");
4444 $src_size_human = ($src_size > 1024 ? $src_size_mb .
" MB" : $src_size_kb .
" kb");
4446 $this->image_text = str_replace(
4474 array($this->file_src_name,
4475 $this->file_src_name_body,
4476 $this->file_src_name_ext,
4477 $this->file_src_pathname,
4478 $this->file_src_mime,
4479 $this->file_src_size,
4485 $this->image_src_pixels,
4486 $this->image_src_type,
4487 $this->image_src_bits,
4488 $this->file_dst_path,
4489 $this->file_dst_name_body,
4490 $this->file_dst_name_ext,
4491 $this->file_dst_name,
4492 $this->file_dst_pathname,
4503 if (!is_numeric($this->image_text_padding)) $this->image_text_padding = 0;
4504 if (!is_numeric($this->image_text_line_spacing)) $this->image_text_line_spacing = 0;
4507 $this->image_text_position = strtolower((
string) $this->image_text_position);
4508 $this->image_text_direction = strtolower((
string) $this->image_text_direction);
4509 $this->image_text_alignment = strtolower((
string) $this->image_text_alignment);
4514 if (!is_numeric($this->image_text_font) && strlen($this->image_text_font) > 4 && substr(strtolower($this->image_text_font), -4) ==
'.gdf') {
4515 if (strpos($this->image_text_font,
'/') ===
false) $this->image_text_font =
"./" .
$this->image_text_font;
4516 $this->log .=
' try to load font ' . $this->image_text_font .
'... ';
4517 if ($this->image_text_font = @imageloadfont($this->image_text_font)) {
4518 $this->log .=
'success<br />';
4520 $this->log .=
'error<br />';
4521 $this->image_text_font = 5;
4525 }
else if (!is_numeric($this->image_text_font) && strlen($this->image_text_font) > 4 && substr(strtolower($this->image_text_font), -4) ==
'.ttf') {
4526 $this->log .=
' try to load font ' . $this->image_text_font .
'... ';
4527 if (strpos($this->image_text_font,
'/') ===
false) $this->image_text_font =
"./" .
$this->image_text_font;
4528 if (file_exists($this->image_text_font) && is_readable($this->image_text_font)) {
4529 $this->log .=
'success<br />';
4532 $this->log .=
'error<br />';
4533 $this->image_text_font = 5;
4538 if ($font_type ==
'gd') {
4539 $text = explode(
"\n", $this->image_text);
4540 $char_width = imagefontwidth($this->image_text_font);
4541 $char_height = imagefontheight($this->image_text_font);
4546 foreach ($text as $k => $v) {
4547 if ($this->image_text_direction ==
'v') {
4548 $h = ($char_width * strlen($v));
4549 if ($h > $text_height) $text_height = $h;
4550 $line_width = $char_height;
4551 $text_width += $line_width + ($k < (
sizeof($text)-1) ? $this->image_text_line_spacing : 0);
4553 $w = ($char_width * strlen($v));
4554 if ($w > $text_width) $text_width = $w;
4555 $line_height = $char_height;
4556 $text_height += $line_height + ($k < (
sizeof($text)-1) ? $this->image_text_line_spacing : 0);
4563 }
else if ($font_type ==
'tt') {
4565 if (!$this->image_text_angle) $this->image_text_angle = $this->image_text_direction ==
'v' ? 90 : 0;
4570 $rect = imagettfbbox($this->image_text_size, $this->image_text_angle, $this->image_text_font, $text );
4572 $minX = min(array($rect[0],$rect[2],$rect[4],$rect[6]));
4573 $maxX = max(array($rect[0],$rect[2],$rect[4],$rect[6]));
4574 $minY = min(array($rect[1],$rect[3],$rect[5],$rect[7]));
4575 $maxY = max(array($rect[1],$rect[3],$rect[5],$rect[7]));
4576 $text_offset_x = abs($minX);
4577 $text_offset_y = abs($minY);
4586 if (is_numeric($this->image_text_x)) {
4587 if ($this->image_text_x < 0) {
4593 if (strpos($this->image_text_position,
'r') !==
false) {
4594 $text_x = $this->image_dst_x - $text_width;
4595 }
else if (strpos($this->image_text_position,
'l') !==
false) {
4598 $text_x = ($this->image_dst_x - $text_width) / 2;
4601 if (is_numeric($this->image_text_y)) {
4602 if ($this->image_text_y < 0) {
4608 if (strpos($this->image_text_position,
'b') !==
false) {
4609 $text_y = $this->image_dst_y - $text_height;
4610 }
else if (strpos($this->image_text_position,
't') !==
false) {
4613 $text_y = ($this->image_dst_y - $text_height) / 2;
4618 if (!empty($this->image_text_background)) {
4619 list($red, $green, $blue) = $this->
getcolors($this->image_text_background);
4620 if ($gd_version >= 2 && (is_numeric($this->image_text_background_opacity)) && $this->image_text_background_opacity >= 0 && $this->image_text_background_opacity <= 100) {
4621 $filter = imagecreatetruecolor($text_width, $text_height);
4622 $background_color = imagecolorallocate($filter, $red, $green, $blue);
4623 imagefilledrectangle($filter, 0, 0, $text_width, $text_height, $background_color);
4624 $this->
imagecopymergealpha($image_dst, $filter, $text_x, $text_y, 0, 0, $text_width, $text_height, $this->image_text_background_opacity);
4627 $background_color = imagecolorallocate($image_dst ,$red, $green, $blue);
4628 imagefilledrectangle($image_dst, $text_x, $text_y, $text_x + $text_width, $text_y + $text_height, $background_color);
4636 list($red, $green, $blue) = $this->
getcolors($this->image_text_color);
4639 if ($gd_version >= 2 && (is_numeric($this->image_text_opacity)) && $this->image_text_opacity >= 0 && $this->image_text_opacity <= 100) {
4640 if ($t_width < 0) $t_width = 0;
4641 if ($t_height < 0) $t_height = 0;
4642 $filter = $this->
imagecreatenew($t_width, $t_height,
false,
true);
4643 $text_color = imagecolorallocate($filter ,$red, $green, $blue);
4645 if ($font_type ==
'gd') {
4646 foreach ($text as $k => $v) {
4647 if ($this->image_text_direction ==
'v') {
4648 imagestringup($filter,
4649 $this->image_text_font,
4650 (
int) ($k * ($line_width + ($k > 0 && $k < (
sizeof($text)) ? $this->image_text_line_spacing : 0))),
4651 (
int) ($text_height - (2 * $this->image_text_padding_y) - ($this->image_text_alignment ==
'l' ? 0 : (($t_height - strlen($v) * $char_width) / ($this->image_text_alignment ==
'r' ? 1 : 2)))),
4655 imagestring($filter,
4656 $this->image_text_font,
4657 (
int) ($this->image_text_alignment ==
'l' ? 0 : (($t_width - strlen($v) * $char_width) / ($this->image_text_alignment ==
'r' ? 1 : 2))),
4658 (
int) ($k * ($line_height + ($k > 0 && $k < (
sizeof($text)) ? $this->image_text_line_spacing : 0))),
4663 }
else if ($font_type ==
'tt') {
4664 imagettftext($filter,
4665 $this->image_text_size,
4666 $this->image_text_angle,
4670 $this->image_text_font,
4673 $this->
imagecopymergealpha($image_dst, $filter, $text_x, $text_y, 0, 0, $t_width, $t_height, $this->image_text_opacity);
4677 $text_color = imagecolorallocate($image_dst ,$red, $green, $blue);
4678 if ($font_type ==
'gd') {
4679 foreach ($text as $k => $v) {
4680 if ($this->image_text_direction ==
'v') {
4681 imagestringup($image_dst,
4682 $this->image_text_font,
4683 $text_x + $k * ($line_width + ($k > 0 && $k < (
sizeof($text)) ? $this->image_text_line_spacing : 0)),
4684 $text_y + $text_height - (2 * $this->image_text_padding_y) - ($this->image_text_alignment ==
'l' ? 0 : (($t_height - strlen($v) * $char_width) / ($this->image_text_alignment ==
'r' ? 1 : 2))),
4688 imagestring($image_dst,
4689 $this->image_text_font,
4690 $text_x + ($this->image_text_alignment ==
'l' ? 0 : (($t_width - strlen($v) * $char_width) / ($this->image_text_alignment ==
'r' ? 1 : 2))),
4691 $text_y + $k * ($line_height + ($k > 0 && $k < (
sizeof($text)) ? $this->image_text_line_spacing : 0)),
4696 }
else if ($font_type ==
'tt') {
4697 imagettftext($image_dst,
4698 $this->image_text_size,
4699 $this->image_text_angle,
4700 $text_offset_x + ($this->image_dst_x / 2) - ($text_width / 2) + $this->image_text_padding_x,
4701 $text_offset_y + ($this->image_dst_y / 2) - ($text_height / 2) + $this->image_text_padding_y,
4703 $this->image_text_font,
4710 if ($this->image_reflection_height) {
4711 $this->log .=
'- add reflection : ' . $this->image_reflection_height .
'<br />';
4718 if (empty($this->image_reflection_opacity)) $this->image_reflection_opacity = 60;
4724 imagecopy($tmp, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y + ($this->image_reflection_space < 0 ? $this->image_reflection_space : 0));
4729 if (!empty($this->image_background_color)) {
4730 list($red, $green, $blue) = $this->
getcolors($this->image_background_color);
4731 $fill = imagecolorallocate($tmp, $red, $green, $blue);
4733 $fill = imagecolorallocatealpha($tmp, 0, 0, 0, 127);
4736 imagefill($tmp, round($this->image_dst_x / 2), $this->image_dst_y +
$image_reflection_height + $this->image_reflection_space - 1, $fill);
4742 $pixel_b = imagecolorsforindex($tmp, imagecolorat($tmp, $x, $y + $this->image_dst_y + $this->image_reflection_space));
4743 $pixel_o = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $this->image_dst_y - $y - 1 + ($this->image_reflection_space < 0 ? $this->image_reflection_space : 0)));
4744 $alpha_o = 1 - ($pixel_o[
'alpha'] / 127);
4745 $alpha_b = 1 - ($pixel_b[
'alpha'] / 127);
4746 $opacity = $alpha_o * $transparency / 100;
4748 $red = round((($pixel_o[
'red'] * $opacity) + ($pixel_b[
'red'] ) * $alpha_b) / ($alpha_b + $opacity));
4749 $green = round((($pixel_o[
'green'] * $opacity) + ($pixel_b[
'green']) * $alpha_b) / ($alpha_b + $opacity));
4750 $blue = round((($pixel_o[
'blue'] * $opacity) + ($pixel_b[
'blue'] ) * $alpha_b) / ($alpha_b + $opacity));
4751 $alpha = ($opacity + $alpha_b);
4752 if ($alpha > 1) $alpha = 1;
4753 $alpha = round((1 - $alpha) * 127);
4754 $color = imagecolorallocatealpha($tmp, $red, $green, $blue, $alpha);
4755 imagesetpixel($tmp, $x, $y + $this->image_dst_y + $this->image_reflection_space, $color);
4758 if ($transparency > 0) $transparency = $transparency - ($this->image_reflection_opacity /
$image_reflection_height);
4767 if ($gd_version >= 2 && is_numeric($this->image_opacity) && $this->image_opacity < 100) {
4768 $this->log .=
'- change opacity<br />';
4770 $tmp = $this->
imagecreatenew($this->image_dst_x, $this->image_dst_y,
true);
4773 $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4774 $alpha = $pixel[
'alpha'] + round((127 - $pixel[
'alpha']) * (100 - $this->image_opacity) / 100);
4775 if ($alpha > 127) $alpha = 127;
4777 $color = imagecolorallocatealpha($tmp, $pixel[
'red'] , $pixel[
'green'], $pixel[
'blue'], $alpha);
4778 imagesetpixel($tmp, $x, $y, $color);
4787 if (is_numeric($this->jpeg_size) && $this->jpeg_size > 0 && ($this->image_convert ==
'jpeg' || $this->image_convert ==
'jpg')) {
4789 $this->log .=
'- JPEG desired file size : ' . $this->jpeg_size .
'<br />';
4791 ob_start(); imagejpeg($image_dst,
null,75); $buffer = ob_get_contents(); ob_end_clean();
4792 $size75 = strlen($buffer);
4793 ob_start(); imagejpeg($image_dst,
null,50); $buffer = ob_get_contents(); ob_end_clean();
4794 $size50 = strlen($buffer);
4795 ob_start(); imagejpeg($image_dst,
null,25); $buffer = ob_get_contents(); ob_end_clean();
4796 $size25 = strlen($buffer);
4799 if ($size50 == $size25) $size50++;
4800 if ($size75 == $size50 || $size75 == $size25) $size75++;
4803 $mgrad1 = 25 / ($size50-$size25);
4804 $mgrad2 = 25 / ($size75-$size50);
4805 $mgrad3 = 50 / ($size75-$size25);
4806 $mgrad = ($mgrad1 + $mgrad2 + $mgrad3) / 3;
4808 $q_factor = round($mgrad * ($this->jpeg_size - $size50) + 50);
4811 $this->jpeg_quality=1;
4812 } elseif ($q_factor>100) {
4813 $this->jpeg_quality=100;
4815 $this->jpeg_quality=$q_factor;
4817 $this->log .=
' JPEG quality factor set to ' . $this->jpeg_quality .
'<br />';
4821 $this->log .=
'- converting...<br />';
4823 switch($this->image_convert) {
4826 if (imageistruecolor($image_dst)) {
4827 $this->log .=
' true color to palette<br />';
4829 $mask = array(array());
4832 $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4833 $mask[$x][$y] = $pixel[
'alpha'];
4836 list($red, $green, $blue) = $this->
getcolors($this->image_default_color);
4840 if ($mask[$x][$y] > 0){
4842 $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4843 $alpha = ($mask[$x][$y] / 127);
4844 $pixel[
'red'] = round(($pixel[
'red'] * (1 -$alpha) + $red * ($alpha)));
4845 $pixel[
'green'] = round(($pixel[
'green'] * (1 -$alpha) + $green * ($alpha)));
4846 $pixel[
'blue'] = round(($pixel[
'blue'] * (1 -$alpha) + $blue * ($alpha)));
4847 $color = imagecolorallocate($image_dst, $pixel[
'red'], $pixel[
'green'], $pixel[
'blue']);
4848 imagesetpixel($image_dst, $x, $y, $color);
4853 if (empty($this->image_background_color)) {
4854 imagetruecolortopalette($image_dst,
true, 255);
4855 $transparency = imagecolorallocate($image_dst, 254, 1, 253);
4856 imagecolortransparent($image_dst, $transparency);
4861 if ($mask[$x][$y] > 120) imagesetpixel($image_dst, $x, $y, $transparency);
4871 $this->log .=
' fills in transparency with default color<br />';
4872 list($red, $green, $blue) = $this->
getcolors($this->image_default_color);
4873 $transparency = imagecolorallocate($image_dst, $red, $green, $blue);
4878 if (imageistruecolor($image_dst)) {
4879 $rgba = imagecolorat($image_dst, $x, $y);
4880 $pixel = array(
'red' => ($rgba >> 16) & 0xFF,
4881 'green' => ($rgba >> 8) & 0xFF,
4882 'blue' => $rgba & 0xFF,
4883 'alpha' => ($rgba & 0x7F000000) >> 24);
4885 $pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
4887 if ($pixel[
'alpha'] == 127) {
4889 imagesetpixel($image_dst, $x, $y, $transparency);
4890 }
else if ($pixel[
'alpha'] > 0) {
4892 $alpha = ($pixel[
'alpha'] / 127);
4893 $pixel[
'red'] = round(($pixel[
'red'] * (1 -$alpha) + $red * ($alpha)));
4894 $pixel[
'green'] = round(($pixel[
'green'] * (1 -$alpha) + $green * ($alpha)));
4895 $pixel[
'blue'] = round(($pixel[
'blue'] * (1 -$alpha) + $blue * ($alpha)));
4896 $color = imagecolorclosest($image_dst, $pixel[
'red'], $pixel[
'green'], $pixel[
'blue']);
4897 imagesetpixel($image_dst, $x, $y, $color);
4908 if($this->image_interlace) imageinterlace($image_dst,
true);
4911 $this->log .=
'- saving image...<br />';
4912 switch($this->image_convert) {
4915 if (!$return_mode) {
4916 $result = @imagejpeg($image_dst, $this->file_dst_pathname, $this->jpeg_quality);
4919 $result = @imagejpeg($image_dst,
null, $this->jpeg_quality);
4920 $return_content = ob_get_contents();
4924 $this->processed =
false;
4925 $this->error = $this->
translate(
'file_create', array(
'JPEG'));
4927 $this->log .=
' JPEG image created<br />';
4931 imagealphablending( $image_dst,
false );
4932 imagesavealpha( $image_dst,
true );
4933 if (!$return_mode) {
4934 if (is_numeric($this->png_compression) && version_compare(PHP_VERSION,
'5.1.2') >= 0) {
4935 $result = @imagepng($image_dst, $this->file_dst_pathname, $this->png_compression);
4937 $result = @imagepng($image_dst, $this->file_dst_pathname);
4941 if (is_numeric($this->png_compression) && version_compare(PHP_VERSION,
'5.1.2') >= 0) {
4942 $result = @imagepng($image_dst,
null, $this->png_compression);
4944 $result = @imagepng($image_dst);
4946 $return_content = ob_get_contents();
4950 $this->processed =
false;
4951 $this->error = $this->
translate(
'file_create', array(
'PNG'));
4953 $this->log .=
' PNG image created<br />';
4957 imagealphablending( $image_dst,
false );
4958 imagesavealpha( $image_dst,
true );
4959 if (!$return_mode) {
4960 $result = @imagewebp($image_dst, $this->file_dst_pathname, $this->webp_quality);
4963 $result = @imagewebp($image_dst,
null, $this->webp_quality);
4964 $return_content = ob_get_contents();
4968 $this->processed =
false;
4969 $this->error = $this->
translate(
'file_create', array(
'WEBP'));
4971 $this->log .=
' WEBP image created<br />';
4975 if (!$return_mode) {
4976 $result = @imagegif($image_dst, $this->file_dst_pathname);
4979 $result = @imagegif($image_dst);
4980 $return_content = ob_get_contents();
4984 $this->processed =
false;
4985 $this->error = $this->
translate(
'file_create', array(
'GIF'));
4987 $this->log .=
' GIF image created<br />';
4991 if (!$return_mode) {
4996 $return_content = ob_get_contents();
5000 $this->processed =
false;
5001 $this->error = $this->
translate(
'file_create', array(
'BMP'));
5003 $this->log .=
' BMP image created<br />';
5008 $this->processed =
false;
5009 $this->error = $this->
translate(
'no_conversion_type');
5011 if ($this->processed) {
5014 $this->log .=
' image objects destroyed<br />';
5019 $this->log .=
'- no image processing wanted<br />';
5021 if (!$return_mode) {
5024 if (!copy($this->file_src_pathname, $this->file_dst_pathname)) {
5025 $this->processed =
false;
5026 $this->error = $this->
translate(
'copy_failed');
5030 $return_content = @file_get_contents($this->file_src_pathname);
5031 if ($return_content ===
false) {
5032 $this->processed =
false;
5033 $this->error = $this->
translate(
'reading_failed');
5039 if ($this->processed) {
5040 $this->log .=
'- <b>process OK</b><br />';
5042 $this->log .=
'- <b>error</b>: ' . $this->error .
'<br />';
5049 if ($return_mode)
return $return_content;