Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Zebra_Image often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Zebra_Image, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
45 | class Zebra_Image |
||
46 | { |
||
47 | |||
48 | /** |
||
49 | * Indicates the file system permissions to be set for newly created images. |
||
50 | * |
||
51 | * Better is to leave this setting as it is. |
||
52 | * |
||
53 | * If you know what you are doing, here is how you can calculate the permission levels: |
||
54 | * |
||
55 | * - 400 Owner Read |
||
56 | * - 200 Owner Write |
||
57 | * - 100 Owner Execute |
||
58 | * - 40 Group Read |
||
59 | * - 20 Group Write |
||
60 | * - 10 Group Execute |
||
61 | * - 4 Global Read |
||
62 | * - 2 Global Write |
||
63 | * - 1 Global Execute |
||
64 | * |
||
65 | * Default is 0755 |
||
66 | * |
||
67 | * @var integer |
||
68 | */ |
||
69 | public $chmod_value; |
||
70 | |||
71 | /** |
||
72 | * If set to FALSE, images having both width and height smaller than the required width and height, will be left |
||
73 | * untouched ({@link jpeg_quality} and {@link png_compression} will still apply). |
||
74 | * |
||
75 | * Available only for the {@link resize()} method |
||
76 | * |
||
77 | * Default is TRUE |
||
78 | * |
||
79 | * @var boolean |
||
80 | */ |
||
81 | public $enlarge_smaller_images; |
||
82 | |||
83 | /** |
||
84 | * In case of an error read this property's value to see the error's code. |
||
85 | * |
||
86 | * Possible error codes are: |
||
87 | * |
||
88 | * - 1: source file could not be found |
||
89 | * - 2: source file is not readable |
||
90 | * - 3: could not write target file |
||
91 | * - 4: unsupported source file format |
||
92 | * - 5: unsupported target file format |
||
93 | * - 6: GD library version does not support target file format |
||
94 | * - 7: GD library is not installed! |
||
95 | * - 8: "chmod" command is disabled via configuration |
||
96 | * |
||
97 | * Default is 0 (no error). |
||
98 | * |
||
99 | * @var integer |
||
100 | */ |
||
101 | public $error; |
||
102 | |||
103 | /** |
||
104 | * Indicates the quality of the output image (better quality means bigger file size). |
||
105 | * |
||
106 | * Used only if the file at {@link target_path} is a JPG/JPEG image. |
||
107 | * |
||
108 | * Range is 0 - 100 |
||
109 | * |
||
110 | * Default is 85 |
||
111 | * |
||
112 | * @var integer |
||
113 | */ |
||
114 | public $jpeg_quality; |
||
115 | |||
116 | /** |
||
117 | * Indicates the compression level of the output image (lower compression means bigger file size). |
||
118 | * |
||
119 | * Available only if PHP version is 5.1.2+, and only if the file at {@link target_path} is a PNG image. It will be |
||
120 | * ignored otherwise. |
||
121 | * |
||
122 | * Range is 0 - 9 |
||
123 | * |
||
124 | * Default is 9 |
||
125 | * |
||
126 | * @since 2.2 |
||
127 | * |
||
128 | * @var integer |
||
129 | */ |
||
130 | public $png_compression; |
||
131 | |||
132 | /** |
||
133 | * Specifies whether, upon resizing, images should preserve their aspect ratio. |
||
134 | * |
||
135 | * Available only for the {@link resize()} method |
||
136 | * |
||
137 | * Default is TRUE |
||
138 | * |
||
139 | * @var boolean |
||
140 | */ |
||
141 | public $preserve_aspect_ratio; |
||
142 | |||
143 | /** |
||
144 | * Indicates whether a target files should preserve the source file's date/time. |
||
145 | * |
||
146 | * Default is TRUE |
||
147 | * |
||
148 | * @since 1.0.4 |
||
149 | * |
||
150 | * @var boolean |
||
151 | */ |
||
152 | public $preserve_time; |
||
153 | |||
154 | /** |
||
155 | * Indicates whether the target image should have a "sharpen" filter applied to it. |
||
156 | * |
||
157 | * Can be very useful when creating thumbnails and should be used only when creating thumbnails. |
||
158 | * |
||
159 | * <i>The sharpen filter relies on the "imageconvolution" PHP function which is available only for PHP version |
||
160 | * 5.1.0+, and will leave the images unaltered for older versions!</i> |
||
161 | * |
||
162 | * Default is FALSE |
||
163 | * |
||
164 | * @since 2.2 |
||
165 | * |
||
166 | * @var boolean |
||
167 | */ |
||
168 | public $sharpen_images; |
||
169 | |||
170 | /** |
||
171 | * Path to an image file to apply the transformations to. |
||
172 | * |
||
173 | * Supported file types are <b>GIF</b>, <b>PNG</b> and <b>JPEG</b>. |
||
174 | * |
||
175 | * @var string |
||
176 | */ |
||
177 | public $source_path; |
||
178 | |||
179 | /** |
||
180 | * Path (including file name) to where to save the transformed image. |
||
181 | * |
||
182 | * <i>Can be a different than {@link source_path} - the type of the transformed image will be as indicated by the |
||
183 | * file's extension (supported file types are GIF, PNG and JPEG)</i>. |
||
184 | * |
||
185 | * @var string |
||
186 | */ |
||
187 | public $target_path; |
||
188 | |||
189 | /** |
||
190 | * Constructor of the class. |
||
191 | * |
||
192 | * Initializes the class and the default properties |
||
193 | * |
||
194 | * @return void |
||
195 | */ |
||
196 | public function __construct() |
||
214 | |||
215 | /** |
||
216 | * Applies one or more filters to the image given as {@link source_path} and outputs it as the file specified as |
||
217 | * {@link target_path}. |
||
218 | * |
||
219 | * <samp>This method is available only if the {@link http://php.net/manual/en/function.imagefilter.php imagefilter} |
||
220 | * function is available (available from PHP 5+), and will leave images unaltered otherwise.</samp> |
||
221 | * |
||
222 | * <code> |
||
223 | * // include the Zebra_Image library |
||
224 | * require 'path/to/Zebra_Image.php'; |
||
225 | * |
||
226 | * // instantiate the class |
||
227 | * $img = new Zebra_Image(); |
||
228 | * |
||
229 | * // a source image |
||
230 | * $img->source_path = 'path/to/source.ext'; |
||
231 | * |
||
232 | * // path to where should the resulting image be saved |
||
233 | * // note that by simply setting a different extension to the file will |
||
234 | * // instruct the script to create an image of that particular type |
||
235 | * $img->target_path = 'path/to/target.ext'; |
||
236 | * |
||
237 | * // apply the "grayscale" filter |
||
238 | * $img->apply_filter('grayscale'); |
||
239 | * |
||
240 | * // apply the "contrast" filter |
||
241 | * $img->apply_filter('contrast', -20); |
||
242 | * </code> |
||
243 | * |
||
244 | * You can also apply multiple filters at once. In this case, the method requires a single argument, an array of |
||
245 | * arrays, containing the filters and associated arguments, where applicable: |
||
246 | * |
||
247 | * <code> |
||
248 | * // create a sepia effect |
||
249 | * // note how we're applying multiple filters at once |
||
250 | * // each filter is in its own array |
||
251 | * $img->apply_filter(array( |
||
252 | * |
||
253 | * // first we apply the "grayscale" filter |
||
254 | * array('grayscale'), |
||
255 | * |
||
256 | * // then we apply the "colorize" filter with 90, 60, 40 as |
||
257 | * // the values for red, green and blue |
||
258 | * array('colorize', 90, 60, 40), |
||
259 | * |
||
260 | * )); |
||
261 | * </code> |
||
262 | * |
||
263 | * @param string $filter The (case-insensitive) name of the filter to apply. Can be one of the following: |
||
264 | * |
||
265 | * - <b>brightness</b> - changes the brightness of the image; use <b>arg1</b> |
||
266 | * to set the level of brightness; the range of brightness |
||
267 | * is -255 to 255; |
||
268 | * - <b>colorize</b> - adds (subtracts) specified RGB values to each pixel; |
||
269 | * use <b>arg1</b>, <b>arg2</b> and <b>arg3</b> in the |
||
270 | * form of red, green, blue and <b>arg4</b> for the alpha |
||
271 | * channel. the range for each color is -255 to 255 and |
||
272 | * 0 to 127 for alpha; <i>alpha support is available only |
||
273 | * for PHP 5.2.5+</i>; |
||
274 | * - <b>contrast</b> - changes the contrast of the image; use <b>arg1</b> |
||
275 | * to set the level of contrast; the range of contrast |
||
276 | * is -100 to 100; |
||
277 | * - <b>gausian_blur</b> - blurs the image using the Gaussian method; |
||
278 | * - <b>grayscale</b> - converts the image into grayscale; |
||
279 | * - <b>edgedetect</b> - uses edge detection to highlight the edges in the image; |
||
280 | * - <b>emboss</b> - embosses the image; |
||
281 | * - <b>mean_removal</b> - uses mean removal to achieve a "sketchy" effect; |
||
282 | * - <b>negate</b> - reverses all the colors of the image; |
||
283 | * - <b>pixelate</b> - applies pixelation effect to the image, use <b>arg1</b> |
||
284 | * to set the block size and <b>arg2</b> to set the |
||
285 | * pixelation effect mode; <i>this filter is available |
||
286 | * only for PHP 5.3.0+</i>; |
||
287 | * - <b>selective_blur</b> - blurs the image; |
||
288 | * - <b>smooth</b> - makes the image smoother. Use <b>arg1</b> to set the |
||
289 | * level of smoothness. applies a 9-cell convolution matrix |
||
290 | * where center pixel has the weight of <b>arg1</b> and |
||
291 | * others weight of 1.0. the result is normalized by dividing |
||
292 | * the sum with <b>arg1</b> + 8.0 (sum of the matrix). |
||
293 | * any float is accepted; |
||
294 | * |
||
295 | * @param mixed $arg1 Used by the following filters: |
||
296 | * - <b>brightness</b> - sets the brightness level (-255 to 255) |
||
297 | * - <b>contrast</b> - sets the contrast level (-100 to 100) |
||
298 | * - <b>colorize</b> - sets the value of the red component (-255 to 255) |
||
299 | * - <b>smooth</b> - sets the smoothness level |
||
300 | * - <b>pixelate</b> - sets the block size, in pixels |
||
301 | * |
||
302 | * @param mixed $arg2 Used by the following filters: |
||
303 | * - <b>colorize</b> - sets the value of the green component (-255 to 255) |
||
304 | * - <b>pixelate</b> - whether to use advanced pixelation effect or not (defaults to FALSE). |
||
305 | * |
||
306 | * @param mixed $arg3 Used by the following filters: |
||
307 | * - <b>colorize</b> - sets the value of the blue component (-255 to 255) |
||
308 | * |
||
309 | * @param mixed $arg4 Used by the following filters: |
||
310 | * - <b>colorize</b> - alpha channel; a value between 0 and 127. 0 indicates |
||
311 | * completely opaque while 127 indicates completely |
||
312 | * transparent. |
||
313 | * |
||
314 | * @since 2.2.2 |
||
315 | * |
||
316 | * @return boolean Returns TRUE on success or FALSE on error. |
||
317 | * |
||
318 | * If {@link http://php.net/manual/en/function.imagefilter.php imagefilter} is not |
||
319 | * available the method will return FALSE without setting an {@link error} code. |
||
320 | * |
||
321 | * If the requested filter doesn't exist, or invalid arguments are passed, the method |
||
322 | * will trigger a warning. |
||
323 | * |
||
324 | * If FALSE is returned and you are sure that |
||
325 | * {@link http://php.net/manual/en/function.imagefilter.php imagefilter} exists and that |
||
326 | * the requested filter is valid, check the {@link error} property to see the error code. |
||
327 | */ |
||
328 | public function apply_filter($filter, $arg1 = '', $arg2 = '', $arg3 = '', $arg4 = '') |
||
393 | |||
394 | /** |
||
395 | * Crops a portion of the image given as {@link source_path} and outputs it as the file specified as {@link target_path}. |
||
396 | * |
||
397 | * <code> |
||
398 | * // include the Zebra_Image library |
||
399 | * require 'path/to/Zebra_Image.php'; |
||
400 | * |
||
401 | * // instantiate the class |
||
402 | * $img = new Zebra_Image(); |
||
403 | * |
||
404 | * // a source image |
||
405 | * $img->source_path = 'path/to/source.ext'; |
||
406 | * |
||
407 | * // path to where should the resulting image be saved |
||
408 | * // note that by simply setting a different extension to the file will |
||
409 | * // instruct the script to create an image of that particular type |
||
410 | * $img->target_path = 'path/to/target.ext'; |
||
411 | * |
||
412 | * // crop a rectangle of 100x100 pixels, starting from the top-left corner |
||
413 | * $img->crop(0, 0, 100, 100); |
||
414 | * </code> |
||
415 | * |
||
416 | * @param integer $start_x x coordinate to start cropping from |
||
417 | * |
||
418 | * @param integer $start_y y coordinate to start cropping from |
||
419 | * |
||
420 | * @param integer $end_x x coordinate where to end the cropping |
||
421 | * |
||
422 | * @param integer $end_y y coordinate where to end the cropping |
||
423 | * |
||
424 | * @since 1.0.4 |
||
425 | * |
||
426 | * @return boolean Returns TRUE on success or FALSE on error. |
||
427 | * |
||
428 | * If FALSE is returned, check the {@link error} property to see the error code. |
||
429 | */ |
||
430 | public function crop($start_x, $start_y, $end_x, $end_y) |
||
474 | |||
475 | /** |
||
476 | * Flips both horizontally and vertically the image given as {@link source_path} and outputs the resulted image as |
||
477 | * {@link target_path} |
||
478 | * |
||
479 | * <code> |
||
480 | * // include the Zebra_Image library |
||
481 | * require 'path/to/Zebra_Image.php'; |
||
482 | * |
||
483 | * // instantiate the class |
||
484 | * $img = new Zebra_Image(); |
||
485 | * |
||
486 | * // a source image |
||
487 | * $img->source_path = 'path/to/source.ext'; |
||
488 | * |
||
489 | * // path to where should the resulting image be saved |
||
490 | * // note that by simply setting a different extension to the file will |
||
491 | * // instruct the script to create an image of that particular type |
||
492 | * $img->target_path = 'path/to/target.ext'; |
||
493 | * |
||
494 | * // flip the image both horizontally and vertically |
||
495 | * $img->flip_both(); |
||
496 | * </code> |
||
497 | * |
||
498 | * @since 2.1 |
||
499 | * |
||
500 | * @return boolean Returns TRUE on success or FALSE on error. |
||
501 | * |
||
502 | * If FALSE is returned, check the {@link error} property to see the error code. |
||
503 | */ |
||
504 | public function flip_both() |
||
508 | |||
509 | /** |
||
510 | * Flips horizontally the image given as {@link source_path} and outputs the resulted image as {@link target_path} |
||
511 | * |
||
512 | * <code> |
||
513 | * // include the Zebra_Image library |
||
514 | * require 'path/to/Zebra_Image.php'; |
||
515 | * |
||
516 | * // instantiate the class |
||
517 | * $img = new Zebra_Image(); |
||
518 | * |
||
519 | * // a source image |
||
520 | * $img->source_path = 'path/to/source.ext'; |
||
521 | * |
||
522 | * // path to where should the resulting image be saved |
||
523 | * // note that by simply setting a different extension to the file will |
||
524 | * // instruct the script to create an image of that particular type |
||
525 | * $img->target_path = 'path/to/target.ext'; |
||
526 | * |
||
527 | * // flip the image horizontally |
||
528 | * $img->flip_horizontal(); |
||
529 | * </code> |
||
530 | * |
||
531 | * @return boolean Returns TRUE on success or FALSE on error. |
||
532 | * |
||
533 | * If FALSE is returned, check the {@link error} property to see the error code. |
||
534 | */ |
||
535 | public function flip_horizontal() |
||
539 | |||
540 | /** |
||
541 | * Flips vertically the image given as {@link source_path} and outputs the resulted image as {@link target_path} |
||
542 | * |
||
543 | * <code> |
||
544 | * // include the Zebra_Image library |
||
545 | * require 'path/to/Zebra_Image.php'; |
||
546 | * |
||
547 | * // instantiate the class |
||
548 | * $img = new Zebra_Image(); |
||
549 | * |
||
550 | * // a source image |
||
551 | * $img->source_path = 'path/to/source.ext'; |
||
552 | * |
||
553 | * // path to where should the resulting image be saved |
||
554 | * // note that by simply setting a different extension to the file will |
||
555 | * // instruct the script to create an image of that particular type |
||
556 | * $img->target_path = 'path/to/target.ext'; |
||
557 | * |
||
558 | * // flip the image vertically |
||
559 | * $img->flip_vertical(); |
||
560 | * </code> |
||
561 | * |
||
562 | * @return boolean Returns TRUE on success or FALSE on error. |
||
563 | * |
||
564 | * If FALSE is returned, check the {@link error} property to see the error code. |
||
565 | */ |
||
566 | public function flip_vertical() |
||
570 | |||
571 | /** |
||
572 | * Resizes the image given as {@link source_path} and outputs the resulted image as {@link target_path}. |
||
573 | * |
||
574 | * <code> |
||
575 | * // include the Zebra_Image library |
||
576 | * require 'path/to/Zebra_Image.php'; |
||
577 | * |
||
578 | * // instantiate the class |
||
579 | * $img = new Zebra_Image(); |
||
580 | * |
||
581 | * // a source image |
||
582 | * $img->source_path = 'path/to/source.ext'; |
||
583 | * |
||
584 | * // path to where should the resulting image be saved |
||
585 | * // note that by simply setting a different extension to the file will |
||
586 | * // instruct the script to create an image of that particular type |
||
587 | * $img->target_path = 'path/to/target.ext'; |
||
588 | * |
||
589 | * // apply a "sharpen" filter to the resulting images |
||
590 | * $img->sharpen_images = true; |
||
591 | * |
||
592 | * // resize the image to exactly 150x150 pixels, without altering aspect ratio, by using the CROP_CENTER method |
||
593 | * $img->resize(150, 150, ZEBRA_IMAGE_CROP_CENTER); |
||
594 | * </code> |
||
595 | * |
||
596 | * @param integer $width The width to resize the image to. |
||
597 | * |
||
598 | * If set to <b>0</b>, the width will be automatically adjusted, depending |
||
599 | * on the value of the <b>height</b> argument so that the image preserves |
||
600 | * its aspect ratio. |
||
601 | * |
||
602 | * If {@link preserve_aspect_ratio} is set to TRUE and both this and the |
||
603 | * <b>height</b> arguments are values greater than <b>0</b>, the image will |
||
604 | * be resized to the exact required width and height and the aspect ratio |
||
605 | * will be preserved - (also see the description for the <b>method</b> |
||
606 | * argument below on how can this be done). |
||
607 | * |
||
608 | * If {@link preserve_aspect_ratio} is set to FALSE, the image will be |
||
609 | * resized to the required width and the aspect ratio will be ignored. |
||
610 | * |
||
611 | * If both <b>width</b> and <b>height</b> are set to <b>0</b>, a copy of |
||
612 | * the source image will be created ({@link jpeg_quality} and |
||
613 | * {@link png_compression} will still apply). |
||
614 | * |
||
615 | * If either <b>width</b> or <b>height</b> are set to <b>0</b>, the script |
||
616 | * will consider the value of the {@link preserve_aspect_ratio} to bet set |
||
617 | * to TRUE regardless of its actual value! |
||
618 | * |
||
619 | * @param integer $height The height to resize the image to. |
||
620 | * |
||
621 | * If set to <b>0</b>, the height will be automatically adjusted, depending |
||
622 | * on the value of the <b>width</b> argument so that the image preserves |
||
623 | * its aspect ratio. |
||
624 | * |
||
625 | * If {@link preserve_aspect_ratio} is set to TRUE and both this and the |
||
626 | * <b>width</b> arguments are values greater than <b>0</b>, the image will |
||
627 | * be resized to the exact required width and height and the aspect ratio |
||
628 | * will be preserved - (also see the description for the <b>method</b> |
||
629 | * argument below on how can this be done). |
||
630 | * |
||
631 | * If {@link preserve_aspect_ratio} is set to FALSE, the image will be |
||
632 | * resized to the required height and the aspect ratio will be ignored. |
||
633 | * |
||
634 | * If both <b>width</b> and <b>height</b> are set to <b>0</b>, a copy of |
||
635 | * the source image will be created ({@link jpeg_quality} and |
||
636 | * {@link png_compression} will still apply). |
||
637 | * |
||
638 | * If either <b>height</b> or <b>width</b> are set to <b>0</b>, the script |
||
639 | * will consider the value of the {@link preserve_aspect_ratio} to bet set |
||
640 | * to TRUE regardless of its actual value! |
||
641 | * |
||
642 | * @param int $method (Optional) Method to use when resizing images to exact width and height |
||
643 | * while preserving aspect ratio. |
||
644 | * |
||
645 | * If the {@link preserve_aspect_ratio} property is set to TRUE and both the |
||
646 | * <b>width</b> and <b>height</b> arguments are values greater than <b>0</b>, |
||
647 | * the image will be resized to the exact given width and height and the |
||
648 | * aspect ratio will be preserved by using on of the following methods: |
||
649 | * |
||
650 | * - <b>ZEBRA_IMAGE_BOXED</b> - the image will be scalled so that it will |
||
651 | * fit in a box with the given width and height (both width/height will |
||
652 | * be smaller or equal to the required width/height) and then it will |
||
653 | * be centered both horizontally and vertically. The blank area will be |
||
654 | * filled with the color specified by the <b>bgcolor</b> argument. (the |
||
655 | * blank area will be filled only if the image is not transparent!) |
||
656 | * |
||
657 | * - <b>ZEBRA_IMAGE_NOT_BOXED</b> - the image will be scalled so that it |
||
658 | * <i>could</i> fit in a box with the given width and height but will |
||
659 | * not be enclosed in a box with given width and height. The new width/ |
||
660 | * height will be both smaller or equal to the required width/height |
||
661 | * |
||
662 | * - <b>ZEBRA_IMAGE_CROP_TOPLEFT</b> |
||
663 | * - <b>ZEBRA_IMAGE_CROP_TOPCENTER</b> |
||
664 | * - <b>ZEBRA_IMAGE_CROP_TOPRIGHT</b> |
||
665 | * - <b>ZEBRA_IMAGE_CROP_MIDDLELEFT</b> |
||
666 | * - <b>ZEBRA_IMAGE_CROP_CENTER</b> |
||
667 | * - <b>ZEBRA_IMAGE_CROP_MIDDLERIGHT</b> |
||
668 | * - <b>ZEBRA_IMAGE_CROP_BOTTOMLEFT</b> |
||
669 | * - <b>ZEBRA_IMAGE_CROP_BOTTOMCENTER</b> |
||
670 | * - <b>ZEBRA_IMAGE_CROP_BOTTOMRIGHT</b> |
||
671 | * |
||
672 | * For the methods involving crop, first the image is scaled so that both |
||
673 | * its sides are equal or greater than the respective sizes of the bounding |
||
674 | * box; next, a region of required width and height will be cropped from |
||
675 | * indicated region of the resulted image. |
||
676 | * |
||
677 | * Default is ZEBRA_IMAGE_CROP_CENTER |
||
678 | * |
||
679 | * @param \hexadecimal|string $background_color (Optional) The hexadecimal color (like "#FFFFFF" or "#FFF") of the |
||
680 | * blank area. See the <b>method</b> argument. |
||
681 | * |
||
682 | * When set to -1 the script will preserve transparency for transparent GIF |
||
683 | * and PNG images. For non-transparent images the background will be white |
||
684 | * in this case. |
||
685 | * |
||
686 | * Default is #FFFFFF. |
||
687 | * |
||
688 | * @return boolean Returns TRUE on success or FALSE on error. |
||
689 | * |
||
690 | * If FALSE is returned, check the {@link error} property to see what went |
||
691 | * wrong |
||
692 | */ |
||
693 | public function resize($width = 0, $height = 0, $method = ZEBRA_IMAGE_CROP_CENTER, $background_color = '#FFFFFF') |
||
966 | |||
967 | /** |
||
968 | * Rotates the image given as {@link source_path} and outputs the resulted image as {@link target_path}. |
||
969 | * |
||
970 | * <code> |
||
971 | * // include the Zebra_Image library |
||
972 | * require 'path/to/Zebra_Image.php'; |
||
973 | * |
||
974 | * // instantiate the class |
||
975 | * $img = new Zebra_Image(); |
||
976 | * |
||
977 | * // a source image |
||
978 | * $img->source_path = 'path/to/source.ext'; |
||
979 | * |
||
980 | * // path to where should the resulting image be saved |
||
981 | * // note that by simply setting a different extension to the file will |
||
982 | * // instruct the script to create an image of that particular type |
||
983 | * $img->target_path = 'path/to/target.ext'; |
||
984 | * |
||
985 | * // rotate the image 45 degrees, clockwise |
||
986 | * $img->rotate(45); |
||
987 | * </code> |
||
988 | * |
||
989 | * @param double $angle Angle by which to rotate the image clockwise. |
||
990 | * |
||
991 | * Between 0 and 360. |
||
992 | * |
||
993 | * @param mixed $background_color (Optional) The hexadecimal color (like "#FFFFFF" or "#FFF") of the |
||
994 | * uncovered zone after the rotation. |
||
995 | * |
||
996 | * When set to -1 the script will preserve transparency for transparent GIF |
||
997 | * and PNG images. For non-transparent images the background will be white |
||
998 | * in this case. |
||
999 | * |
||
1000 | * Default is -1. |
||
1001 | * |
||
1002 | * @return boolean Returns TRUE on success or FALSE on error. |
||
1003 | * |
||
1004 | * If FALSE is returned, check the {@link error} property to see the error |
||
1005 | * code. |
||
1006 | */ |
||
1007 | public function rotate($angle, $background_color = -1) |
||
1085 | |||
1086 | /** |
||
1087 | * Returns an array containing the image identifier representing the image obtained from {@link $source_path}, the |
||
1088 | * image's width and height and the image's type |
||
1089 | * |
||
1090 | * @access private |
||
1091 | */ |
||
1092 | public function _create_from_source() |
||
1207 | |||
1208 | /** |
||
1209 | * Converts a hexadecimal representation of a color (i.e. #123456 or #AAA) to a RGB representation. |
||
1210 | * |
||
1211 | * The RGB values will be a value between 0 and 255 each. |
||
1212 | * |
||
1213 | * @param string $color Hexadecimal representation of a color (i.e. #123456 or #AAA). |
||
1214 | * |
||
1215 | * @param string $default_on_error Hexadecimal representation of a color to be used in case $color is not |
||
1216 | * recognized as a hexadecimal color. |
||
1217 | * |
||
1218 | * @return array Returns an associative array with the values of (R)ed, (G)reen and (B)lue |
||
1219 | * |
||
1220 | * @access private |
||
1221 | */ |
||
1222 | public function _hex2rgb($color, $default_on_error = '#FFFFFF') |
||
1260 | |||
1261 | /** |
||
1262 | * Flips horizontally or vertically or both ways the image given as {@link source_path}. |
||
1263 | * |
||
1264 | * @since 2.1 |
||
1265 | * |
||
1266 | * @access private |
||
1267 | * |
||
1268 | * @param $orientation |
||
1269 | * |
||
1270 | * @return boolean Returns TRUE on success or FALSE on error. |
||
1271 | * |
||
1272 | * If FALSE is returned, check the {@link error} property to see the error code. |
||
1273 | */ |
||
1274 | public function _flip($orientation) |
||
1327 | |||
1328 | /** |
||
1329 | * Creates a blank image of given width, height and background color. |
||
1330 | * |
||
1331 | * @param integer $width Width of the new image. |
||
1332 | * |
||
1333 | * @param integer $height Height of the new image. |
||
1334 | * |
||
1335 | * @param string $background_color (Optional) The hexadecimal color of the background. |
||
1336 | * |
||
1337 | * Can also be -1 case in which the script will try to create a transparent |
||
1338 | * image, if possible. |
||
1339 | * |
||
1340 | * Default is "#FFFFFF". |
||
1341 | * |
||
1342 | * @return Returns the identifier of the newly created image. |
||
1343 | * |
||
1344 | * @access private |
||
1345 | */ |
||
1346 | public function _prepare_image($width, $height, $background_color = '#FFFFFF') |
||
1400 | |||
1401 | /** |
||
1402 | * Sharpens images. Useful when creating thumbnails. |
||
1403 | * |
||
1404 | * Code taken from the comments at {@link http://docs.php.net/imageconvolution}. |
||
1405 | * |
||
1406 | * <i>This function will yield a result only for PHP version 5.1.0+ and will leave the image unaltered for older |
||
1407 | * versions!</i> |
||
1408 | * |
||
1409 | * @param $image |
||
1410 | * |
||
1411 | * @return |
||
1412 | * @internal param \identifier $identifier An image identifier |
||
1413 | * |
||
1414 | * @access private |
||
1415 | */ |
||
1416 | public function _sharpen_image($image) |
||
1443 | |||
1444 | /** |
||
1445 | * Creates a new image from given image identifier having the extension as specified by {@link target_path}. |
||
1446 | * |
||
1447 | * @param $identifier identifier An image identifier |
||
1448 | * |
||
1449 | * @return boolean Returns TRUE on success or FALSE on error. |
||
1450 | * |
||
1451 | * If FALSE is returned, check the {@link error} property to see the error code. |
||
1452 | * |
||
1453 | * @access private |
||
1454 | */ |
||
1455 | public function _write_image($identifier) |
||
1570 | } |
||
1571 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.