如何使用 PHP 从底部剪切图像?
我想去掉图像底部的文字。我怎样才能从底部切割它......比如说从底部切割10个像素。
我想用 PHP 来做这个。我有很多底部有文字的图像。
有办法做到吗?
I want to take out the text in the bottom of an image. How can I cut it from bottom ...say 10 pixels to cut from bottom.
I want do this in PHP. I have lots of images that have text in the bottom.
Is there a way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
干得好。
要更改图像的名称,请更改 $in_filename(当前为“source.jpg”)。您也可以在其中使用 URL,尽管显然这会表现得更差。
更改 $new_height 变量以设置要裁剪的底部数量。
尝试一下 $offset_x、$offset_y、$new_width 和 $new_height,你就会明白的。
请让我知道它有效。 :)
希望有帮助!
Here you go.
To change the name of the image, change $in_filename (currently 'source.jpg'). You can use URLs in there as well, although obviously that will perform worse.
Change the $new_height variable to set how much of the bottom you want cropped.
Play around with $offset_x, $offset_y, $new_width and $new_height, and you'll figure it out.
Please let me know that it works. :)
Hope it helps!
您可以使用 GD 图像库 在 PHP 中操作图像。您正在寻找的函数是
imagecopy()
,它将图像的一部分复制到另一个图像上。下面是来自 PHP.net 的示例,大致按照您的描述进行操作:要裁剪源图像,请根据您的喜好更改
$source_x
和$source_y
变量。You may use the GD Image Library to manipulate images in PHP. The function you're looking for is
imagecopy()
, which copies part of an image onto another. Here's an example from PHP.net that does roughly what you describe:To crop the source image, change the
$source_x
and$source_y
variables to your liking.