26 $this->
DebugMessage(
'Using alpha ApplyMask() technique', __FILE__, __LINE__);
29 ImageCopyResampled($gdimg_mask_resized, $gdimg_mask, 0, 0, 0, 0, ImageSX($gdimg_image), ImageSY($gdimg_image), ImageSX($gdimg_mask), ImageSY($gdimg_mask));
32 $color_background = ImageColorAllocate($gdimg_mask_blendtemp, 0, 0, 0);
33 ImageFilledRectangle($gdimg_mask_blendtemp, 0, 0, ImageSX($gdimg_mask_blendtemp), ImageSY($gdimg_mask_blendtemp), $color_background);
34 ImageAlphaBlending($gdimg_mask_blendtemp,
false);
35 ImageSaveAlpha($gdimg_mask_blendtemp,
true);
36 for ($x = 0; $x < ImageSX($gdimg_image); $x++) {
37 for ($y = 0; $y < ImageSY($gdimg_image); $y++) {
41 $MaskAlpha = 127 - (floor($MaskPixel[
'red'] / 2) * (1 - ($RealPixel[
'alpha'] / 127)));
43 ImageSetPixel($gdimg_mask_blendtemp, $x, $y, $newcolor);
46 ImageAlphaBlending($gdimg_image,
false);
47 ImageSaveAlpha($gdimg_image,
true);
48 ImageCopy($gdimg_image, $gdimg_mask_blendtemp, 0, 0, 0, 0, ImageSX($gdimg_mask_blendtemp), ImageSY($gdimg_mask_blendtemp));
49 ImageDestroy($gdimg_mask_blendtemp);
52 $this->
DebugMessage(
'ImageCreateFunction() failed', __FILE__, __LINE__);
54 ImageDestroy($gdimg_mask_resized);
57 $this->
DebugMessage(
'ImageCreateFunction() failed', __FILE__, __LINE__);
62 $this->
DebugMessage(
'Skipping ApplyMask() technique because PHP is v"'.phpversion().
'"', __FILE__, __LINE__);
68 function Bevel(&$gdimg, $width, $hexcolor1, $hexcolor2) {
69 $width = ($width ? $width : 5);
70 $hexcolor1 = ($hexcolor1 ? $hexcolor1 :
'FFFFFF');
71 $hexcolor2 = ($hexcolor2 ? $hexcolor2 :
'000000');
73 ImageAlphaBlending($gdimg,
true);
74 for (
$i = 0;
$i < $width;
$i++) {
75 $alpha = round((
$i / $width) * 127);
79 ImageLine($gdimg,
$i,
$i + 1,
$i, ImageSY($gdimg) -
$i - 1, $color1);
80 ImageLine($gdimg,
$i,
$i , ImageSX($gdimg) -
$i,
$i , $color1);
81 ImageLine($gdimg, ImageSX($gdimg) -
$i, ImageSY($gdimg) -
$i - 1, ImageSX($gdimg) -
$i,
$i + 1, $color2);
82 ImageLine($gdimg, ImageSX($gdimg) -
$i, ImageSY($gdimg) -
$i ,
$i, ImageSY($gdimg) -
$i , $color2);
88 function Blur(&$gdimg, $radius=0.5) {
91 $radius = round(max(0, min($radius, 50)) * 2);
98 if ($imgBlur = ImageCreateTrueColor($w, $h)) {
106 for (
$i = 0;
$i < $radius;
$i++) {
107 ImageCopy ($imgBlur, $gdimg, 0, 0, 1, 1, $w - 1, $h - 1);
108 ImageCopyMerge($imgBlur, $gdimg, 1, 1, 0, 0, $w, $h, 50.00000);
109 ImageCopyMerge($imgBlur, $gdimg, 0, 1, 1, 0, $w - 1, $h, 33.33333);
110 ImageCopyMerge($imgBlur, $gdimg, 1, 0, 0, 1, $w, $h - 1, 25.00000);
111 ImageCopyMerge($imgBlur, $gdimg, 0, 0, 1, 0, $w - 1, $h, 33.33333);
112 ImageCopyMerge($imgBlur, $gdimg, 1, 0, 0, 0, $w, $h, 25.00000);
113 ImageCopyMerge($imgBlur, $gdimg, 0, 0, 0, 1, $w, $h - 1, 20.00000);
114 ImageCopyMerge($imgBlur, $gdimg, 0, 1, 0, 0, $w, $h, 16.666667);
115 ImageCopyMerge($imgBlur, $gdimg, 0, 0, 0, 0, $w, $h, 50.000000);
116 ImageCopy ($gdimg, $imgBlur, 0, 0, 0, 0, $w, $h);
126 if (ImageFilter($gdimg, IMG_FILTER_GAUSSIAN_BLUR)) {
129 $this->
DebugMessage(
'FAILED: ImageFilter($gdimg, IMG_FILTER_GAUSSIAN_BLUR)', __FILE__, __LINE__);
132 $this->
DebugMessage(
'FAILED: phpthumb_filters::BlurGaussian($gdimg) [using phpthumb_filters::Blur() instead]', __FILE__, __LINE__);
139 if (ImageFilter($gdimg, IMG_FILTER_SELECTIVE_BLUR)) {
142 $this->
DebugMessage(
'FAILED: ImageFilter($gdimg, IMG_FILTER_SELECTIVE_BLUR)', __FILE__, __LINE__);
146 $this->
DebugMessage(
'FAILED: phpthumb_filters::BlurSelective($gdimg) [function not implemented]', __FILE__, __LINE__);
155 $amount = max(-255, min(255, $amount));
158 if (ImageFilter($gdimg, IMG_FILTER_BRIGHTNESS, $amount)) {
161 $this->
DebugMessage(
'FAILED: ImageFilter($gdimg, IMG_FILTER_BRIGHTNESS, '.$amount.
')', __FILE__, __LINE__);
165 $scaling = (255 - abs($amount)) / 255;
166 $baseamount = (($amount > 0) ? $amount : 0);
167 for ($x = 0; $x < ImageSX($gdimg); $x++) {
168 for ($y = 0; $y < ImageSY($gdimg); $y++) {
170 foreach ($OriginalPixel as $key => $value) {
171 $NewPixel[$key] = round($baseamount + ($OriginalPixel[$key] * $scaling));
173 $newColor = ImageColorAllocate($gdimg, $NewPixel[
'red'], $NewPixel[
'green'], $NewPixel[
'blue']);
174 ImageSetPixel($gdimg, $x, $y, $newColor);
185 $amount = max(-255, min(255, $amount));
189 $amount = ($amount / 255) * -100;
190 if (ImageFilter($gdimg, IMG_FILTER_CONTRAST, $amount)) {
193 $this->
DebugMessage(
'FAILED: ImageFilter($gdimg, IMG_FILTER_CONTRAST, '.$amount.
')', __FILE__, __LINE__);
198 $scaling = 1 + ($amount / 255);
200 $scaling = (255 - abs($amount)) / 255;
202 for ($x = 0; $x < ImageSX($gdimg); $x++) {
203 for ($y = 0; $y < ImageSY($gdimg); $y++) {
205 foreach ($OriginalPixel as $key => $value) {
206 $NewPixel[$key] = min(255, max(0, round($OriginalPixel[$key] * $scaling)));
208 $newColor = ImageColorAllocate($gdimg, $NewPixel[
'red'], $NewPixel[
'green'], $NewPixel[
'blue']);
209 ImageSetPixel($gdimg, $x, $y, $newColor);
215 function Colorize(&$gdimg, $amount, $targetColor) {
216 $amount = (is_numeric($amount) ? $amount : 25);
217 $amountPct = $amount / 100;
225 if ($targetColor ==
'gray') {
226 $targetColor =
'808080';
228 $r = round($amountPct * hexdec(substr($targetColor, 0, 2)));
229 $g = round($amountPct * hexdec(substr($targetColor, 2, 2)));
230 $b = round($amountPct * hexdec(substr($targetColor, 4, 2)));
231 if (ImageFilter($gdimg, IMG_FILTER_COLORIZE, $r, $g, $b)) {
234 $this->
DebugMessage(
'FAILED: ImageFilter($gdimg, IMG_FILTER_COLORIZE)', __FILE__, __LINE__);
239 if ($targetColor !=
'gray') {
240 $TargetPixel[
'red'] = hexdec(substr($targetColor, 0, 2));
241 $TargetPixel[
'green'] = hexdec(substr($targetColor, 2, 2));
242 $TargetPixel[
'blue'] = hexdec(substr($targetColor, 4, 2));
245 for ($x = 0; $x < ImageSX($gdimg); $x++) {
246 for ($y = 0; $y < ImageSY($gdimg); $y++) {
248 if ($targetColor ==
'gray') {
251 foreach ($TargetPixel as $key => $value) {
252 $NewPixel[$key] = round(max(0, min(255, ($OriginalPixel[$key] * ((100 - $amount) / 100)) + ($TargetPixel[$key] * $amountPct))));
255 $newColor = ImageColorAllocate($gdimg, $NewPixel[
'red'], $NewPixel[
'green'], $NewPixel[
'blue']);
256 ImageSetPixel($gdimg, $x, $y, $newColor);
263 function Crop(&$gdimg, $left=0, $right=0, $top=0, $bottom=0) {
264 if (!$left && !$right && !$top && !$bottom) {
267 $oldW = ImageSX($gdimg);
268 $oldH = ImageSY($gdimg);
269 if (($left > 0) && ($left < 1)) { $left = round($left * $oldW); }
270 if (($right > 0) && ($right < 1)) { $right = round($right * $oldW); }
271 if (($top > 0) && ($top < 1)) { $top = round($top * $oldH); }
272 if (($bottom > 0) && ($bottom < 1)) { $bottom = round($bottom * $oldH); }
273 $right = min($oldW - $left - 1, $right);
274 $bottom = min($oldH - $top - 1, $bottom);
275 $newW = $oldW - $left - $right;
276 $newH = $oldH - $top - $bottom;
278 if ($imgCropped = ImageCreateTrueColor($newW, $newH)) {
279 ImageCopy($imgCropped, $gdimg, 0, 0, $left, $top, $newW, $newH);
280 if ($gdimg = ImageCreateTrueColor($newW, $newH)) {
281 ImageCopy($gdimg, $imgCropped, 0, 0, 0, 0, $newW, $newH);
282 ImageDestroy($imgCropped);
285 ImageDestroy($imgCropped);
299 function DropShadow(&$gdimg, $distance, $width, $hexcolor, $angle, $alpha) {
303 $distance = ($distance ? $distance : 10);
304 $width = ($width ? $width : 10);
305 $hexcolor = ($hexcolor ? $hexcolor :
'000000');
306 $angle = ($angle ? $angle : 225) % 360;
307 $alpha = max(0, min(100, ($alpha ? $alpha : 100)));
313 if ($distance <= 0) {
318 $width_shadow = cos(deg2rad($angle)) * ($distance + $width);
319 $height_shadow = sin(deg2rad($angle)) * ($distance + $width);
321 $scaling = min(ImageSX($gdimg) / (ImageSX($gdimg) + abs($width_shadow)), ImageSY($gdimg) / (ImageSY($gdimg) + abs($height_shadow)));
323 for (
$i = 0;
$i < $width;
$i++) {
324 $WidthAlpha[
$i] = (abs(($width / 2) -
$i) / $width);
325 $Offset[
'x'] = cos(deg2rad($angle)) * ($distance +
$i);
326 $Offset[
'y'] = sin(deg2rad($angle)) * ($distance +
$i);
329 $tempImageWidth = ImageSX($gdimg) + abs($Offset[
'x']);
330 $tempImageHeight = ImageSY($gdimg) + abs($Offset[
'y']);
334 ImageAlphaBlending($gdimg_dropshadow_temp,
false);
335 ImageSaveAlpha($gdimg_dropshadow_temp,
true);
337 ImageFill($gdimg_dropshadow_temp, 0, 0, $transparent1);
339 for ($x = 0; $x < ImageSX($gdimg); $x++) {
340 for ($y = 0; $y < ImageSY($gdimg); $y++) {
344 for ($x = 0; $x < $tempImageWidth; $x++) {
345 for ($y = 0; $y < $tempImageHeight; $y++) {
347 for (
$i = 0;
$i < 1;
$i++) {
348 if (!isset($PixelMap[$x][$y][
'alpha']) || ($PixelMap[$x][$y][
'alpha'] > 0)) {
349 if (isset($PixelMap[$x + $Offset[
'x']][$y + $Offset[
'y']][
'alpha']) && ($PixelMap[$x + $Offset[
'x']][$y + $Offset[
'y']][
'alpha'] < 127)) {
351 ImageSetPixel($gdimg_dropshadow_temp, $x, $y, $thisColor);
358 ImageAlphaBlending($gdimg_dropshadow_temp,
true);
359 for ($x = 0; $x < ImageSX($gdimg); $x++) {
360 for ($y = 0; $y < ImageSY($gdimg); $y++) {
361 if ($PixelMap[$x][$y][
'alpha'] < 127) {
363 ImageSetPixel($gdimg_dropshadow_temp, $x, $y, $thisColor);
368 ImageSaveAlpha($gdimg,
true);
369 ImageAlphaBlending($gdimg,
false);
372 ImageFilledRectangle($gdimg, 0, 0, ImageSX($gdimg), ImageSY($gdimg), $transparent2);
373 ImageCopyResampled($gdimg, $gdimg_dropshadow_temp, 0, 0, 0, 0, ImageSX($gdimg), ImageSY($gdimg), ImageSX($gdimg_dropshadow_temp), ImageSY($gdimg_dropshadow_temp));
375 ImageDestroy($gdimg_dropshadow_temp);
383 if (ImageFilter($gdimg, IMG_FILTER_EDGEDETECT)) {
386 $this->
DebugMessage(
'FAILED: ImageFilter($gdimg, IMG_FILTER_EDGEDETECT)', __FILE__, __LINE__);
390 $this->
DebugMessage(
'FAILED: phpthumb_filters::EdgeDetect($gdimg) [function not implemented]', __FILE__, __LINE__);
403 $color_transparent = ImageColorAllocate($gdimg_elipsemask_double, 255, 255, 255);
404 ImageFilledEllipse($gdimg_elipsemask_double, ImageSX($gdimg), ImageSY($gdimg), (ImageSX($gdimg) - 1) * 2, (ImageSY($gdimg) - 1) * 2, $color_transparent);
405 ImageCopyResampled($gdimg_elipsemask, $gdimg_elipsemask_double, 0, 0, 0, 0, ImageSX($gdimg), ImageSY($gdimg), ImageSX($gdimg) * 2, ImageSY($gdimg) * 2);
408 ImageDestroy($gdimg_elipsemask);
412 $this->
DebugMessage(
'$gdimg_elipsemask = phpthumb_functions::ImageCreateFunction() failed', __FILE__, __LINE__);
414 ImageDestroy($gdimg_elipsemask_double);
416 $this->
DebugMessage(
'$gdimg_elipsemask_double = phpthumb_functions::ImageCreateFunction() failed', __FILE__, __LINE__);
424 if (ImageFilter($gdimg, IMG_FILTER_EMBOSS)) {
427 $this->
DebugMessage(
'FAILED: ImageFilter($gdimg, IMG_FILTER_EMBOSS)', __FILE__, __LINE__);
431 $this->
DebugMessage(
'FAILED: phpthumb_filters::Emboss($gdimg) [function not implemented]', __FILE__, __LINE__);
436 function Flip(&$gdimg, $x=
false, $y=
false) {
442 ImageCopy($tempImage, $gdimg, 0, 0, 0, 0, ImageSX($gdimg), ImageSY($gdimg));
443 for ($x = 0; $x < ImageSX($gdimg); $x++) {
444 ImageCopy($gdimg, $tempImage, ImageSX($gdimg) - 1 - $x, 0, $x, 0, 1, ImageSY($gdimg));
448 ImageCopy($tempImage, $gdimg, 0, 0, 0, 0, ImageSX($gdimg), ImageSY($gdimg));
449 for ($y = 0; $y < ImageSY($gdimg); $y++) {
450 ImageCopy($gdimg, $tempImage, 0, ImageSY($gdimg) - 1 - $y, 0, $y, ImageSX($gdimg), 1);
453 ImageDestroy($tempImage);
459 function Frame(&$gdimg, $frame_width, $edge_width, $hexcolor_frame, $hexcolor1, $hexcolor2) {
460 $frame_width = ($frame_width ? $frame_width : 5);
461 $edge_width = ($edge_width ? $edge_width : 1);
462 $hexcolor_frame = ($hexcolor_frame ? $hexcolor_frame :
'CCCCCC');
463 $hexcolor1 = ($hexcolor1 ? $hexcolor1 :
'FFFFFF');
464 $hexcolor2 = ($hexcolor2 ? $hexcolor2 :
'000000');
469 for (
$i = 0;
$i < $edge_width;
$i++) {
471 ImageLine($gdimg,
$i,
$i,
$i, ImageSY($gdimg) -
$i, $color1);
472 ImageLine($gdimg,
$i,
$i, ImageSX($gdimg) -
$i,
$i, $color1);
473 ImageLine($gdimg, ImageSX($gdimg) -
$i, ImageSY($gdimg) -
$i, ImageSX($gdimg) -
$i,
$i, $color2);
474 ImageLine($gdimg, ImageSX($gdimg) -
$i, ImageSY($gdimg) -
$i,
$i, ImageSY($gdimg) -
$i, $color2);
476 for (
$i = 0;
$i < $frame_width;
$i++) {
478 ImageRectangle($gdimg, $edge_width +
$i, $edge_width +
$i, ImageSX($gdimg) - $edge_width -
$i, ImageSY($gdimg) - $edge_width -
$i, $color_frame);
480 for (
$i = 0;
$i < $edge_width;
$i++) {
482 ImageLine($gdimg, $frame_width + $edge_width +
$i, $frame_width + $edge_width +
$i, $frame_width + $edge_width +
$i, ImageSY($gdimg) - $frame_width - $edge_width -
$i, $color2);
483 ImageLine($gdimg, $frame_width + $edge_width +
$i, $frame_width + $edge_width +
$i, ImageSX($gdimg) - $frame_width - $edge_width -
$i, $frame_width + $edge_width +
$i, $color2);
484 ImageLine($gdimg, ImageSX($gdimg) - $frame_width - $edge_width -
$i, ImageSY($gdimg) - $frame_width - $edge_width -
$i, ImageSX($gdimg) - $frame_width - $edge_width -
$i, $frame_width + $edge_width +
$i, $color1);
485 ImageLine($gdimg, ImageSX($gdimg) - $frame_width - $edge_width -
$i, ImageSY($gdimg) - $frame_width - $edge_width -
$i, $frame_width + $edge_width +
$i, ImageSY($gdimg) - $frame_width - $edge_width -
$i, $color1);
492 if (number_format($amount, 4) ==
'1.0000') {
495 return ImageGammaCorrect($gdimg, 1.0, $amount);
501 if (ImageFilter($gdimg, IMG_FILTER_GRAYSCALE)) {
504 $this->
DebugMessage(
'FAILED: ImageFilter($gdimg, IMG_FILTER_GRAYSCALE)', __FILE__, __LINE__);
512 $ImageSX = ImageSX($gdimg);
513 $ImageSY = ImageSY($gdimg);
514 for ($x = 0; $x < $ImageSX; $x++) {
515 for ($y = 0; $y < $ImageSY; $y++) {
517 @$Analysis[
'red'][$OriginalPixel[
'red']]++;
518 @$Analysis[
'green'][$OriginalPixel[
'green']]++;
519 @$Analysis[
'blue'][$OriginalPixel[
'blue']]++;
520 @$Analysis[
'alpha'][$OriginalPixel[
'alpha']]++;
521 if ($calculateGray) {
523 @$Analysis[
'gray'][$GrayPixel[
'red']]++;
527 $keys = array(
'red',
'green',
'blue',
'alpha');
528 if ($calculateGray) {
531 foreach ($keys as $dummy => $key) {
532 ksort($Analysis[$key]);
543 $keys = array(
'r'=>
'red',
'g'=>
'green',
'b'=>
'blue',
'a'=>
'alpha',
'*'=>((
$method == 0) ?
'all' :
'gray'));
544 $band = substr($band, 0, 1);
545 if (!isset($keys[$band])) {
554 $threshold = floatval($threshold) / 100;
555 $clip_threshold = ImageSX($gdimg) * ImageSX($gdimg) * $threshold;
560 for (
$i = 0;
$i <= 255;
$i++) {
562 $countsum = max(@$Analysis[
'red'][
$i], @$Analysis[
'green'][$i], @$Analysis[
'blue'][$i]);
564 $countsum += @$Analysis[$key][
$i];
566 if ($countsum >= $clip_threshold) {
571 $range_min = max($range_min, 0);
577 for (
$i = 255;
$i >= 0;
$i--) {
579 $countsum = max(@$Analysis[
'red'][
$i], @$Analysis[
'green'][$i], @$Analysis[
'blue'][$i]);
581 $countsum += @$Analysis[$key][
$i];
583 if ($countsum >= $clip_threshold) {
588 $range_max = min($range_max, 255);
590 $range_scale = (($range_max == $range_min) ? 1 : (255 / ($range_max - $range_min)));
591 if (($range_min == 0) && ($range_max == 255)) {
596 $ImageSX = ImageSX($gdimg);
597 $ImageSY = ImageSY($gdimg);
598 for ($x = 0; $x < $ImageSX; $x++) {
599 for ($y = 0; $y < $ImageSY; $y++) {
602 $new[
'red'] = min(255, max(0, ($OriginalPixel[
'red'] - $range_min) * $range_scale));
603 $new[
'green'] = min(255, max(0, ($OriginalPixel[
'green'] - $range_min) * $range_scale));
604 $new[
'blue'] = min(255, max(0, ($OriginalPixel[
'blue'] - $range_min) * $range_scale));
605 $new[
'alpha'] = min(255, max(0, ($OriginalPixel[
'alpha'] - $range_min) * $range_scale));
607 $new = $OriginalPixel;
608 $new[$key] = min(255, max(0, ($OriginalPixel[$key] - $range_min) * $range_scale));
611 ImageSetPixel($gdimg, $x, $y, $newColor);
619 function HistogramOverlay(&$gdimg, $bands=
'*', $colors=
'', $width=0.25, $height=0.25, $alignment=
'BR', $opacity=50, $margin_x=5, $margin_y=null) {
620 $margin_y = (is_null($margin_y) ? $margin_x : $margin_y);
623 $histW = round(($width > 1) ? min($width, ImageSX($gdimg)) : ImageSX($gdimg) * $width);
624 $histH = round(($width > 1) ? min($width, ImageSX($gdimg)) : ImageSX($gdimg) * $width);
625 if ($gdHist = ImageCreateTrueColor($histW, $histH)) {
627 ImageFilledRectangle($gdHist, 0, 0, $histW, $histH, $color_back);
628 ImageAlphaBlending($gdHist,
false);
629 ImageSaveAlpha($gdHist,
true);
631 $HistogramTempWidth = 256;
632 $HistogramTempHeight = 100;
633 if ($gdHistTemp = ImageCreateTrueColor($HistogramTempWidth, $HistogramTempHeight)) {
635 ImageAlphaBlending($gdHistTemp,
false);
636 ImageSaveAlpha($gdHistTemp,
true);
637 ImageFilledRectangle($gdHistTemp, 0, 0, ImageSX($gdHistTemp), ImageSY($gdHistTemp), $color_back_temp);
639 $DefaultColors = array(
'r'=>
'FF0000',
'g'=>
'00FF00',
'b'=>
'0000FF',
'a'=>
'999999',
'*'=>
'FFFFFF');
640 $Colors = explode(
';', $colors);
641 $BandsToGraph = array_unique(preg_split(
'##', $bands));
642 $keys = array(
'r'=>
'red',
'g'=>
'green',
'b'=>
'blue',
'a'=>
'alpha',
'*'=>
'gray');
643 foreach ($BandsToGraph as $key => $band) {
644 if (!isset($keys[$band])) {
647 $PeakValue = max($Analysis[$keys[$band]]);
649 for ($x = 0; $x < $HistogramTempWidth; $x++) {
650 ImageLine($gdHistTemp, $x, $HistogramTempHeight - 1, $x, $HistogramTempHeight - 1 - round(@$Analysis[$keys[$band]][$x] / $PeakValue * $HistogramTempHeight), $thisColor);
652 ImageLine($gdHistTemp, 0, $HistogramTempHeight - 1, $HistogramTempWidth - 1, $HistogramTempHeight - 1, $thisColor);
653 ImageLine($gdHistTemp, 0, $HistogramTempHeight - 2, $HistogramTempWidth - 1, $HistogramTempHeight - 2, $thisColor);
655 ImageCopyResampled($gdHist, $gdHistTemp, 0, 0, 0, 0, ImageSX($gdHist), ImageSY($gdHist), ImageSX($gdHistTemp), ImageSY($gdHistTemp));
656 ImageDestroy($gdHistTemp);
662 ImageDestroy($gdHist);
669 function ImageBorder(&$gdimg, $border_width, $radius_x, $radius_y, $hexcolor_border) {
670 $border_width = ($border_width ? $border_width : 1);
671 $radius_x = ($radius_x ? $radius_x : 0);
672 $radius_y = ($radius_y ? $radius_y : 0);
674 $output_width = ImageSX($gdimg);
675 $output_height = ImageSY($gdimg);
677 list($new_width, $new_height) =
phpthumb_functions::ProportionalResize($output_width, $output_height, $output_width - max($border_width * 2, $radius_x), $output_height - max($border_width * 2, $radius_y));
678 $offset_x = ($radius_x ? $output_width - $new_width - $radius_x : 0);
679 $offset_y = ($radius_y ? $output_height - $new_height - $radius_y : 0);
686 ImageSaveAlpha($gd_border_canvas,
true);
687 ImageAlphaBlending($gd_border_canvas,
false);
689 ImageFilledRectangle($gd_border_canvas, 0, 0, $output_width, $output_height, $color_background);
693 for (
$i = 0;
$i < $border_width;
$i++) {
694 ImageLine($gd_border_canvas, floor($offset_x / 2) + $radius_x,
$i, $output_width - $radius_x - ceil($offset_x / 2),
$i, $color_border);
695 ImageLine($gd_border_canvas, floor($offset_x / 2) + $radius_x, $output_height - 1 -
$i, $output_width - $radius_x - ceil($offset_x / 2), $output_height - 1 -
$i, $color_border);
696 ImageLine($gd_border_canvas, floor($offset_x / 2) +
$i, $radius_y, floor($offset_x / 2) +
$i, $output_height - $radius_y, $color_border);
697 ImageLine($gd_border_canvas, $output_width - 1 -
$i - ceil($offset_x / 2), $radius_y, $output_width - 1 -
$i - ceil($offset_x / 2), $output_height - $radius_y, $color_border);
700 if ($radius_x && $radius_y) {
708 for ($thickness_offset = 0; $thickness_offset < $border_width; $thickness_offset++) {
709 ImageArc($gd_border_canvas, floor($offset_x / 2) + 1 + $radius_x, $thickness_offset - 1 + $radius_y, $radius_x * 2, $radius_y * 2, 180, 270, $color_border);
710 ImageArc($gd_border_canvas, $output_width - $radius_x - 1 - ceil($offset_x / 2), $thickness_offset - 1 + $radius_y, $radius_x * 2, $radius_y * 2, 270, 360, $color_border);
711 ImageArc($gd_border_canvas, $output_width - $radius_x - 1 - ceil($offset_x / 2), $output_height - $thickness_offset - $radius_y, $radius_x * 2, $radius_y * 2, 0, 90, $color_border);
712 ImageArc($gd_border_canvas, floor($offset_x / 2) + 1 + $radius_x, $output_height - $thickness_offset - $radius_y, $radius_x * 2, $radius_y * 2, 90, 180, $color_border);
714 if ($border_width > 1) {
715 for ($thickness_offset = 0; $thickness_offset < $border_width; $thickness_offset++) {
716 ImageArc($gd_border_canvas, floor($offset_x / 2) + $thickness_offset + $radius_x, $radius_y, $radius_x * 2, $radius_y * 2, 180, 270, $color_border);
717 ImageArc($gd_border_canvas, $output_width - $thickness_offset - $radius_x - 1 - ceil($offset_x / 2), $radius_y, $radius_x * 2, $radius_y * 2, 270, 360, $color_border);
718 ImageArc($gd_border_canvas, $output_width - $thickness_offset - $radius_x - 1 - ceil($offset_x / 2), $output_height - $radius_y, $radius_x * 2, $radius_y * 2, 0, 90, $color_border);
719 ImageArc($gd_border_canvas, floor($offset_x / 2) + $thickness_offset + $radius_x, $output_height - $radius_y, $radius_x * 2, $radius_y * 2, 90, 180, $color_border);
724 $this->phpThumbObject->ImageResizeFunction($gd_border_canvas, $gdimg, floor(($output_width - $new_width) / 2), round(($output_height - $new_height) / 2), 0, 0, $new_width, $new_height, $output_width, $output_height);
726 ImageDestroy($gdimg);
728 ImageSaveAlpha($gdimg,
true);
729 ImageAlphaBlending($gdimg,
false);
731 ImageFilledRectangle($gdimg, 0, 0, $output_width, $output_height, $gdimg_color_background);
733 ImageCopy($gdimg, $gd_border_canvas, 0, 0, 0, 0, $output_width, $output_height);
735 ImageDestroy($gd_border_canvas);
740 $this->
DebugMessage(
'FAILED: $gd_border_canvas = phpthumb_functions::ImageCreateFunction('.$output_width.
', '.$output_height.
')', __FILE__, __LINE__);
746 function ImprovedImageRotate(&$gdimg_source, $rotate_angle=0, $config_background_hexcolor=
'FFFFFF', $bg=null) {
747 while ($rotate_angle < 0) {
748 $rotate_angle += 360;
750 $rotate_angle = $rotate_angle % 360;
751 if ($rotate_angle != 0) {
760 for (
$i = 0;
$i <= 255;
$i++) {
761 $color_mask[
$i] = ImageColorAllocate($gdimg_rotate_mask,
$i,
$i,
$i);
763 ImageFilledRectangle($gdimg_rotate_mask, 0, 0, ImageSX($gdimg_rotate_mask), ImageSY($gdimg_rotate_mask), $color_mask[255]);
764 $imageX = ImageSX($gdimg_source);
765 $imageY = ImageSY($gdimg_source);
766 for ($x = 0; $x < $imageX; $x++) {
767 for ($y = 0; $y < $imageY; $y++) {
769 ImageSetPixel($gdimg_rotate_mask, $x, $y, $color_mask[255 - round($pixelcolor[
'alpha'] * 255 / 127)]);
772 $gdimg_rotate_mask = ImageRotate($gdimg_rotate_mask, $rotate_angle, $color_mask[0]);
773 $gdimg_source = ImageRotate($gdimg_source, $rotate_angle, $background_color);
775 ImageAlphaBlending($gdimg_source,
false);
776 ImageSaveAlpha($gdimg_source,
true);
779 $phpThumbFilters->phpThumbObject = $this;
780 $phpThumbFilters->ApplyMask($gdimg_rotate_mask, $gdimg_source);
782 ImageDestroy($gdimg_rotate_mask);
794 } elseif ($rotate_angle % 90) {
800 if (ImageColorTransparent($gdimg_source) >= 0) {
805 if (!function_exists(
'ImageIsTrueColor') || !ImageIsTrueColor($gdimg_source)) {
813 ImageCopy($gdimg_newsrc, $gdimg_source, 0, 0, 0, 0, ImageSX($gdimg_source), ImageSY($gdimg_source));
814 ImageDestroy($gdimg_source);
815 unset($gdimg_source);
816 $gdimg_source = $gdimg_newsrc;
817 unset($gdimg_newsrc);
823 ImageColorTransparent($gdimg_source),
824 hexdec(substr($config_background_hexcolor, 0, 2)),
825 hexdec(substr($config_background_hexcolor, 2, 2)),
826 hexdec(substr($config_background_hexcolor, 4, 2)));
828 ImageColorTransparent($gdimg_source, -1);
833 $gdimg_source = ImageRotate($gdimg_source, $rotate_angle, $background_color);
843 if (ImageFilter($gdimg, IMG_FILTER_MEAN_REMOVAL)) {
846 $this->
DebugMessage(
'FAILED: ImageFilter($gdimg, IMG_FILTER_MEAN_REMOVAL)', __FILE__, __LINE__);
850 $this->
DebugMessage(
'FAILED: phpthumb_filters::MeanRemoval($gdimg) [function not implemented]', __FILE__, __LINE__);
857 if (ImageFilter($gdimg, IMG_FILTER_NEGATE)) {
860 $this->
DebugMessage(
'FAILED: ImageFilter($gdimg, IMG_FILTER_NEGATE)', __FILE__, __LINE__);
863 $ImageSX = ImageSX($gdimg);
864 $ImageSY = ImageSY($gdimg);
865 for ($x = 0; $x < $ImageSX; $x++) {
866 for ($y = 0; $y < $ImageSY; $y++) {
869 ImageSetPixel($gdimg, $x, $y, $newColor);
883 $color_transparent = ImageColorAllocate($gdimg_cornermask_triple, 255, 255, 255);
884 ImageFilledEllipse($gdimg_cornermask_triple, $radius_x * 3, $radius_y * 3, $radius_x * 4, $radius_y * 4, $color_transparent);
886 ImageFilledRectangle($gdimg_cornermask, 0, 0, ImageSX($gdimg), ImageSY($gdimg), $color_transparent);
888 ImageCopyResampled($gdimg_cornermask, $gdimg_cornermask_triple, 0, 0, $radius_x, $radius_y, $radius_x, $radius_y, $radius_x * 2, $radius_y * 2);
889 ImageCopyResampled($gdimg_cornermask, $gdimg_cornermask_triple, 0, ImageSY($gdimg) - $radius_y, $radius_x, $radius_y * 3, $radius_x, $radius_y, $radius_x * 2, $radius_y * 2);
890 ImageCopyResampled($gdimg_cornermask, $gdimg_cornermask_triple, ImageSX($gdimg) - $radius_x, ImageSY($gdimg) - $radius_y, $radius_x * 3, $radius_y * 3, $radius_x, $radius_y, $radius_x * 2, $radius_y * 2);
891 ImageCopyResampled($gdimg_cornermask, $gdimg_cornermask_triple, ImageSX($gdimg) - $radius_x, 0, $radius_x * 3, $radius_y, $radius_x, $radius_y, $radius_x * 2, $radius_y * 2);
894 ImageDestroy($gdimg_cornermask);
895 $this->
DebugMessage(
'RoundedImageCorners('.$radius_x.
', '.$radius_y.
') succeeded', __FILE__, __LINE__);
899 $this->
DebugMessage(
'FAILED: $gdimg_cornermask = phpthumb_functions::ImageCreateFunction('.ImageSX($gdimg).
', '.ImageSY($gdimg).
')', __FILE__, __LINE__);
901 ImageDestroy($gdimg_cornermask_triple);
904 $this->
DebugMessage(
'FAILED: $gdimg_cornermask_triple = phpthumb_functions::ImageCreateFunction('.($radius_x * 6).
', '.($radius_y * 6).
')', __FILE__, __LINE__);
913 } elseif ($amount > 0) {
914 $amount = 0 - $amount;
916 $amount = abs($amount);
922 function Sepia(&$gdimg, $amount, $targetColor) {
923 $amount = (is_numeric($amount) ? max(0, min(100, $amount)) : 50);
924 $amountPct = $amount / 100;
932 if (ImageFilter($gdimg, IMG_FILTER_GRAYSCALE)) {
934 $r = round($amountPct * hexdec(substr($targetColor, 0, 2)));
935 $g = round($amountPct * hexdec(substr($targetColor, 2, 2)));
936 $b = round($amountPct * hexdec(substr($targetColor, 4, 2)));
937 if (ImageFilter($gdimg, IMG_FILTER_COLORIZE, $r, $g, $b)) {
940 $this->
DebugMessage(
'FAILED: ImageFilter($gdimg, IMG_FILTER_COLORIZE)', __FILE__, __LINE__);
945 $this->
DebugMessage(
'FAILED: ImageFilter($gdimg, IMG_FILTER_GRAYSCALE)', __FILE__, __LINE__);
951 $TargetPixel[
'red'] = hexdec(substr($targetColor, 0, 2));
952 $TargetPixel[
'green'] = hexdec(substr($targetColor, 2, 2));
953 $TargetPixel[
'blue'] = hexdec(substr($targetColor, 4, 2));
955 $ImageSX = ImageSX($gdimg);
956 $ImageSY = ImageSY($gdimg);
957 for ($x = 0; $x < $ImageSX; $x++) {
958 for ($y = 0; $y < $ImageSY; $y++) {
965 $SepiaAmount = ((128 - abs($GrayPixel[
'red'] - 128)) / 128) * $amountPct;
967 foreach ($TargetPixel as $key => $value) {
968 $NewPixel[$key] = round(max(0, min(255, $GrayPixel[$key] * (1 - $SepiaAmount) + ($TargetPixel[$key] * $SepiaAmount))));
971 ImageSetPixel($gdimg, $x, $y, $newColor);
979 $amount = min(25, max(0, $amount));
984 if (ImageFilter($gdimg, IMG_FILTER_SMOOTH, $amount)) {
987 $this->
DebugMessage(
'FAILED: ImageFilter($gdimg, IMG_FILTER_SMOOTH, '.$amount.
')', __FILE__, __LINE__);
991 $this->
DebugMessage(
'FAILED: phpthumb_filters::Smooth($gdimg, '.$amount.
') [function not implemented]', __FILE__, __LINE__);
997 $width = ImageSX($gdimg);
998 $height = ImageSY($gdimg);
999 if ($gdimg_mask = ImageCreateTrueColor($width, $height)) {
1000 $R = hexdec(substr($hexcolor, 0, 2));
1001 $G = hexdec(substr($hexcolor, 2, 2));
1002 $B = hexdec(substr($hexcolor, 4, 2));
1003 $targetPixel = array(
'red'=>$R,
'green'=>$G,
'blue'=>$B);
1004 $cutoffRange = $max_limit - $min_limit;
1005 for ($x = 0; $x < $width; $x++) {
1006 for ($y = 0; $y < $height; $y++) {
1009 $grayLevel = min($cutoffRange, MAX(0, -$min_limit + $colorDiff)) * (255 / MAX(1, $cutoffRange));
1010 $newColor = ImageColorAllocate($gdimg_mask, $grayLevel, $grayLevel, $grayLevel);
1011 ImageSetPixel($gdimg_mask, $x, $y, $newColor);
1021 $width = ImageSX($gdimg);
1022 $height = ImageSY($gdimg);
1023 $cutoff = min(255, max(0, ($cutoff ? $cutoff : 128)));
1024 for ($x = 0; $x < $width; $x++) {
1025 for ($y = 0; $y < $height; $y++) {
1028 if ($grayPixel[
'red'] < $cutoff) {
1033 ImageSetPixel($gdimg, $x, $y, $newColor);
1043 $width = ImageSX(
$image);
1044 $height = ImageSY(
$image);
1045 $image_copy = ImageCreateTrueColor($width, $height);
1047 ImageCopy($image_copy,
$image, 0, 0, 0, 0, $width, $height);
1048 ImageTrueColorToPalette(
$image, $dither, $ncolors);
1049 ImageColorMatch($image_copy,
$image);
1050 ImageDestroy($image_copy);
1055 $colors = max(min($colors, 256), 2);
1065 $targetPixel = array(
1066 'red' => hexdec(substr($targetColor, 0, 2)),
1067 'green' => hexdec(substr($targetColor, 2, 2)),
1068 'blue' => hexdec(substr($targetColor, 4, 2))
1072 $targetPixel = array(
1073 'red' => max(array_keys($Analysis[
'red'])),
1074 'green' => max(array_keys($Analysis[
'green'])),
1075 'blue' => max(array_keys($Analysis[
'blue']))
1079 $scaleR = $grayValue / $targetPixel[
'red'];
1080 $scaleG = $grayValue / $targetPixel[
'green'];
1081 $scaleB = $grayValue / $targetPixel[
'blue'];
1083 for ($x = 0; $x < ImageSX($gdimg); $x++) {
1084 for ($y = 0; $y < ImageSY($gdimg); $y++) {
1088 max(0, min(255, round($currentPixel[
'red'] * $scaleR))),
1089 max(0, min(255, round($currentPixel[
'green'] * $scaleG))),
1090 max(0, min(255, round($currentPixel[
'blue'] * $scaleB))),
1091 $currentPixel[
'alpha']
1093 ImageSetPixel($gdimg, $x, $y, $newColor);
1100 function WatermarkText(&$gdimg, $text, $size, $alignment, $hex_color=
'000000', $ttffont=
'', $opacity=100, $margin=5, $angle=0, $bg_color=
false, $bg_opacity=0, $fillextend=
'') {
1105 ImageAlphaBlending($gdimg,
true);
1107 if (preg_match(
'#^([0-9\\.\\-]*)x([0-9\\.\\-]*)(@[LCR])?$#i', $alignment, $matches)) {
1108 $originOffsetX = intval($matches[1]);
1109 $originOffsetY = intval($matches[2]);
1110 $alignment = (@$matches[4] ? $matches[4] :
'L');
1117 $metaTextArray = array(
1118 '^Fb' => $this->phpThumbObject->getimagesizeinfo[
'filesize'],
1119 '^Fk' => round($this->phpThumbObject->getimagesizeinfo[
'filesize'] / 1024),
1120 '^Fm' => round($this->phpThumbObject->getimagesizeinfo[
'filesize'] / 1048576),
1121 '^X' => $this->phpThumbObject->getimagesizeinfo[0],
1122 '^Y' => $this->phpThumbObject->getimagesizeinfo[1],
1123 '^x' => ImageSX($gdimg),
1124 '^y' => ImageSY($gdimg),
1127 $text = strtr($text, $metaTextArray);
1129 $text = str_replace(
"\r\n",
"\n", $text);
1130 $text = str_replace(
"\r",
"\n", $text);
1131 $textlines = explode(
"\n", $text);
1132 $this->
DebugMessage(
'Processing '.count($textlines).
' lines of text', __FILE__, __LINE__);
1134 if (@is_readable($ttffont) && is_file($ttffont)) {
1136 $opacity = 100 - intval(max(min($opacity, 100), 0));
1139 $this->
DebugMessage(
'Using TTF font "'.$ttffont.
'"', __FILE__, __LINE__);
1141 $TTFbox = ImageTTFbBox($size, $angle, $ttffont, $text);
1143 $min_x = min($TTFbox[0], $TTFbox[2], $TTFbox[4], $TTFbox[6]);
1144 $max_x = max($TTFbox[0], $TTFbox[2], $TTFbox[4], $TTFbox[6]);
1146 $text_width = round($max_x - $min_x);
1148 $min_y = min($TTFbox[1], $TTFbox[3], $TTFbox[5], $TTFbox[7]);
1149 $max_y = max($TTFbox[1], $TTFbox[3], $TTFbox[5], $TTFbox[7]);
1151 $text_height = round($max_y - $min_y);
1153 $TTFboxChar = ImageTTFbBox($size, $angle, $ttffont,
'jH');
1154 $char_min_y = min($TTFboxChar[1], $TTFboxChar[3], $TTFboxChar[5], $TTFboxChar[7]);
1155 $char_max_y = max($TTFboxChar[1], $TTFboxChar[3], $TTFboxChar[5], $TTFboxChar[7]);
1156 $char_height = round($char_max_y - $char_min_y);
1158 if ($alignment ==
'*') {
1160 $text_origin_y = $char_height + $margin;
1161 while (($text_origin_y - $text_height) < ImageSY($gdimg)) {
1162 $text_origin_x = $margin;
1163 while ($text_origin_x < ImageSX($gdimg)) {
1164 ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y, $letter_color_text, $ttffont, $text);
1165 $text_origin_x += ($text_width + $margin);
1167 $text_origin_y += ($text_height + $margin);
1174 switch ($alignment) {
1180 $text_origin_x = ($originOffsetX ? $originOffsetX - round($text_width / 2) : round((ImageSX($gdimg) - $text_width) / 2));
1181 $text_origin_y = $char_height + $margin + $originOffsetY;
1185 $text_origin_x = ($originOffsetX ? $originOffsetX - round($text_width / 2) : round((ImageSX($gdimg) - $text_width) / 2));
1186 $text_origin_y = ImageSY($gdimg) + $TTFbox[1] - $margin + $originOffsetY;
1190 $text_origin_x = $margin + $originOffsetX;
1191 $text_origin_y = ($originOffsetY ? $originOffsetY : round((ImageSY($gdimg) - $text_height) / 2) + $char_height);
1195 $text_origin_x = ($originOffsetX ? $originOffsetX - $text_width : ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin);
1196 $text_origin_y = ($originOffsetY ? $originOffsetY : round((ImageSY($gdimg) - $text_height) / 2) + $char_height);
1200 $text_origin_x = ($originOffsetX ? $originOffsetX - round($text_width / 2) : round((ImageSX($gdimg) - $text_width) / 2));
1201 $text_origin_y = ($originOffsetY ? $originOffsetY : round((ImageSY($gdimg) - $text_height) / 2) + $char_height);
1205 $text_origin_x = $margin + $originOffsetX;
1206 $text_origin_y = $char_height + $margin + $originOffsetY;
1210 $text_origin_x = ($originOffsetX ? $originOffsetX - $text_width : ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin);
1211 $text_origin_y = $char_height + $margin + $originOffsetY;
1215 $text_origin_x = $margin + $originOffsetX;
1216 $text_origin_y = ImageSY($gdimg) + $TTFbox[1] - $margin + $originOffsetY;
1221 $text_origin_x = ($originOffsetX ? $originOffsetX - $text_width : ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin);
1222 $text_origin_y = ImageSY($gdimg) + $TTFbox[1] - $margin + $originOffsetY;
1228 $text_background_alpha = round(127 * ((100 - min(max(0, $bg_opacity), 100)) / 100));
1233 $x1 = $text_origin_x + $min_x;
1234 $y1 = $text_origin_y + $TTFbox[1];
1235 $x2 = $text_origin_x + $min_x + $text_width;
1236 $y2 = $text_origin_y + $TTFbox[1] - $text_height;
1237 $x_TL = preg_match(
'#x#i', $fillextend) ? 0 : min($x1, $x2);
1238 $y_TL = preg_match(
'#y#i', $fillextend) ? 0 : min($y1, $y2);
1239 $x_BR = preg_match(
'#x#i', $fillextend) ? ImageSX($gdimg) : max($x1, $x2);
1240 $y_BR = preg_match(
'#y#i', $fillextend) ? ImageSY($gdimg) : max($y1, $y2);
1246 $this->
DebugMessage(
'WatermarkText() calling ImageFilledRectangle($gdimg, '.$x_TL.
', '.$y_TL.
', '.$x_BR.
', '.$y_BR.
', $text_color_background)', __FILE__, __LINE__);
1247 ImageFilledRectangle($gdimg, $x_TL, $y_TL, $x_BR, $y_BR, $text_color_background);
1253 foreach ($textlines as $dummy => $line) {
1255 $TTFboxLine = ImageTTFbBox($size, $angle, $ttffont, $line);
1256 $min_x_line = min($TTFboxLine[0], $TTFboxLine[2], $TTFboxLine[4], $TTFboxLine[6]);
1257 $max_x_line = max($TTFboxLine[0], $TTFboxLine[2], $TTFboxLine[4], $TTFboxLine[6]);
1259 $text_width_line = round($max_x_line - $min_x_line);
1261 $min_y_line = min($TTFboxLine[1], $TTFboxLine[3], $TTFboxLine[5], $TTFboxLine[7]);
1262 $max_y_line = max($TTFboxLine[1], $TTFboxLine[3], $TTFboxLine[5], $TTFboxLine[7]);
1264 $text_height_line = round($max_y_line - $min_y_line);
1266 switch ($alignment) {
1278 $text_origin_x = ($originOffsetX ? $originOffsetX - round($text_width_line / 2) : round((ImageSX($gdimg) - $text_width_line) / 2));
1284 $text_origin_x = ($originOffsetX ? $originOffsetX - $text_width_line : ImageSX($gdimg) - $text_width_line + $TTFbox[0] - $min_x + round($size * 0.25) - $margin);
1289 $this->
DebugMessage(
'WatermarkText() calling ImageTTFtext($gdimg, '.$size.
', '.$angle.
', '.$text_origin_x.
', '.($text_origin_y + $y_offset).
', $letter_color_text, '.$ttffont.
', '.$line.
')', __FILE__, __LINE__);
1290 ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y + $y_offset, $letter_color_text, $ttffont, $line);
1292 $y_offset += $char_height;
1300 $size = min(5, max(1, $size));
1301 $this->
DebugMessage(
'Using built-in font (size='.$size.
') for text watermark'.($ttffont ?
' because $ttffont !is_readable('.$ttffont.
')' :
''), __FILE__, __LINE__);
1305 foreach ($textlines as $dummy => $line) {
1306 $text_width = max($text_width, ImageFontWidth($size) * strlen($line));
1307 $text_height += ImageFontHeight($size);
1310 ImageAlphaBlending($img_watermark,
false);
1312 $text_background_alpha = round(127 * ((100 - min(max(0, $bg_opacity), 100)) / 100));
1317 $this->
DebugMessage(
'WatermarkText() calling ImageFilledRectangle($img_watermark, 0, 0, '.ImageSX($img_watermark).
', '.ImageSY($img_watermark).
', $text_color_background)', __FILE__, __LINE__);
1318 ImageFilledRectangle($img_watermark, 0, 0, ImageSX($img_watermark), ImageSY($img_watermark), $text_color_background);
1320 if ($angle && function_exists(
'ImageRotate')) {
1323 $mask_color_background = ImageColorAllocate($img_watermark_mask, 0, 0, 0);
1324 ImageAlphaBlending($img_watermark_mask,
false);
1325 ImageFilledRectangle($img_watermark_mask, 0, 0, ImageSX($img_watermark_mask), ImageSY($img_watermark_mask), $mask_color_background);
1326 $mask_color_watermark = ImageColorAllocate($img_watermark_mask, 255, 255, 255);
1331 foreach ($textlines as $key => $line) {
1332 switch ($alignment) {
1334 $x_offset = round(($text_width - (ImageFontWidth($size) * strlen($line))) / 2);
1335 $originOffsetX = (ImageSX($gdimg) - ImageSX($img_watermark)) / 2;
1336 $originOffsetY = (ImageSY($gdimg) - ImageSY($img_watermark)) / 2;
1340 $x_offset = round(($text_width - (ImageFontWidth($size) * strlen($line))) / 2);
1341 $originOffsetX = (ImageSX($gdimg) - ImageSX($img_watermark)) / 2;
1342 $originOffsetY = $margin;
1346 $x_offset = round(($text_width - (ImageFontWidth($size) * strlen($line))) / 2);
1347 $originOffsetX = (ImageSX($gdimg) - ImageSX($img_watermark)) / 2;
1348 $originOffsetY = ImageSY($gdimg) - ImageSY($img_watermark) - $margin;
1353 $originOffsetX = $margin;
1354 $originOffsetY = (ImageSY($gdimg) - ImageSY($img_watermark)) / 2;
1359 $originOffsetX = $margin;
1360 $originOffsetY = $margin;
1365 $originOffsetX = $margin;
1366 $originOffsetY = ImageSY($gdimg) - ImageSY($img_watermark) - $margin;
1370 $x_offset = $text_width - (ImageFontWidth($size) * strlen($line));
1371 $originOffsetX = ImageSX($gdimg) - ImageSX($img_watermark) - $margin;
1372 $originOffsetY = (ImageSY($gdimg) - ImageSY($img_watermark)) / 2;
1376 $x_offset = $text_width - (ImageFontWidth($size) * strlen($line));
1377 $originOffsetX = ImageSX($gdimg) - ImageSX($img_watermark) - $margin;
1378 $originOffsetY = $margin;
1383 $x_offset = $text_width - (ImageFontWidth($size) * strlen($line));
1384 $originOffsetX = ImageSX($gdimg) - ImageSX($img_watermark) - $margin;
1385 $originOffsetY = ImageSY($gdimg) - ImageSY($img_watermark) - $margin;
1388 $this->
DebugMessage(
'WatermarkText() calling ImageString($img_watermark, '.$size.
', '.$x_offset.
', '.($key * ImageFontHeight($size)).
', '.$line.
', $text_color_watermark)', __FILE__, __LINE__);
1389 ImageString($img_watermark, $size, $x_offset, $key * ImageFontHeight($size), $line, $text_color_watermark);
1390 if ($angle && $img_watermark_mask) {
1391 $this->
DebugMessage(
'WatermarkText() calling ImageString($img_watermark_mask, '.$size.
', '.$x_offset.
', '.($key * ImageFontHeight($size)).
', '.$text.
', $mask_color_watermark)', __FILE__, __LINE__);
1392 ImageString($img_watermark_mask, $size, $x_offset, $key * ImageFontHeight($size), $text, $mask_color_watermark);
1395 if ($angle && $img_watermark_mask) {
1396 $img_watermark = ImageRotate($img_watermark, $angle, $text_color_background);
1397 $img_watermark_mask = ImageRotate($img_watermark_mask, $angle, $mask_color_background);
1401 $this->
DebugMessage(
'WatermarkText() calling phpthumb_filters::WatermarkOverlay($gdimg, $img_watermark, '.($originOffsetX.
'x'.$originOffsetY).
', '.$opacity.
', 0)', __FILE__, __LINE__);
1403 ImageDestroy($img_watermark);
1412 function WatermarkOverlay(&$gdimg_dest, &$img_watermark, $alignment=
'*', $opacity=50, $margin_x=5, $margin_y=null) {
1414 if (is_resource($gdimg_dest) && is_resource($img_watermark)) {
1415 $watermark_source_x = 0;
1416 $watermark_source_y = 0;
1417 $img_source_width = ImageSX($gdimg_dest);
1418 $img_source_height = ImageSY($gdimg_dest);
1419 $watermark_source_width = ImageSX($img_watermark);
1420 $watermark_source_height = ImageSY($img_watermark);
1421 $watermark_opacity_percent = max(0, min(100, $opacity));
1422 $margin_y = (is_null($margin_y) ? $margin_x : $margin_y);
1423 $watermark_margin_x = ((($margin_x > 0) && ($margin_x < 1)) ? round((1 - $margin_x) * $img_source_width) : $margin_x);
1424 $watermark_margin_y = ((($margin_y > 0) && ($margin_y < 1)) ? round((1 - $margin_y) * $img_source_height) : $margin_y);
1425 if (preg_match(
'#^([0-9\\.\\-]*)x([0-9\\.\\-]*)$#i', $alignment, $matches)) {
1426 $watermark_destination_x = intval($matches[1]);
1427 $watermark_destination_y = intval($matches[2]);
1429 switch ($alignment) {
1433 ImageAlphaBlending($gdimg_tiledwatermark,
false);
1434 ImageSaveAlpha($gdimg_tiledwatermark,
true);
1436 ImageFill($gdimg_tiledwatermark, 0, 0, $text_color_transparent);
1448 for ($x = $watermark_margin_x; $x < ($img_source_width + $watermark_source_width); $x += ($watermark_source_width + $watermark_margin_x)) {
1449 for ($y = $watermark_margin_y; $y < ($img_source_height + $watermark_source_height); $y += ($watermark_source_height + $watermark_margin_y)) {
1451 $gdimg_tiledwatermark,
1457 min($watermark_source_width, $img_source_width - $x - $watermark_margin_x),
1458 min($watermark_source_height, $img_source_height - $y - $watermark_margin_y)
1463 $watermark_source_width = ImageSX($gdimg_tiledwatermark);
1464 $watermark_source_height = ImageSY($gdimg_tiledwatermark);
1465 $watermark_destination_x = 0;
1466 $watermark_destination_y = 0;
1468 ImageDestroy($img_watermark);
1469 $img_watermark = $gdimg_tiledwatermark;
1474 $watermark_destination_x = round((($img_source_width / 2) - ($watermark_source_width / 2)) + $watermark_margin_x);
1475 $watermark_destination_y = $watermark_margin_y;
1479 $watermark_destination_x = round((($img_source_width / 2) - ($watermark_source_width / 2)) + $watermark_margin_x);
1480 $watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y;
1484 $watermark_destination_x = $watermark_margin_x;
1485 $watermark_destination_y = round((($img_source_height / 2) - ($watermark_source_height / 2)) + $watermark_margin_y);
1489 $watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x;
1490 $watermark_destination_y = round((($img_source_height / 2) - ($watermark_source_height / 2)) + $watermark_margin_y);
1494 $watermark_destination_x = round(($img_source_width / 2) - ($watermark_source_width / 2));
1495 $watermark_destination_y = round(($img_source_height / 2) - ($watermark_source_height / 2));
1499 $watermark_destination_x = $watermark_margin_x;
1500 $watermark_destination_y = $watermark_margin_y;
1504 $watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x;
1505 $watermark_destination_y = $watermark_margin_y;
1516 $watermark_destination_x = $watermark_margin_x;
1517 $watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y;
1522 $watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x;
1523 $watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y;
1527 ImageAlphaBlending($gdimg_dest,
false);
1528 ImageSaveAlpha($gdimg_dest,
true);
1529 ImageSaveAlpha($img_watermark,
true);
1530 phpthumb_functions::ImageCopyRespectAlpha($gdimg_dest, $img_watermark, $watermark_destination_x, $watermark_destination_y, 0, 0, $watermark_source_width, $watermark_source_height, $watermark_opacity_percent);
1539 if (is_object($this->phpThumbObject)) {
1540 return $this->phpThumbObject->DebugMessage($message,
$file, $line);