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: http://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_heig开发者_运维知识库ht);
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: http://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: http://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:
<?php
$body = imagecreatefromjpeg('http://i.stack.imgur.com/KJjDi.jpg');
$logo = imagecreatefromjpeg('http://b.vimeocdn.com/ps/161/161028_300.jpg');
$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
);
header('Content-Type: image/jpeg');
imagejpeg($image, null, 85);
?>
I'm gonna say it's got something to do with the actual images :-?
精彩评论