Hoping someone out there can help. I recently updated to the latest version of PHP5 and now the program I was using for watermarking has stopped working.
If I change the program below to imagecreatefromgif() it works fine, but I lose transparency.
The following program slaps a png watermark on top of any image that is hotlinked (via .htaccess). It's been working great for years.
Is there another way to accomplish this that is compatible with this version of PHP5?
FreeBSD 6.2
Apache2.2.13
PHP Version 5.2.11
- GD Version bundled (2.0.34 compatible)
- PNG Support enabled
<?php
//Set placement of watermark.
//$horizontal can be left, right, or center. Default is right.
//$vertical can be top, bottom, or center. Default is bottom.
$horizontal = 'right';
$vertical = 'bottom';
header('content-type: image/jpeg');
$watermark = imagecreatefrompng('watermarkst24b.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$src = $_GET["src"];
$image = imagecreatefromjpeg($src);
$size = getimagesize($src);
switch ($horizontal) {
case 'left':
$dest_x = 5;
break;
case 'right':
$dest_x = $size[0] - $watermark_width - 5;
break;
case 'center':
$dest_x = ($size[0] / 2) - ($watermark_width / 2);
break;
default:
$dest_x = $size[0] - $watermark_width - 5;
}
switch ($vertical) {
case 'top':
$dest_y = 5;
break;
case 'bottom':
$dest_y = $size[1] - $watermark_height - 5;
break;
case 'center':
$dest_y = ($size[1] / 2) - ($watermark_height / 2);
break;
default:
$dest_y = $size[1] - $watermark_height - 5;
}
imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
?>
This is from the Apache22 error.log
PHP Warning: imagecreatefrompng() [<a href='function.imagecreatefrompng'>function.imagecreatefrompng</a>]: gd-png: fatal libpng error: [00][00][00][00]: unknown critical chunk in /path/watermark.php on line 9
PHP Warning: imagecreatefrompng() [<a href='function.imagecreatefrompng'>function.imagecreatefrompng</a>]: gd-png error: setjmp returns error condition in /path/watermark.php on line
PHP Warning: imagecreatefrompng() [<a href='function.imagecreatefrompng'>function.imagecreatefrompng</a>]: 'watermarkst24b.png' is not a valid PNG file in /path/watermark.php on line 9
PHP Warning: imagesx(): supplied argument is not a valid Image resource in /path/watermark.php on line 10
PHP Warning: imagesy(): supplied argument is not a valid Image resource in /path/watermark.php on line 11
PHP Warning: imagecopy(): supplied argument is not a valid Image resource in /path/watermark.php on line 44
PHP Warning: imagedestroy(): supplied argument is not a valid Image resource in /path/watermark.php on line 47