仅显示图像的某些部分并使用 GD 调整其大小
我目前已经准备好一个脚本,可以使用 GD 调整整个图像的大小,但我需要获取图像的特定部分来显示并仅调整该特定部分的大小。
这是图像:
这是需要显示的内容,用Photoshop把剩下的部分拿出来:
最终图像需要为 150x150 。
这是我尝试过的脚本:
<?php
$srcp = imagecreatefrompng("enjikaka.png");
$destp = imagecreate(150, 150);
imagecopyresampled($destp, $srcp, 0, 0, -8, -8, 150, 150, 64, 32);
header('Content-type: image/png');
imagepng($destp);
?>
但是这个脚本没有选择图像的正确部分。有人可以帮我吗?
I currently have a script ready that resizes a whole image with GD but I need to get a specific part of an image to display and resize only that specific part.
This is the image:
This is what needs to be displayed, took out the rest with Photoshop:
The final image needs to be 150x150.
This is the script i tried:
<?php
$srcp = imagecreatefrompng("enjikaka.png");
$destp = imagecreate(150, 150);
imagecopyresampled($destp, $srcp, 0, 0, -8, -8, 150, 150, 64, 32);
header('Content-type: image/png');
imagepng($destp);
?>
But this one does not pick the correct part of the image. Can anyone help me here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么是(-8,-8)?这些应该是您要复制的区域的左上角。它应该是 8, 8。最后两个参数:(64, 32) 是源区域的宽度和高度。那些也应该是8、8。
我在这里假设您的源图像是由 8x8 单元构建的。你应该检查photosop中的坐标。
我建议您阅读该函数的文档。当事情没有按你的预期发展时,这应该是你做的第一件事。
Why the (-8, -8)? Those should be the upper left corner of your area to copy. It should be 8, 8. And the last two parameters: (64, 32) are the width and height of your source area. Those should be 8, 8 too.
I assume here that your source image is built up by 8x8 units. You should check the coordinates in photosop.
I suggest you read the documentation of the function. That shopuld be the first thing you do when things do not go as you expected.
我认为您应该在脚本中包含对 imagecopy 的调用,该调用应该处理图像的裁剪。
I think you should include this call to imagecopy in your script, which should handle the cropping of the image.