@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | public function __toString() { |
10 | 10 | try { |
11 | - return (string)$this->call(); |
|
11 | + return (string) $this->call(); |
|
12 | 12 | } catch (Exception $e) { |
13 | 13 | return 'Caught exception: ' . $e->getMessage() . "\n"; |
14 | 14 | } |
@@ -21,12 +21,12 @@ discard block |
||
21 | 21 | * @param array $args |
22 | 22 | * @param bool $return_output_buffer |
23 | 23 | */ |
24 | - public function __construct( $function, $args = array(), $return_output_buffer = false ) { |
|
24 | + public function __construct($function, $args = array(), $return_output_buffer = false) { |
|
25 | 25 | $this->_function = $function; |
26 | 26 | $this->_args = $args; |
27 | 27 | $this->_use_ob = $return_output_buffer; |
28 | 28 | |
29 | - add_filter( 'get_twig', array( &$this, 'add_to_twig' ) ); |
|
29 | + add_filter('get_twig', array(&$this, 'add_to_twig')); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | * @param Twig_Environment $twig |
36 | 36 | * @return Twig_Environment |
37 | 37 | */ |
38 | - public function add_to_twig( $twig ) { |
|
38 | + public function add_to_twig($twig) { |
|
39 | 39 | $wrapper = $this; |
40 | 40 | |
41 | - $twig->addFunction( new Twig_SimpleFunction( $this->_function, function () use ( $wrapper ) { |
|
42 | - return call_user_func_array( array( $wrapper, 'call' ), func_get_args() ); |
|
43 | - } ) ); |
|
41 | + $twig->addFunction(new Twig_SimpleFunction($this->_function, function() use ($wrapper) { |
|
42 | + return call_user_func_array(array($wrapper, 'call'), func_get_args()); |
|
43 | + } )); |
|
44 | 44 | |
45 | 45 | return $twig; |
46 | 46 | } |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | * @return string |
52 | 52 | */ |
53 | 53 | public function call() { |
54 | - $args = $this->_parse_args( func_get_args(), $this->_args ); |
|
54 | + $args = $this->_parse_args(func_get_args(), $this->_args); |
|
55 | 55 | |
56 | 56 | if ( $this->_use_ob ) { |
57 | - return TimberHelper::ob_function( $this->_function, $args ); |
|
57 | + return TimberHelper::ob_function($this->_function, $args); |
|
58 | 58 | } else { |
59 | - return call_user_func_array( $this->_function, $args ); |
|
59 | + return call_user_func_array($this->_function, $args); |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 | |
@@ -67,12 +67,12 @@ discard block |
||
67 | 67 | * @param array $defaults |
68 | 68 | * @return array |
69 | 69 | */ |
70 | - private function _parse_args( $args, $defaults ) { |
|
71 | - $_arg = reset( $defaults ); |
|
70 | + private function _parse_args($args, $defaults) { |
|
71 | + $_arg = reset($defaults); |
|
72 | 72 | |
73 | - foreach ( $args as $index => $arg ) { |
|
74 | - $defaults[$index] = is_null( $arg ) ? $_arg : $arg; |
|
75 | - $_arg = next( $defaults ); |
|
73 | + foreach ($args as $index => $arg) { |
|
74 | + $defaults[$index] = is_null($arg) ? $_arg : $arg; |
|
75 | + $_arg = next($defaults); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | return $defaults; |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * (ex: my-awesome-pic-lbox-300x200-FF3366.jpg) |
31 | 31 | */ |
32 | 32 | public function filename($src_filename, $src_extension) { |
33 | - $color = str_replace( '#', '', $this->color ); |
|
33 | + $color = str_replace('#', '', $this->color); |
|
34 | 34 | $newbase = $src_filename . '-lbox-' . $this->w . 'x' . $this->h . '-' . $color; |
35 | 35 | $new_name = $newbase . '.' . $src_extension; |
36 | 36 | return $new_name; |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | $w = $this->w; |
51 | 51 | $h = $this->h; |
52 | 52 | |
53 | - $bg = imagecreatetruecolor( $w, $h ); |
|
54 | - $c = self::hexrgb( $this->color ); |
|
55 | - $bgColor = imagecolorallocate( $bg, $c['red'], $c['green'], $c['blue'] ); |
|
56 | - imagefill( $bg, 0, 0, $bgColor ); |
|
57 | - $image = wp_get_image_editor( $load_filename ); |
|
58 | - if ( !is_wp_error( $image ) ) { |
|
53 | + $bg = imagecreatetruecolor($w, $h); |
|
54 | + $c = self::hexrgb($this->color); |
|
55 | + $bgColor = imagecolorallocate($bg, $c['red'], $c['green'], $c['blue']); |
|
56 | + imagefill($bg, 0, 0, $bgColor); |
|
57 | + $image = wp_get_image_editor($load_filename); |
|
58 | + if ( !is_wp_error($image) ) { |
|
59 | 59 | $current_size = $image->get_size(); |
60 | 60 | $quality = $image->get_quality(); |
61 | 61 | $ow = $current_size['width']; |
@@ -69,39 +69,39 @@ discard block |
||
69 | 69 | $y = 0; |
70 | 70 | $x = $w / 2 - $owt / 2; |
71 | 71 | $oht = $h; |
72 | - $image->crop( 0, 0, $ow, $oh, $owt, $oht ); |
|
72 | + $image->crop(0, 0, $ow, $oh, $owt, $oht); |
|
73 | 73 | } else { |
74 | 74 | $w_scale = $w / $ow; |
75 | 75 | $oht = $oh * $w_scale; |
76 | 76 | $x = 0; |
77 | 77 | $y = $h / 2 - $oht / 2; |
78 | 78 | $owt = $w; |
79 | - $image->crop( 0, 0, $ow, $oh, $owt, $oht ); |
|
79 | + $image->crop(0, 0, $ow, $oh, $owt, $oht); |
|
80 | 80 | } |
81 | - $result = $image->save( $save_filename ); |
|
81 | + $result = $image->save($save_filename); |
|
82 | 82 | $func = 'imagecreatefromjpeg'; |
83 | 83 | $save_func = 'imagejpeg'; |
84 | - $ext = pathinfo( $save_filename, PATHINFO_EXTENSION ); |
|
84 | + $ext = pathinfo($save_filename, PATHINFO_EXTENSION); |
|
85 | 85 | if ( $ext == 'gif' ) { |
86 | 86 | $func = 'imagecreatefromgif'; |
87 | 87 | $save_func = 'imagegif'; |
88 | 88 | } else if ( $ext == 'png' ) { |
89 | 89 | $func = 'imagecreatefrompng'; |
90 | 90 | $save_func = 'imagepng'; |
91 | - if ($quality > 9) { |
|
92 | - $quality = $quality/10; |
|
91 | + if ( $quality > 9 ) { |
|
92 | + $quality = $quality / 10; |
|
93 | 93 | $quality = round(10 - $quality); |
94 | 94 | } |
95 | 95 | } |
96 | - $image = $func( $save_filename ); |
|
97 | - imagecopy( $bg, $image, $x, $y, 0, 0, $owt, $oht ); |
|
98 | - if ($save_func === 'imagegif') { |
|
99 | - $save_func( $bg, $save_filename ); |
|
96 | + $image = $func($save_filename); |
|
97 | + imagecopy($bg, $image, $x, $y, 0, 0, $owt, $oht); |
|
98 | + if ( $save_func === 'imagegif' ) { |
|
99 | + $save_func($bg, $save_filename); |
|
100 | 100 | } |
101 | - $save_func( $bg, $save_filename, $quality ); |
|
101 | + $save_func($bg, $save_filename, $quality); |
|
102 | 102 | return true; |
103 | 103 | } else { |
104 | - TimberHelper::error_log( $image ); |
|
104 | + TimberHelper::error_log($image); |
|
105 | 105 | } |
106 | 106 | return false; |
107 | 107 | } |