diff --git a/README.md b/README.md index 68943d9..1d38a1f 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ A 1.0 release will not be made until the following drivers are available and sol ### Transforms -A 1.0 release will be made available once the following transforms are available and solidly tested across all drivers: +A 1.0 release will be made available once the following transforms are available and solidly tested across all drivers. These are basically what I see as the bare minimum for such a library to be useful. * rotate (in 90 degree increments) * mirror-h @@ -25,8 +25,8 @@ A 1.0 release will be made available once the following transforms are available * max-width * max-height * fit (basically an alias for max-width and max-height) -* cover -* crop +* cover (scale to cover a box, then crop excess) +* crop (crop toward the center to a given size) * cover-crop (convenience transform, combining cover and crop, useful for thumbnails) The following transforms are also on my mind as possibilities, but may or may not make it into 1.0: @@ -34,3 +34,7 @@ The following transforms are also on my mind as possibilities, but may or may no * grayscale * colorize (needs to function consistently though) * overlay (i.e. for watermarking) +* blur +* hue +* saturation +* brightness diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..e244830 --- /dev/null +++ b/composer.json @@ -0,0 +1,25 @@ +{ + "name": "jobyone/image-transform", + "description": "A tightly-focused library for performing a very limited set of simple image transformations. This library's purpose is to eschew the standard kitchen sink approach to PHP image libraries in favor of high performance, wide driver support, and a dead simple API.", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Joby Elliott", + "email": "joby@byjoby.com" + } + ], + "autoload": { + "psr-4": { + "ByJoby\\ImageTransform\\": "src/" + } + }, + "suggest": { + "ext-imagick": "to use the Imagick implementation", + "ext-gmagick": "to use the Gmagick implementation" + }, + "require": { + "php": ">=7.1", + "ext-gd": "*" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..1261ea0 --- /dev/null +++ b/composer.lock @@ -0,0 +1,20 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "6eb3038135c5de665d7b86ae7ecb3427", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "ext-gd": "*" + }, + "platform-dev": [], + "plugin-api-version": "1.1.0" +} diff --git a/src/DriverInterface.php b/src/DriverInterface.php new file mode 100644 index 0000000..0b0e91f --- /dev/null +++ b/src/DriverInterface.php @@ -0,0 +1,10 @@ +source = $source; + // validate file + if (!is_file($this->source)) { + throw new \Exception("Image file doesn't exist: " . htmlentities($this->source)); + } + if (!exif_imagetype($this->source)) { + throw new \Exception("Invalid image file: " . htmlentities($this->source)); + } + // get height/width + list($this->originalWidth, $this->originalHeight) = getimagesize($this->source); + } +} diff --git a/src/Drivers/GDDriver.php b/src/Drivers/GDDriver.php new file mode 100644 index 0000000..ded729f --- /dev/null +++ b/src/Drivers/GDDriver.php @@ -0,0 +1,10 @@ +src = $src; + $this->driver = clone $driver; + $this->driver->source($src); + } + + public function transform(TransformInterface $transform) + { + $this->transforms[] = $transform; + } + + public function originalWidth(): int + { + return $this->driver->originalWidth(); + } + + public function originalHeight(): int + { + return $this->driver->originalHeight(); + } +} diff --git a/src/TransformInterface.php b/src/TransformInterface.php new file mode 100644 index 0000000..7eeaf3d --- /dev/null +++ b/src/TransformInterface.php @@ -0,0 +1,52 @@ +size = $size; + } + + public function willTransform(Image $image): bool + { + if ($image->originalWidth() <= $this->size) { + return false; + } else { + return true; + } + } +}