Skip to content

Commit

Permalink
Updated php-image-resize to 1.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
renekreijveld committed Mar 3, 2017
1 parent d3d2b94 commit 6544c13
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 36 deletions.
6 changes: 0 additions & 6 deletions source/plg_rsfp_imageresize/vendor/composer/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ class ClassLoader
private $classMap = array();
private $classMapAuthoritative = false;
private $missingClasses = array();
<<<<<<< Updated upstream
=======
private $apcuPrefix;
>>>>>>> Stashed changes

public function getPrefixes()
{
Expand Down Expand Up @@ -358,13 +355,10 @@ public function findFile($class)
$file = $this->findFileWithExtension($class, '.hh');
}

<<<<<<< Updated upstream
=======
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}

>>>>>>> Stashed changes
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
$baseDir = dirname($vendorDir);

return array(
'Eventviva\\ImageResize' => $vendorDir . '/eventviva/php-image-resize/src/ImageResize.php',
'Eventviva\\ImageResize' => $vendorDir . '/eventviva/php-image-resize/lib/ImageResize.php',
);
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class ComposerStaticInit1f47e521aa532623ee8c604463465c1e
{
public static $classMap = array (
'Eventviva\\ImageResize' => __DIR__ . '/..' . '/eventviva/php-image-resize/src/ImageResize.php',
'Eventviva\\ImageResize' => __DIR__ . '/..' . '/eventviva/php-image-resize/lib/ImageResize.php',
);

public static function getInitializer(ClassLoader $loader)
Expand Down
14 changes: 7 additions & 7 deletions source/plg_rsfp_imageresize/vendor/composer/installed.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
[
{
"name": "eventviva/php-image-resize",
"version": "1.5.5",
"version_normalized": "1.5.5.0",
"version": "1.6.2",
"version_normalized": "1.6.2.0",
"source": {
"type": "git",
"url": "https://github.com/eventviva/php-image-resize.git",
"reference": "87e7200ad2e24beb9ec9862f6f2c11d93dee8838"
"reference": "8c086aad961c082939ee9e42f83f536f37b73b00"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/eventviva/php-image-resize/zipball/87e7200ad2e24beb9ec9862f6f2c11d93dee8838",
"reference": "87e7200ad2e24beb9ec9862f6f2c11d93dee8838",
"url": "https://api.github.com/repos/eventviva/php-image-resize/zipball/8c086aad961c082939ee9e42f83f536f37b73b00",
"reference": "8c086aad961c082939ee9e42f83f536f37b73b00",
"shasum": ""
},
"require": {
"ext-exif": "*",
"ext-gd": "*",
"php": ">=5.3.0"
},
"time": "2016-08-17T17:41:24+00:00",
"time": "2017-01-19T10:34:05+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"classmap": [
"src"
"lib"
]
},
"notification-url": "https://packagist.org/downloads/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ php:
- 5.5
- 5.6
- 7.0
- 7.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 Aditya Patadia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
php-image-resize
================

PHP class to resize and scale images.
PHP library to resize, scale and crop images.

[![Build Status](https://travis-ci.org/eventviva/php-image-resize.svg?branch=master)](https://travis-ci.org/eventviva/php-image-resize)

Expand All @@ -15,7 +15,7 @@ If using [Composer](https://getcomposer.org/), in your `composer.json` file add:
```json
{
"require": {
"eventviva/php-image-resize": "1.5.*"
"eventviva/php-image-resize": "1.6.*"
}
}
```
Expand All @@ -41,10 +41,10 @@ use \Eventviva\ImageResize;
$image = new ImageResize();
```

Note: This library uses GD class which do not support resizing animated gif files
> Note: This library uses GD class which do not support resizing animated gif files
Usage
-----
Resize
------

To scale an image, in this case to half it's size (scaling is percentage based):

Expand All @@ -53,7 +53,7 @@ $image = new ImageResize('image.jpg');
$image->scale(50);
$image->save('image2.jpg')
```

To resize an image according to one dimension (keeping aspect ratio):

```php
Expand All @@ -73,6 +73,27 @@ $image->resizeToBestFit(500, 300);
$image->save('image2.jpg');
```

All resize functions have ```$allow_enlarge``` option which is set to false by default.
You can enable by passing ```true``` to any resize function:
```php
$image = new ImageResize('image.jpg');
$image->resize(500, 300, $allow_enlarge = True);
$image->save('image2.jpg');
```

If you are happy to handle aspect ratios yourself, you can resize directly:

```php
$image = new ImageResize('image.jpg');
$image->resize(800, 600);
$image->save('image2.jpg');
```

This will cause your image to skew if you do not use the same width/height ratio as the source image.

Crop
----

To to crop an image:

```php
Expand All @@ -85,16 +106,15 @@ This will scale the image to as close as it can to the passed dimensions, and th

In the case of the example above, an image of 400px &times; 600px will be resized down to 200px &times; 300px, and then 50px will be taken off the top and bottom, leaving you with 200px &times; 200px.

If you are happy to handle aspect ratios yourself, you can resize directly:
There is also a way to define custom crop position.
You can define $x and $y in ```freecrop``` method:

```php
$image = new ImageResize('image.jpg');
$image->resize(800, 600);
$image->freecrop(200, 200, $x = 20, $y = 20);
$image->save('image2.jpg');
```

This will cause your image to skew if you do not use the same width/height ratio as the source image.

Loading and saving images from string
-------------------------------------

Expand Down Expand Up @@ -183,12 +203,12 @@ We're passing `null` for the image type in the example above to skip over it and
Interlacing
-----------

By default, [image interlacing](http://php.net/manual/en/function.imageinterlace.php) is turned off. It can be enabled by setting `$interlace` to `1`:
By default, [image interlacing](http://php.net/manual/en/function.imageinterlace.php) is turned on. It can be disabled by setting `$interlace` to `0`:

```php
$image = new ImageResize('image.jpg');
$image->scale(50);
$image->interlace = 1;
$image->interlace = 0;
$image->save('image2.jpg')
```

Expand All @@ -212,3 +232,8 @@ $image
->save('image4.jpg')
;
```

API Doc
-------

https://eventviva.github.io/php-image-resize/class-Eventviva.ImageResize.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"ext-exif": "*"
},
"autoload": {
"classmap": ["src"]
"classmap": ["lib"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class ImageResize

public $quality_jpg = 75;
public $quality_png = 0;
public $quality_truecolor = TRUE;

public $interlace = 0;
public $interlace = 1;

public $source_type;

Expand Down Expand Up @@ -96,6 +97,10 @@ public function __construct($filename)
throw new \Exception('Unsupported image type');
break;
}

if (!$this->source_image) {
throw new \Exception('Could not load image');
}

return $this->resize($this->getSourceWidth(), $this->getSourceHeight());
}
Expand Down Expand Up @@ -139,29 +144,41 @@ public function save($filename, $image_type = null, $quality = null, $permission
{
$image_type = $image_type ?: $this->source_type;

$dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight());

imageinterlace($dest_image, $this->interlace);

switch ($image_type) {
case IMAGETYPE_GIF:
$dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight());

$background = imagecolorallocatealpha($dest_image, 255, 255, 255, 1);
imagecolortransparent($dest_image, $background);
imagefill($dest_image, 0, 0 , $background);
imagesavealpha($dest_image, true);
break;

case IMAGETYPE_JPEG:
$dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight());

$background = imagecolorallocate($dest_image, 255, 255, 255);
imagefilledrectangle($dest_image, 0, 0, $this->getDestWidth(), $this->getDestHeight(), $background);
break;

case IMAGETYPE_PNG:
if (!$this->quality_truecolor && !imageistruecolor($this->source_image)) {
$dest_image = imagecreate($this->getDestWidth(), $this->getDestHeight());

$background = imagecolorallocatealpha($dest_image, 255, 255, 255, 1);
imagecolortransparent($dest_image, $background);
imagefill($dest_image, 0, 0 , $background);
} else {
$dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight());
}

imagealphablending($dest_image, false);
imagesavealpha($dest_image, true);
break;
}

imageinterlace($dest_image, $this->interlace);

imagecopyresampled(
$dest_image,
$this->source_image,
Expand Down Expand Up @@ -200,6 +217,8 @@ public function save($filename, $image_type = null, $quality = null, $permission
if ($permissions) {
chmod($filename, $permissions);
}

imagedestroy($dest_image);

return $this;
}
Expand All @@ -215,7 +234,7 @@ public function getImageAsString($image_type = null, $quality = null)
{
$string_temp = tempnam(sys_get_temp_dir(), '');

$this->save($string_temp, $image_type, $quality);
$this->save($string_temp , $image_type, $quality);

$string = file_get_contents($string_temp);

Expand Down Expand Up @@ -312,7 +331,7 @@ public function resizeToBestFit($max_width, $max_height, $allow_enlarge = false)
* Resizes image according to given scale (proportionally)
*
* @param integer|float $scale
* @return \Eventviva\ImageResize
* @return \static
*/
public function scale($scale)
{
Expand Down Expand Up @@ -408,6 +427,40 @@ public function crop($width, $height, $allow_enlarge = false, $position = self::
return $this;
}

/**
* Crops image according to the given width, height, x and y
*
* @param integer $width
* @param integer $height
* @param integer $x
* @param integer $y
* @return \static
*/
public function freecrop($width, $height, $x = false, $y = false)
{
if($x === false or $y === false){
return $this->crop($width, $height);
}
$this->source_x = $x;
$this->source_y = $y;
if($width > $this->getSourceWidth() - $x){
$this->source_w = $this->getSourceWidth() - $x;
} else {
$this->source_w = $width;
}

if($height > $this->getSourceHeight() - $y){
$this->source_h = $this->getSourceHeight() - $y;
} else {
$this->source_h = $height;
}

$this->dest_w = $width;
$this->dest_h = $height;

return $this;
}

/**
* Gets source width
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

include __DIR__.'/../src/ImageResize.php';
include __DIR__.'/../lib/ImageResize.php';

use \Eventviva\ImageResize;

Expand Down Expand Up @@ -209,6 +209,17 @@ public function testCrop()
$this->assertEquals(50, $resize->getDestHeight());
}

public function testFreeCrop()
{
$image = $this->createImage(200, 100, 'png');
$resize = new ImageResize($image);

$resize->freecrop(50, 50 , $x = 20, $y = 20);

$this->assertEquals(50, $resize->getDestWidth());
$this->assertEquals(50, $resize->getDestHeight());
}

public function testCropPosition()
{
$image = $this->createImage(200, 100, 'png');
Expand Down

0 comments on commit 6544c13

Please sign in to comment.