最佳 PHP 图像裁剪类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6460578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best PHP Image Crop Class
提问by Tomas
I'm designing a website and I need to:
我正在设计一个网站,我需要:
- Upload the image
- Validate that it's an image (and not, oh I don't know.... a virus :) )
- Resize the Image
- convert to jpg
- 上传图片
- 验证它是一个图像(而不是,哦,我不知道......病毒:))
- 调整图像大小
- 转换为jpg
Essentially basic image upload
基本上是基本的图片上传
Instead of writing my own I'm trying to find a phpclass that let's me do all this, because as Jeff Atwood said, "never design what you can steal"
我不是自己写,而是试图找到一个让我做这一切的php类,因为正如杰夫阿特伍德所说,“永远不要设计你可以窃取的东西”
Now before you go ahead and downvote because I didn't do my research, I did:
现在,在你继续投票之前,因为我没有做我的研究,我做了:
Googling this brings up a huge amount of results, which is the problem, I don't know which results are useful and which are trash!
谷歌搜索这带来了大量的结果,这是问题所在,我不知道哪些结果有用,哪些结果是垃圾!
So far, Ive found:
到目前为止,我发现:
- https://stackoverflow.com/questions/4997127/php-class-to-upload-image-from-url-and-resize-it(I know it looks like a duplicate, but its not because it is asking for a URL fetcher)
- http://net.tutsplus.com/tutorials/php/image-resizing-made-easy-with-php/
- http://www.verot.net/php_class_upload.htm
- http://blog.freelancer-id.com/index.php/2010/03/21/php-image-crop-resize-upload
- http://www.phpclasses.org/package/2181-PHP-Process-files-and-images-uploaded-via-a-form.html
- http://www.digitalgemstones.com/code/tools/ImgUploader.php
- https://stackoverflow.com/questions/4997127/php-class-to-upload-image-from-url-and-resize-it(我知道它看起来像重复,但不是因为它要求一个 URL取物器)
- http://net.tutsplus.com/tutorials/php/image-resizing-made-easy-with-php/
- http://www.verot.net/php_class_upload.htm
- http://blog.freelancer-id.com/index.php/2010/03/21/php-image-crop-resize-upload
- http://www.phpclasses.org/package/2181-PHP-Process-files-and-images-uploaded-via-a-form.html
- http://www.digitalgemstones.com/code/tools/ImgUploader.php
Does anyone have any experience with these classes? Can you recommend an outstanding image upload class?
有没有人有这些课程的经验?你能推荐一个优秀的图片上传类吗?
采纳答案by benlumley
I tend to use a framework of one description or another, which cover's the file upload part. However, do have a recommendation for the cropping bit:
我倾向于使用一种描述或另一种描述的框架,其中包括文件上传部分。但是,对裁剪位有一个建议:
Imagine - https://github.com/avalanche123/Imagine
想象一下 - https://github.com/avalanche123/Imagine
And if you want to make the uploader a tiny bit better than just an input type=file, try:
如果你想让上传器比输入类型=文件更好一点,请尝试:
回答by Andrew Moore
My personal favorite Image Manipulation Library is WideImage
. It makes is ridiculously easy to do that kind of task.
我个人最喜欢的图像处理库是WideImage
. 做这样的任务变得非常容易。
WideImage::load('pic.png')
->crop('center', 'center', 90, 50)->saveToFile('cropped/pic.jpg');
As for validating if it is actually an image or not, use finfo
or PEAR::Mime_type
. I personally prefer PEAR::Mime_Type
. It uses finfo
but it's just simpler to use.
至于验证它是否确实是图像,请使用finfo
或PEAR::Mime_type
。我个人更喜欢PEAR::Mime_Type
. 它使用finfo
但使用起来更简单。
Using finfo
:
使用finfo
:
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mimetype = finfo_file($finfo, $filename);
$isImage = (preg_match('#^image/#', $mimetype) === 1);
Using PEAR::Mime_Type
:
使用PEAR::Mime_Type
:
$mimetype = MIME_Type::autoDetect($filename);
$isImage = MIME_Type::wildcardMatch('image/*', $mimetype);
回答by Nikz
Check out JCROP Plugin
查看 JCROP 插件
This will be uselful for all
这对所有人都有用
JCROP Image cropping----deepliquid.com/content/Jcrop.html
JCROP 图片裁剪----deepliquid.com/content/Jcrop.html
回答by Stefan Gabos
there's also this lightweight image manipulation library written in PHPcalled Zebra_Imagethat's very small, not bloated with zillion of functions you'll never use, highly optimized, with a great documentationand which is actively maintained.
还有这个用 PHP 编写的名为Zebra_Image 的轻量级图像处理库,它非常小,不会因无数您永远不会使用的函数而变得臃肿,高度优化,有很好的文档,并得到积极维护。
回答by Hans Kerkhof
The class upload from Colin Verot http://www.verot.net/php_class_upload.htmis my favourite. I use in in all my projects. Like the way you 'talk' to the class and only use what your need, but gives plenty of configuration/methods to tweak it to your exact needs. Great class!
从 Colin Verot http://www.verot.net/php_class_upload.htm上传的课程是我的最爱。我在我所有的项目中使用。就像你与班级“交谈”的方式,只使用你需要的东西,但提供了大量的配置/方法来调整它以满足你的确切需求。很棒的课!
回答by adam pery
I recommend to use Smart Image Resizer http://shiftingpixel.com/2008/03/03/smart-image-resizer/
我建议使用 Smart Image Resizer http://shiftingpixel.com/2008/03/03/smart-image-resizer/
You get the best image quality after resizing
调整大小后您将获得最佳图像质量
It's extremely simple to use. It uses image cache.
使用起来非常简单。它使用图像缓存。
回答by Marcio Mazzucato
I recommend SimpleImage, it is very simple, has only one file and is updated.
我推荐SimpleImage,它很简单,只有一个文件,而且是更新的。
Example of use:
使用示例:
$img = new SimpleImage('image.jpg');
// Resize the image to 320x200
$img->resize(320, 200);
$img->save('new-image.jpg');
回答by pepe
If you're willing to migrate into an MVC PHP framework, I strongly recommend Codeigniter.
如果您愿意迁移到 MVC PHP 框架,我强烈推荐Codeigniter。
Besides several other classes and libraries that handle pagination, tables, security, forms, etc CI also has nice upload and image manipulation classes that are very handy and flexible. I believe they can do all you require (just not sure about jpg conversion).
除了处理分页、表格、安全、表单等的几个其他类和库之外,CI 还具有非常方便和灵活的很好的上传和图像处理类。我相信他们可以满足您的所有要求(只是不确定 jpg 转换)。
You can check them out at:
您可以在以下位置查看它们: