PHP GD imagecopy() 上的图像损坏
我在使用 PHP 5.3.3 时遇到了一些奇怪的情况,我正在尝试向图像添加水印。
$body = @imagecreatefromstring($image_data['body']);
imagejpeg($body, null, 85);
返回:https://i.sstatic.net/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);
返回:https://i.sstatic.net/nwtqZ.jpg
buuuuuuuuut......如果我添加身体(猫)到图像...
$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);
结果: https://i.sstatic.net/ Xeb73.jpg
正如您在最后一张中看到的那样,图像的底部已损坏或发生了其他情况……发生了什么?
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.sstatic.net/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.sstatic.net/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.sstatic.net/Xeb73.jpg
As you can see in this last one, the bottom of the image is corrupt or something...... wtf happened?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这段代码我发现绝对没有错误:
我想说它与实际图像有关:-?
Trying this code I see absolutely no error:
I'm gonna say it's got something to do with the actual images :-?