edwrodrig/image

Library optimize images for web sites and create thumbnails

3.4.1 2020-09-02 16:09 UTC

README

Library to create optimized images and thumbnails for web, and compare images.

Latest Stable Version Total Downloads License Build Status codecov.io Code Coverage Code Climate

My use cases

  • Make a area contained thumbnail.
  • Create a area cover thumbnail.
  • Load SVG files transparently.
  • Optimize for web to meet the PageSpeed Insights suggestions about optimizing images.
  • Create small preview thumbnails of about <1Kb suitable for database columns.
  • Compare images to detect duplicates.
  • Enhance document images (diagrams, text, lineart)

My infrastructure is targeted to Ubuntu 16.04 machines with last php7.4 installed from ppa:ondrej/php

Examples

$image->contain(new Size(200, 200));
  • Cover

    OriginalTarget
$image->cover(new Size(200, 200));
  • Cover with automatic width

    OriginalTarget
$image->cover(new Size(0, 90));
  • Cover with automatic height

    OriginalTarget
$image->cover(new Size(90, 0));
  • Contain to 200x200

    OriginalTarget
$image->contain(new Size(200, 200));
  • Contain resize to 200x200

    OriginalTarget
$image->containResize(new Size(200, 200));

Composer

composer require edwrodrig/image

Dependencies

It needs rsvg-convert to convert svg images nicely. Also need compare to make image comparisons. You can install these dependencies in Ubuntu 16.04 with the following commands.

sudo apt install librsvg2-bin php-imagick

My current system information

Output of system_info.sh

  Operating System: Ubuntu 16.04.6 LTS
            Kernel: Linux 4.15.0-99-generic
PHP 7.4.5 (cli) (built: Apr 19 2020 07:36:13) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.5, Copyright (c), by Zend Technologies
    with Xdebug v2.9.3, Copyright (c) 2002-2020, by Derick Rethans
Version: ImageMagick 6.8.9-9 Q16 x86_64 2019-11-12 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff wmf x xml zlib

rsvg-convert version 2.40.13

Documentation

The source code is documented using phpDocumentor style, so it should pop up nicely if you're using IDEs like PhpStorm or similar.

Testing

The test are built using PhpUnit. It generates images and compare the signature with expected ones. Maybe some test fails due metadata of some generated images, but at the moment I haven't any reported issue.

License

MIT license. Use it as you want at your own risk.

About language

I'm not a native english writer, so there may be a lot of grammar and orthographical errors on text, I'm just trying my best. But feel free to correct my language, any contribution is welcome and for me they are a learning instance.