I have the following script which resizes and watermarks images, it all works fine, however when I add the line to only resize if required, the outputted image is just a black image with the watermark, anyone know why this is, and how I get around it? I assume it's because my script needs to execute imagecopyresampled() for some reason for the watermarking to work, and thus when it is not executed, I get a black (watermarked) image, thanks.
function watermark($images, $max, $quality, $wmark) {
foreach ($images as $img) {
// get sizes
list ($orig_width, $orig_height) = getimagesize($img);
list ($width, $height) = $this->get_sizes($orig_width, $orig_height, $max);
// original
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($img);
// resize if required
if ($orig_width > $width) imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $orig_width, $orig_height);
// watermark details
$watermark = imagecreatefrompng($wmark);
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
// where to place watermark
$dest_x = $width - $watermark_width - 5;
$dest_y = $height - $watermark_height - 5;
// create watermark
if (!imagecopymerge($image_p, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100)) {
// error
error::log(ERR_MED, 'Resizing and watermarking of '.$img.' unable to be completed.', ERR_SHOW);
exit();
}
imagejpeg($image_p, $img, $quality);
// destroy
imagedestroy($image_p);
imagedestroy($watermark);
}
}