如何在codeigniter中裁剪图像?
我正在使用 codeigniter 构建一个项目,现在我需要根据用户选择创建一个拇指。就像他会给我 X1,Y1,X2,Y2,X3,Y3,X4,Y4 我想根据这 4 个点裁剪图像。我检查了图像处理类。裁剪功能似乎很奇怪。有什么帮助吗?
i'm using codeigniter to build a project and right now i need to create a thumb depending on user choice. like he will give me X1,Y1,X2,Y2,X3,Y3,X4,Y4 i want to crop the image depending on that 4 points. i checked the image manipulation class. the crop function seems to be very strange. any help please ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要设置 x 轴(左)、宽度(右)、y 轴(顶部)和高度(底部)。您需要确保设置图像的宽度和高度。
上面的代码将图像的左、右、上、下各裁剪 10 个像素。您可以随意将“10”的值更改为您喜欢的值;)
You will need to set the x-axis (left), width (right), y-axis (top), and height (bottom). You need to be sure to set the width and height of the image.
The code above will crop the image by 10 pixels on the left, right, top, and bottom. you can feel free to change the value of '10' to whichever value you prefer ;)
我知道图像库中这个特定函数的文档很少。裁剪函数只要求您提供轴。然后它将沿着这些轴进行切割并返回图像中更靠近中心的部分。因此,如果将 x 轴设置为 10,y 轴设置为 10,它将删除图像的顶部 10 像素和左侧 10 像素。同样,如果将 x 轴设置为图像宽度 - 10,它将从图像右侧裁剪 10 个像素。
你的四个位置告诉你的实际上是四个不同的轴。因此,需要进行两次操作。您只需要更改每个 $this->image_lib->crop() 之间的轴即可。
如何找出这些轴取决于您如何获取这些数据。在数组中,作为单独的值等,所以我不会讨论这个。
I know that the documentation is sparse on this particular function in the image library. The crop function asks you only to supply to axises. It will then cut along these axes and return the part of the image which is closer to the center. So if you set the x axis to 10 and the y axis to 10 it will remove the top 10px of the image and the left 10 px of the image. Similarly, if you set the x axis to the image width - 10 it will crop 10 pixels from the right of the image.
What your four positions tell you are really four different axises. Therefore, you need to do two operations. You just need to change the axises in between each $this->image_lib->crop().
How to figure out these axises depends on how you get this data. In an array, as separate values etc. so I won't go into this.
我没有从 gd2 库中得到任何结果。
它总是调整图像的大小,但更新作物。
所以这里是 imagemagick 的解决方案并且效果很好。
i am not getting any results with gd2 library.
it always resizes image, but newer crops.
so here is the solution with imagemagick and works great.