Best PHP Image Crop Class

前端 未结 9 1080
盖世英雄少女心
盖世英雄少女心 2021-01-30 14:30

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 Imag
相关标签:
9条回答
  • 2021-01-30 15:10

    My personal favorite Image Manipulation Library is WideImage. It makes is ridiculously easy to do that kind of task.

    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.

    Using finfo:

    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mimetype = finfo_file($finfo, $filename);
    
    $isImage = (preg_match('#^image/#', $mimetype) === 1);
    

    Using PEAR::Mime_Type:

    $mimetype = MIME_Type::autoDetect($filename);
    
    $isImage = MIME_Type::wildcardMatch('image/*', $mimetype);
    
    0 讨论(0)
  • 2021-01-30 15:19

    I am using this Image crop, it working well

    Simple PHP Image cCrop

    0 讨论(0)
  • 2021-01-30 15:21

    there's also this lightweight image manipulation library written in PHP called Zebra_Image that's very small, not bloated with zillion of functions you'll never use, highly optimized, with a great documentation and which is actively maintained.

    0 讨论(0)
  • 2021-01-30 15:27

    I recommend to use 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.

    0 讨论(0)
  • 2021-01-30 15:27

    If you're willing to migrate into an MVC PHP framework, I strongly recommend 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).

    You can check them out at:

    Image manipulation class

    File uploading class

    0 讨论(0)
  • 2021-01-30 15:30

    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

    And if you want to make the uploader a tiny bit better than just an input type=file, try:

    https://github.com/valums/file-uploader

    0 讨论(0)
提交回复
热议问题