I’m experiencing some weirdness with PHP 5.3.3, i’m trying to add a watermark to an image.
$body = @imagecreatefromstring($image_data['body']);
imagejpeg($body, null, 85);
returns in: https://i.stack.imgur.com/KJjDi.jpg
$body = @imagecreatefromstring($image_data['body']);
$logo = @imagecreatefrompng(APP_ROOT . self::WATERMARK_PATH);
$body_width = (int) @imagesx($body);
$body_height = (int) @imagesy($body);
$logo_width = (int) @imagesx($logo);
$logo_height = (int) @imagesy($logo);
$image = imagecreatetruecolor($body_width + 4, $body_height + $logo_height);
imagecopy(
$image, $logo,
intval($body_width / 2) - ceil($logo_width / 2), $body_height,
0, 0, $logo_width, $logo_height
);
imagejpeg($image, null, 85);
returns in: https://i.stack.imgur.com/nwtqZ.jpg
buuuuuuuuut…… if i add the body (the cat) to the image…
$body = @imagecreatefromstring($image_data['body']);
$logo = @imagecreatefrompng(APP_ROOT . self::WATERMARK_PATH);
$body_width = (int) @imagesx($body);
$body_height = (int) @imagesy($body);
$logo_width = (int) @imagesx($logo);
$logo_height = (int) @imagesy($logo);
$image = imagecreatetruecolor($body_width + 4, $body_height + $logo_height);
imagecopy(
$image, $body,
1, 1,
0, 0, $body_width, $body_height
);
imagecopy(
$image, $logo,
intval($body_width / 2) - ceil($logo_width / 2), $body_height,
0, 0, $logo_width, $logo_height
);
imagejpeg($image, null, 85);
results in: https://i.stack.imgur.com/Xeb73.jpg
As you can see in this last one, the bottom of the image is corrupt or something…… wtf happened?
Trying this code I see absolutely no error:
I’m gonna say it’s got something to do with the actual images 😕