PHP中的图像处理类 [英] Image processing class in PHP

查看:124
本文介绍了PHP中的图像处理类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要构建一个PHP照片处理类,我知道有一些已经存在的公众,但我需要构建一个,只做我需要做的,没有什么额外的,没有更少。

I need to build a PHP photo processing class, I know there are MANY that already exist to the public but I need to build one to do just what I need done and nothing extra and nothing less.

我需要我的班级这样做...

I need my class to do this...

1) br>
我创建一个新类的实例,并传入照片的URL,或者使用POST表单上传的本地照片的路径。

1)
I create a new instance of my class and I pass in either a URL of a photo, or the path to a local photo being uploaded using POST form.

2)

然后,我需要拍摄主图像并检查其尺寸,如果它的宽度更大的800像素,我需要调整它的大小,如果它是不大于800那么我就离开它

2)
I then need to take the main image and check it's dimensions, if it is wider the 800 pixels, I need to resize it down, if it is not wider then 800 then I just leave it

3)

现在我们需要创建2个不同大小的缩略图如果我们调整图像大小以满足我们的800像素要求,那么我们使用该图像来生成缩略图,否则我们会使用原始图像生成缩略图。

3)
We now need to build 2 different sized thumbnails from this image, if we resized the image to meet our 800 pixel requirement then we use that image to make the thumbnails from, otherwise we make our thumbnails from the original image.

4)

然后我们更新一些数据库记录

4)
We then update a few a database records

然后完成。

我知道这并不是那么困难,但是我需要以最好的性能构建这个,例如如果用户上传一张2mb的照片,我不想如果我们已经制作了一个较小的图像,我认为应该使用较小的图像来建立缩略图。

I know this is not that difficult but I need to build this with best performance in mind, for example if a user uploads a 2mb photo, I don't want to hog up memory and keep building thumbnails from that photo if we already madea smaller image I think it should then use the smaller image to build out thumbnails from.

有了所有这些信息现在,你有什么建议,如何在GD或imagemagick这样做。如果我做一个方法来做缩略图,我应该如何确保它继续使用较小的图像来制作其他较小的图像?我已经看过一些现有的图像类,他们都非常复杂,完成IMO,但没有一个完成这个简单的任务。

With all this information now, do you have any suggestions on how to do this in GD or imagemagick. If I make a method that does the thumbnails, how should I make sure it keeps using the smaller images to make other smaller images? I have looked at some existing image classes and they all are very complex and over done IMO however none do exactly this simple task.

推荐答案

PHP GD 库使用资源对象表示图像。您可以使用 imagecopyresampled imagecopyresized 调整图片大小。

The PHP GD library uses a resource object to represent images. You can use imagecopyresampled or imagecopyresized to resize the image.

如果已调整大小,请使用新调整大小的图像对象进行后续操作,否则使用原始资源对象。

If it has been resized, use the new resized image object for future operations, otherwise use the original resource object.

这篇关于PHP中的图像处理类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆