Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
vendor
vendor
.idea
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,55 @@ Illuminage is a wrapper for the Imagine library to hook into the Laravel framewo

```php
// This will create a cropped 200x300 thumb, cache it, and display it in an image tag
echo Thumb::create('image.jpg', 200, 300)
echo Illuminage::thumb('image.jpg', 200, 300)

// Shortcuts
echo Thumb::square('image.jpg', 300)
// Shortcut
echo Illuminage::square('image.jpg', 300)

// This will resize image to specified dimensions, cache it, and display it in an image tag
echo Illuminage::resize('image.jpg', 200, 300)

// This will **proportionaly** resize image to fit the specified dimensions, cache it, and display it in an image tag
echo Illuminage::fit('image.jpg', 200, 300)
```

What you get from those calls are not direct HTML strings but objects implementing the [HtmlObject\Tag](https://github.com/Anahkiasen/html-object) abstract, so you can use all sorts of HTML manipulation methods on them :

```php
$thumb = Thumb::square('image.jpg', 200)->addClass('image-wide');
$thumb = Illuminage::square('image.jpg', 200)->addClass('image-wide');
$thumb = $thumb->wrapWith('figure')->id('avatar');

echo $thumb;
// <figure id="avatar"><img class="image-wide" src="pathToThumbnail.jpg"></figure>
```

You can at all time access the original Imagine instance used to render the images :
To get the URL of generated image:
```php
echo $thumb->getPath();
```

You can at all time access the Image instance used to render the images and use the Imagine methods:
```php
$thumb = new Thumb('foo.jpg', 200, 200);
$thumb = Illuminage::image('foo.jpg');

echo $thumb->grayscale()->onImage(function($image) {
$image->flipVertically()->rotate(45);
});
```
```

## Installation

* Add **"anahkiasen/illuminage":"dev-master"** in "require" section of composer.json
* To use *this* version of Illuminage (with fit support), add:
```
"repositories":[
{
"type":"git",
"url":"https://github.com/terion-name/illuminage"
}
],
```
* Run command **composer update**
* Add **'Illuminage\IlluminageServiceProvider'** in providers list in config/app.php
* Add **'Illuminage' => 'Illuminage\Facades\Illuminage'** in aliases list in config/app.php
* Run commands **php artisan asset:publish && php artisan config:publish anahkiasen/illuminage**
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
],
"require": {
"php": ">=5.3.0",
"anahkiasen/html-object": "dev-master",
"anahkiasen/html-object": "1.1.2",
"illuminate/cache": "~4",
"illuminate/container": "~4",
"illuminate/config": "~4",
"illuminate/routing": "~4",
"illuminate/support": "~4",
"imagine/Imagine": "dev-develop"
"imagine/Imagine": "0.5.0"
},
"require-dev": {
"mockery/mockery": "dev-master"
Expand Down
16 changes: 16 additions & 0 deletions src/Illuminage/Illuminage.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ public function square($image, $size)
return $this->thumb($image, $size, $size);
}

/**
* Create a proportional resize that fits provided dimensions
*
* @param string $image
* @param integer $size
*
* @return Image
*/
public function fit($image, $width, $height, $upscale = false)
{
$image = new Image($this, $image);
$image->proportional($width, $height, $upscale);

return $image;
}

////////////////////////////////////////////////////////////////////
/////////////////////////// IMAGE PROCESSING ///////////////////////
////////////////////////////////////////////////////////////////////
Expand Down
78 changes: 52 additions & 26 deletions src/Illuminage/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,32 @@ public function thumbnail($width, $height)
return $this;
}

/**
* Resize an Image, proportional style
*
* @param integer $width
* @param integer $height
*/
public function proportional($width, $height, $upscale = false)
{
$ratios = array(
$width / $this->getOriginalSize()->getWidth(),
$height / $this->getOriginalSize()->getHeight()
);
$ratio = min($ratios);

if ( $ratio > 1 && !$upscale ) {
return $this;
}

$resize = $this->getOriginalSize()->scale($ratio);
$salts['resize'] = array($resize);

$this->salts['resize'] = array($resize);

return $this;
}

/**
* Inverts the colors
*/
Expand Down Expand Up @@ -314,32 +340,32 @@ public function quality($quality)
*/
protected function processThumbnail(array $salts)
{
if (isset($salts['_thumbnail'])) {
$box = $salts['_thumbnail'];
unset($salts['_thumbnail']);

// Compute thumbnail ratio
$ratios = array(
$box->getWidth() / $this->getOriginalSize()->getWidth(),
$box->getHeight() / $this->getOriginalSize()->getHeight()
);
if ($this->getOriginalSize()->getWidth() < $box->getWidth()) $ratio = $ratios[0];
elseif ($this->getOriginalSize()->getHeight() < $box->getHeight()) $ratio = $ratios[1];
else $ratio = max($ratios);

// Resize this to fit bounds
$resize = $this->getOriginalSize()->scale($ratio);
$salts['resize'] = array($resize);

// Crop image
$salts['crop'] = array(
new Point(
max(0, round(($resize->getWidth() - $box->getWidth()) / 2)),
max(0, round(($resize->getHeight() - $box->getHeight()) / 2))
),
$box
);
}
if (isset($salts['_thumbnail'])) {
$box = $salts['_thumbnail'];
unset($salts['_thumbnail']);

// Compute thumbnail ratio
$ratios = array(
$box->getWidth() / $this->getOriginalSize()->getWidth(),
$box->getHeight() / $this->getOriginalSize()->getHeight()
);
if ($this->getOriginalSize()->getWidth() < $box->getWidth()) $ratio = $ratios[0];
elseif ($this->getOriginalSize()->getHeight() < $box->getHeight()) $ratio = $ratios[1];
else $ratio = max($ratios);

// Resize this to fit bounds
$resize = $this->getOriginalSize()->scale($ratio);
$salts['resize'] = array($resize);

// Crop image
$salts['crop'] = array(
new Point(
max(0, round(($resize->getWidth() - $box->getWidth()) / 2)),
max(0, round(($resize->getHeight() - $box->getHeight()) / 2))
),
$box
);
}

return $salts;
}
Expand Down