Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'release/v1.21'

  • Loading branch information...
commit befc971683ea2a15d6f152ce5fbe79f613a29d1f 2 parents 23d0ff9 + 2902b75
@maikeldaloo authored
Showing with 25 additions and 8 deletions.
  1. +4 −0 README.md
  2. +21 −8 resizer.php
View
4 README.md
@@ -55,6 +55,10 @@ Then you can start resizing your images by simply calling:
}
});
+## Config
+
+Options have been added to allow for choosing where to crop from. You can set the vertical and horizontal crop positions in the /config/defaults.php file. Better yet, copy that file into your /application/config/ directory and rename it to **resizer.php**, so that when updating the bundle, your configuration isn't reset.
+
## Credits
The image resize class was originally written in a tutorial by Jarrod Oberto on [NetTuts+](http://net.tutsplus.com/tutorials/php/image-resizing-made-easy-with-php/). I only modified it to use Laravel's File class, updated the coding style, added comments throughout the class file and turned it into a Laravel bundle.
View
29 resizer.php
@@ -10,7 +10,7 @@
* I only turned it into a Laravel bundle.
*
* @package Resizer
- * @version 1.2
+ * @version 1.21
* @author Maikel D (original author Jarrod Oberto)
* @link
* @example
@@ -54,11 +54,21 @@ class Resizer {
private $image_resized;
/**
+ * Loads config from the main application, falls back to the bundle config.
+ * @var array
+ */
+ private $config = array();
+
+ /**
* Instantiates the Resizer and receives the path to an image we're working with.
* @param mixed $file The file array provided by Laravel's Input::file('field_name') or a path to a file
*/
function __construct( $file )
{
+ // Load the config from the main application first, if it's not available
+ // load the one from the bundle's config directory.
+ $this->config = Config::get('resizer', Config::get('resizer::defaults'));
+
// Open up the file.
$this->image = $this->open_image( $file );
@@ -104,9 +114,9 @@ public function resize( $new_width , $new_height , $option = 'auto' )
// Retain transparency for PNG and GIF files.
$background_colour = imagecolorallocate(
$image_background,
- Config::get('resizer::defaults.background_color.r'),
- Config::get('resizer::defaults.background_color.g'),
- Config::get('resizer::defaults.background_color.b')
+ array_get( $this->config , 'background_color.r' ),
+ array_get( $this->config , 'background_color.g' ),
+ array_get( $this->config , 'background_color.b' )
);
imagefilledrectangle( $image_background , 0 , 0 , $this->width , $this->height , $background_colour );
@@ -442,8 +452,11 @@ private function crop( $optimal_width , $optimal_height , $new_width , $new_heig
private function get_crop_points( $optimal_width , $optimal_height , $new_width , $new_height ) {
$crop_points = array();
+ $vertical_start = array_get( $this->config , 'crop_vertical_start_point' );
+ $horizontal_start = array_get( $this->config , 'crop_horizontal_start_point' );
+
// Where is our vertical starting crop point?
- switch ( Config::get('resizer::defaults.crop_vertical_start_point') ) {
+ switch ( $vertical_start ) {
case 'top':
$crop_points['y'] = 0;
break;
@@ -455,12 +468,12 @@ private function get_crop_points( $optimal_width , $optimal_height , $new_width
break;
default:
- throw new Exception('Unknown value for crop_vertical_start_point: '. Config::get('resizer::defaults.crop_vertical_start_point') .'. Please check config file in the Resizer bundle.');
+ throw new Exception('Unknown value for crop_vertical_start_point: '. $vertical_start .'. Please check config file in the Resizer bundle.');
break;
}
// Where is our horizontal starting crop point?
- switch ( Config::get('resizer::defaults.crop_horizontal_start_point') ) {
+ switch ( $horizontal_start ) {
case 'left':
$crop_points['x'] = 0;
break;
@@ -472,7 +485,7 @@ private function get_crop_points( $optimal_width , $optimal_height , $new_width
break;
default:
- throw new Exception('Unknown value for crop_horizontal_start_point: '. Config::get('resizer::defaults.crop_horizontal_start_point') .'. Please check config file in the Resizer bundle.');
+ throw new Exception('Unknown value for crop_horizontal_start_point: '. $horizontal_start .'. Please check config file in the Resizer bundle.');
break;
}
Please sign in to comment.
Something went wrong with that request. Please try again.