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 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 Image, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class Image extends File implements Flushable { |
||
| 10 | |||
| 11 | const ORIENTATION_SQUARE = 0; |
||
| 12 | const ORIENTATION_PORTRAIT = 1; |
||
| 13 | const ORIENTATION_LANDSCAPE = 2; |
||
| 14 | |||
| 15 | private static $backend = "GDBackend"; |
||
| 16 | |||
| 17 | private static $casting = array( |
||
|
|
|||
| 18 | 'Tag' => 'HTMLText', |
||
| 19 | ); |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @config |
||
| 23 | * @var int The width of an image thumbnail in a strip. |
||
| 24 | */ |
||
| 25 | private static $strip_thumbnail_width = 50; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @config |
||
| 29 | * @var int The height of an image thumbnail in a strip. |
||
| 30 | */ |
||
| 31 | private static $strip_thumbnail_height = 50; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @config |
||
| 35 | * @var int The width of an image thumbnail in the CMS. |
||
| 36 | */ |
||
| 37 | private static $cms_thumbnail_width = 100; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @config |
||
| 41 | * @var int The height of an image thumbnail in the CMS. |
||
| 42 | */ |
||
| 43 | private static $cms_thumbnail_height = 100; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @config |
||
| 47 | * @var int The width of an image thumbnail in the Asset section. |
||
| 48 | */ |
||
| 49 | private static $asset_thumbnail_width = 100; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @config |
||
| 53 | * @var int The height of an image thumbnail in the Asset section. |
||
| 54 | */ |
||
| 55 | private static $asset_thumbnail_height = 100; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @config |
||
| 59 | * @var int The width of an image preview in the Asset section. |
||
| 60 | */ |
||
| 61 | private static $asset_preview_width = 400; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @config |
||
| 65 | * @var int The height of an image preview in the Asset section. |
||
| 66 | */ |
||
| 67 | private static $asset_preview_height = 200; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @config |
||
| 71 | * @var bool Force all images to resample in all cases |
||
| 72 | */ |
||
| 73 | private static $force_resample = false; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @config |
||
| 77 | * @var bool Regenerates images if set to true. This is set by {@link flush()} |
||
| 78 | */ |
||
| 79 | private static $flush = false; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Triggered early in the request when someone requests a flush. |
||
| 83 | */ |
||
| 84 | public static function flush() { |
||
| 87 | |||
| 88 | public static function set_backend($backend) { |
||
| 91 | |||
| 92 | public static function get_backend() { |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Retrieve the original filename from the path of a transformed image. |
||
| 98 | * Any other filenames pass through unchanged. |
||
| 99 | * |
||
| 100 | * @param string $path |
||
| 101 | * @return string |
||
| 102 | */ |
||
| 103 | public static function strip_resampled_prefix($path) { |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Set up template methods to access the transformations generated by 'generate' methods. |
||
| 109 | */ |
||
| 110 | public function defineMethods() { |
||
| 111 | $methodNames = $this->allMethodNames(); |
||
| 112 | foreach($methodNames as $methodName) { |
||
| 113 | if(substr($methodName,0,8) == 'generate') { |
||
| 114 | $this->addWrapperMethod(substr($methodName,8), 'getFormattedImage'); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | parent::defineMethods(); |
||
| 119 | } |
||
| 120 | |||
| 121 | public function getCMSFields() { |
||
| 122 | $fields = parent::getCMSFields(); |
||
| 123 | |||
| 124 | $urlLink = "<div class='field readonly'>"; |
||
| 125 | $urlLink .= "<label class='left'>"._t('AssetTableField.URL','URL')."</label>"; |
||
| 126 | $urlLink .= "<span class='readonly'><a href='{$this->Link()}'>{$this->RelativeLink()}</a></span>"; |
||
| 127 | $urlLink .= "</div>"; |
||
| 128 | // todo: check why the above code is here, since $urlLink is not used? |
||
| 129 | |||
| 130 | //attach the addition file information for an image to the existing FieldGroup create in the parent class |
||
| 131 | $fileAttributes = $fields->fieldByName('Root.Main.FilePreview')->fieldByName('FilePreviewData'); |
||
| 132 | $fileAttributes->push(new ReadonlyField("Dimensions", _t('AssetTableField.DIM','Dimensions') . ':')); |
||
| 133 | |||
| 134 | return $fields; |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Return an XHTML img tag for this Image, |
||
| 139 | * or NULL if the image file doesn't exist on the filesystem. |
||
| 140 | * |
||
| 141 | * @return string |
||
| 142 | */ |
||
| 143 | public function getTag() { |
||
| 144 | if($this->exists()) { |
||
| 145 | $url = $this->getURL(); |
||
| 146 | $title = ($this->Title) ? $this->Title : $this->Filename; |
||
| 147 | if($this->Title) { |
||
| 148 | $title = Convert::raw2att($this->Title); |
||
| 149 | } else { |
||
| 150 | if(preg_match("/([^\/]*)\.[a-zA-Z0-9]{1,6}$/", $title, $matches)) { |
||
| 151 | $title = Convert::raw2att($matches[1]); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | return "<img src=\"$url\" alt=\"$title\" />"; |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Return an XHTML img tag for this Image. |
||
| 160 | * |
||
| 161 | * @return string |
||
| 162 | */ |
||
| 163 | public function forTemplate() { |
||
| 166 | |||
| 167 | /** |
||
| 168 | * File names are filtered through {@link FileNameFilter}, see class documentation |
||
| 169 | * on how to influence this behaviour. |
||
| 170 | * |
||
| 171 | * @deprecated 4.0 |
||
| 172 | */ |
||
| 173 | public function loadUploadedImage($tmpFile) { |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Scale image proportionally to fit within the specified bounds |
||
| 220 | * |
||
| 221 | * @param integer $width The width to size within |
||
| 222 | * @param integer $height The height to size within |
||
| 223 | * @return Image|null |
||
| 224 | */ |
||
| 225 | public function Fit($width, $height) { |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Scale image proportionally to fit within the specified bounds |
||
| 247 | * |
||
| 248 | * @param Image_Backend $backend |
||
| 249 | * @param integer $width The width to size within |
||
| 250 | * @param integer $height The height to size within |
||
| 251 | * @return Image_Backend |
||
| 252 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 253 | */ |
||
| 254 | public function generateFit(Image_Backend $backend, $width, $height) { |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Proportionally scale down this image if it is wider or taller than the specified dimensions. |
||
| 261 | * Similar to Fit but without up-sampling. Use in templates with $FitMax. |
||
| 262 | * |
||
| 263 | * @uses Image::Fit() |
||
| 264 | * @param integer $width The maximum width of the output image |
||
| 265 | * @param integer $height The maximum height of the output image |
||
| 266 | * @return Image |
||
| 267 | */ |
||
| 268 | public function FitMax($width, $height) { |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Resize and crop image to fill specified dimensions. |
||
| 279 | * Use in templates with $Fill |
||
| 280 | * |
||
| 281 | * @param integer $width Width to crop to |
||
| 282 | * @param integer $height Height to crop to |
||
| 283 | * @return Image|null |
||
| 284 | */ |
||
| 285 | public function Fill($width, $height) { |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Resize and crop image to fill specified dimensions. |
||
| 293 | * Use in templates with $Fill |
||
| 294 | * |
||
| 295 | * @param Image_Backend $backend |
||
| 296 | * @param integer $width Width to crop to |
||
| 297 | * @param integer $height Height to crop to |
||
| 298 | * @return Image_Backend |
||
| 299 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 300 | */ |
||
| 301 | public function generateFill(Image_Backend $backend, $width, $height) { |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Crop this image to the aspect ratio defined by the specified width and height, |
||
| 308 | * then scale down the image to those dimensions if it exceeds them. |
||
| 309 | * Similar to Fill but without up-sampling. Use in templates with $FillMax. |
||
| 310 | * |
||
| 311 | * @uses Image::Fill() |
||
| 312 | * @param integer $width The relative (used to determine aspect ratio) and maximum width of the output image |
||
| 313 | * @param integer $height The relative (used to determine aspect ratio) and maximum height of the output image |
||
| 314 | * @return Image |
||
| 315 | */ |
||
| 316 | public function FillMax($width, $height) { |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Fit image to specified dimensions and fill leftover space with a solid colour (default white). Use in templates with $Pad. |
||
| 339 | * |
||
| 340 | * @param integer $width The width to size to |
||
| 341 | * @param integer $height The height to size to |
||
| 342 | * @return Image|null |
||
| 343 | */ |
||
| 344 | public function Pad($width, $height, $backgroundColor='FFFFFF') { |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Fit image to specified dimensions and fill leftover space with a solid colour (default white). Use in templates with $Pad. |
||
| 352 | * |
||
| 353 | * @param Image_Backend $backend |
||
| 354 | * @param integer $width The width to size to |
||
| 355 | * @param integer $height The height to size to |
||
| 356 | * @return Image_Backend |
||
| 357 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 358 | */ |
||
| 359 | public function generatePad(Image_Backend $backend, $width, $height, $backgroundColor='FFFFFF') { |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Scale image proportionally by width. Use in templates with $ScaleWidth. |
||
| 366 | * |
||
| 367 | * @param integer $width The width to set |
||
| 368 | * @return Image|null |
||
| 369 | */ |
||
| 370 | public function ScaleWidth($width) { |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Scale image proportionally by width. Use in templates with $ScaleWidth. |
||
| 378 | * |
||
| 379 | * @param Image_Backend $backend |
||
| 380 | * @param int $width The width to set |
||
| 381 | * @return Image_Backend |
||
| 382 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 383 | */ |
||
| 384 | public function generateScaleWidth(Image_Backend $backend, $width) { |
||
| 388 | |||
| 389 | /** |
||
| 390 | * Proportionally scale down this image if it is wider than the specified width. |
||
| 391 | * Similar to ScaleWidth but without up-sampling. Use in templates with $ScaleMaxWidth. |
||
| 392 | * |
||
| 393 | * @uses Image::ScaleWidth() |
||
| 394 | * @param integer $width The maximum width of the output image |
||
| 395 | * @return Image |
||
| 396 | */ |
||
| 397 | View Code Duplication | public function ScaleMaxWidth($width) { |
|
| 405 | |||
| 406 | /** |
||
| 407 | * Scale image proportionally by height. Use in templates with $ScaleHeight. |
||
| 408 | * |
||
| 409 | * @param integer $height The height to set |
||
| 410 | * @return Image|null |
||
| 411 | */ |
||
| 412 | public function ScaleHeight($height) { |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Scale image proportionally by height. Use in templates with $ScaleHeight. |
||
| 420 | * |
||
| 421 | * @param Image_Backend $backend |
||
| 422 | * @param integer $height The height to set |
||
| 423 | * @return Image_Backend |
||
| 424 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 425 | */ |
||
| 426 | public function generateScaleHeight(Image_Backend $backend, $height){ |
||
| 430 | |||
| 431 | /** |
||
| 432 | * Proportionally scale down this image if it is taller than the specified height. |
||
| 433 | * Similar to ScaleHeight but without up-sampling. Use in templates with $ScaleMaxHeight. |
||
| 434 | * |
||
| 435 | * @uses Image::ScaleHeight() |
||
| 436 | * @param integer $height The maximum height of the output image |
||
| 437 | * @return Image |
||
| 438 | */ |
||
| 439 | View Code Duplication | public function ScaleMaxHeight($height) { |
|
| 447 | |||
| 448 | /** |
||
| 449 | * Crop image on X axis if it exceeds specified width. Retain height. |
||
| 450 | * Use in templates with $CropWidth. Example: $Image.ScaleHeight(100).$CropWidth(100) |
||
| 451 | * |
||
| 452 | * @uses Image::Fill() |
||
| 453 | * @param integer $width The maximum width of the output image |
||
| 454 | * @return Image |
||
| 455 | */ |
||
| 456 | View Code Duplication | public function CropWidth($width) { |
|
| 464 | |||
| 465 | /** |
||
| 466 | * Crop image on Y axis if it exceeds specified height. Retain width. |
||
| 467 | * Use in templates with $CropHeight. Example: $Image.ScaleWidth(100).CropHeight(100) |
||
| 468 | * |
||
| 469 | * @uses Image::Fill() |
||
| 470 | * @param integer $height The maximum height of the output image |
||
| 471 | * @return Image |
||
| 472 | */ |
||
| 473 | View Code Duplication | public function CropHeight($height) { |
|
| 481 | |||
| 482 | /** |
||
| 483 | * Resize the image by preserving aspect ratio, keeping the image inside the |
||
| 484 | * $width and $height |
||
| 485 | * |
||
| 486 | * @param integer $width The width to size within |
||
| 487 | * @param integer $height The height to size within |
||
| 488 | * @return Image |
||
| 489 | * @deprecated 4.0 Use Fit instead |
||
| 490 | */ |
||
| 491 | public function SetRatioSize($width, $height) { |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Resize the image by preserving aspect ratio, keeping the image inside the |
||
| 498 | * $width and $height |
||
| 499 | * |
||
| 500 | * @param Image_Backend $backend |
||
| 501 | * @param integer $width The width to size within |
||
| 502 | * @param integer $height The height to size within |
||
| 503 | * @return Image_Backend |
||
| 504 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 505 | */ |
||
| 506 | public function generateSetRatioSize(Image_Backend $backend, $width, $height) { |
||
| 510 | |||
| 511 | /** |
||
| 512 | * Resize this Image by width, keeping aspect ratio. Use in templates with $SetWidth. |
||
| 513 | * |
||
| 514 | * @param integer $width The width to set |
||
| 515 | * @return Image |
||
| 516 | * @deprecated 4.0 Use ScaleWidth instead |
||
| 517 | */ |
||
| 518 | public function SetWidth($width) { |
||
| 522 | |||
| 523 | /** |
||
| 524 | * Resize this Image by width, keeping aspect ratio. Use in templates with $SetWidth. |
||
| 525 | * |
||
| 526 | * @param Image_Backend $backend |
||
| 527 | * @param int $width The width to set |
||
| 528 | * @return Image_Backend |
||
| 529 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 530 | */ |
||
| 531 | public function generateSetWidth(Image_Backend $backend, $width) { |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Resize this Image by height, keeping aspect ratio. Use in templates with $SetHeight. |
||
| 538 | * |
||
| 539 | * @param integer $height The height to set |
||
| 540 | * @return Image |
||
| 541 | * @deprecated 4.0 Use ScaleHeight instead |
||
| 542 | */ |
||
| 543 | public function SetHeight($height) { |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Resize this Image by height, keeping aspect ratio. Use in templates with $SetHeight. |
||
| 550 | * |
||
| 551 | * @param Image_Backend $backend |
||
| 552 | * @param integer $height The height to set |
||
| 553 | * @return Image_Backend |
||
| 554 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 555 | */ |
||
| 556 | public function generateSetHeight(Image_Backend $backend, $height){ |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Resize this Image by both width and height, using padded resize. Use in templates with $SetSize. |
||
| 563 | * @see Image::PaddedImage() |
||
| 564 | * |
||
| 565 | * @param integer $width The width to size to |
||
| 566 | * @param integer $height The height to size to |
||
| 567 | * @return Image |
||
| 568 | * @deprecated 4.0 Use Pad instead |
||
| 569 | */ |
||
| 570 | public function SetSize($width, $height) { |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Resize this Image by both width and height, using padded resize. Use in templates with $SetSize. |
||
| 577 | * |
||
| 578 | * @param Image_Backend $backend |
||
| 579 | * @param integer $width The width to size to |
||
| 580 | * @param integer $height The height to size to |
||
| 581 | * @return Image_Backend |
||
| 582 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 583 | */ |
||
| 584 | public function generateSetSize(Image_Backend $backend, $width, $height) { |
||
| 588 | |||
| 589 | /** |
||
| 590 | * Resize this image for the CMS. Use in templates with $CMSThumbnail |
||
| 591 | * |
||
| 592 | * @return Image_Cached|null |
||
| 593 | */ |
||
| 594 | public function CMSThumbnail() { |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Resize this image for the CMS. Use in templates with $CMSThumbnail. |
||
| 600 | * |
||
| 601 | * @return Image_Backend |
||
| 602 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 603 | */ |
||
| 604 | public function generateCMSThumbnail(Image_Backend $backend) { |
||
| 608 | |||
| 609 | /** |
||
| 610 | * Resize this image for preview in the Asset section. Use in templates with $AssetLibraryPreview. |
||
| 611 | * |
||
| 612 | * @return Image_Backend |
||
| 613 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 614 | */ |
||
| 615 | public function generateAssetLibraryPreview(Image_Backend $backend) { |
||
| 619 | |||
| 620 | /** |
||
| 621 | * Resize this image for thumbnail in the Asset section. Use in templates with $AssetLibraryThumbnail. |
||
| 622 | * |
||
| 623 | * @return Image_Backend |
||
| 624 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 625 | */ |
||
| 626 | public function generateAssetLibraryThumbnail(Image_Backend $backend) { |
||
| 630 | |||
| 631 | /** |
||
| 632 | * Resize this image for use as a thumbnail in a strip. Use in templates with $StripThumbnail. |
||
| 633 | * |
||
| 634 | * @return Image_Cached|null |
||
| 635 | */ |
||
| 636 | public function StripThumbnail() { |
||
| 639 | |||
| 640 | /** |
||
| 641 | * Resize this image for use as a thumbnail in a strip. Use in templates with $StripThumbnail. |
||
| 642 | * |
||
| 643 | * @return Image_Backend |
||
| 644 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 645 | */ |
||
| 646 | public function generateStripThumbnail(Image_Backend $backend) { |
||
| 650 | |||
| 651 | /** |
||
| 652 | * Resize this Image by both width and height, using padded resize. Use in templates with $PaddedImage. |
||
| 653 | * @see Image::SetSize() |
||
| 654 | * |
||
| 655 | * @param integer $width The width to size to |
||
| 656 | * @param integer $height The height to size to |
||
| 657 | * @return Image |
||
| 658 | * @deprecated 4.0 Use Pad instead |
||
| 659 | */ |
||
| 660 | public function PaddedImage($width, $height, $backgroundColor='FFFFFF') { |
||
| 664 | |||
| 665 | /** |
||
| 666 | * Resize this Image by both width and height, using padded resize. Use in templates with $PaddedImage. |
||
| 667 | * |
||
| 668 | * @param Image_Backend $backend |
||
| 669 | * @param integer $width The width to size to |
||
| 670 | * @param integer $height The height to size to |
||
| 671 | * @return Image_Backend |
||
| 672 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 673 | */ |
||
| 674 | public function generatePaddedImage(Image_Backend $backend, $width, $height, $backgroundColor='FFFFFF') { |
||
| 678 | |||
| 679 | /** |
||
| 680 | * Determine if this image is of the specified size |
||
| 681 | * |
||
| 682 | * @param integer $width Width to check |
||
| 683 | * @param integer $height Height to check |
||
| 684 | * @return boolean |
||
| 685 | */ |
||
| 686 | public function isSize($width, $height) { |
||
| 689 | |||
| 690 | /** |
||
| 691 | * Determine if this image is of the specified width |
||
| 692 | * |
||
| 693 | * @param integer $width Width to check |
||
| 694 | * @return boolean |
||
| 695 | */ |
||
| 696 | public function isWidth($width) { |
||
| 699 | |||
| 700 | /** |
||
| 701 | * Determine if this image is of the specified width |
||
| 702 | * |
||
| 703 | * @param integer $height Height to check |
||
| 704 | * @return boolean |
||
| 705 | */ |
||
| 706 | public function isHeight($height) { |
||
| 709 | |||
| 710 | /** |
||
| 711 | * Return an image object representing the image in the given format. |
||
| 712 | * This image will be generated using generateFormattedImage(). |
||
| 713 | * The generated image is cached, to flush the cache append ?flush=1 to your URL. |
||
| 714 | * |
||
| 715 | * Just pass the correct number of parameters expected by the working function |
||
| 716 | * |
||
| 717 | * @param string $format The name of the format. |
||
| 718 | * @return Image_Cached|null |
||
| 719 | */ |
||
| 720 | public function getFormattedImage($format) { |
||
| 734 | |||
| 735 | /** |
||
| 736 | * Return the filename for the cached image, given its format name and arguments. |
||
| 737 | * @param string $format The format name. |
||
| 738 | * @return string |
||
| 739 | * @throws InvalidArgumentException |
||
| 740 | */ |
||
| 741 | public function cacheFilename($format) { |
||
| 769 | |||
| 770 | /** |
||
| 771 | * Generate an image on the specified format. It will save the image |
||
| 772 | * at the location specified by cacheFilename(). The image will be generated |
||
| 773 | * using the specific 'generate' method for the specified format. |
||
| 774 | * |
||
| 775 | * @param string $format Name of the format to generate. |
||
| 776 | */ |
||
| 777 | public function generateFormattedImage($format) { |
||
| 805 | |||
| 806 | /** |
||
| 807 | * Generate a resized copy of this image with the given width & height. |
||
| 808 | * This can be used in templates with $ResizedImage but should be avoided, |
||
| 809 | * as it's the only image manipulation function which can skew an image. |
||
| 810 | * |
||
| 811 | * @param integer $width Width to resize to |
||
| 812 | * @param integer $height Height to resize to |
||
| 813 | * @return Image |
||
| 814 | */ |
||
| 815 | public function ResizedImage($width, $height) { |
||
| 820 | |||
| 821 | /** |
||
| 822 | * Generate a resized copy of this image with the given width & height. |
||
| 823 | * Use in templates with $ResizedImage. |
||
| 824 | * |
||
| 825 | * @param Image_Backend $backend |
||
| 826 | * @param integer $width Width to resize to |
||
| 827 | * @param integer $height Height to resize to |
||
| 828 | * @return Image_Backend|null |
||
| 829 | */ |
||
| 830 | public function generateResizedImage(Image_Backend $backend, $width, $height) { |
||
| 838 | |||
| 839 | /** |
||
| 840 | * Generate a resized copy of this image with the given width & height, cropping to maintain aspect ratio. |
||
| 841 | * Use in templates with $CroppedImage |
||
| 842 | * |
||
| 843 | * @param integer $width Width to crop to |
||
| 844 | * @param integer $height Height to crop to |
||
| 845 | * @return Image |
||
| 846 | * @deprecated 4.0 Use Fill instead |
||
| 847 | */ |
||
| 848 | public function CroppedImage($width, $height) { |
||
| 852 | |||
| 853 | /** |
||
| 854 | * Generate a resized copy of this image with the given width & height, cropping to maintain aspect ratio. |
||
| 855 | * Use in templates with $CroppedImage |
||
| 856 | * |
||
| 857 | * @param Image_Backend $backend |
||
| 858 | * @param integer $width Width to crop to |
||
| 859 | * @param integer $height Height to crop to |
||
| 860 | * @return Image_Backend |
||
| 861 | * @deprecated 4.0 Generate methods are no longer applicable |
||
| 862 | */ |
||
| 863 | public function generateCroppedImage(Image_Backend $backend, $width, $height) { |
||
| 867 | |||
| 868 | /** |
||
| 869 | * Generate patterns that will help to match filenames of cached images |
||
| 870 | * @param string $filename Filename of source image |
||
| 871 | * @return array |
||
| 872 | */ |
||
| 873 | private function getFilenamePatterns($filename) { |
||
| 891 | |||
| 892 | /** |
||
| 893 | * Generate a list of images that were generated from this image |
||
| 894 | */ |
||
| 895 | private function getGeneratedImages() { |
||
| 935 | |||
| 936 | /** |
||
| 937 | * Regenerate all of the formatted cached images for this image. |
||
| 938 | * |
||
| 939 | * @return int The number of formatted images regenerated |
||
| 940 | */ |
||
| 941 | public function regenerateFormattedImages() { |
||
| 965 | |||
| 966 | /** |
||
| 967 | * Remove all of the formatted cached images for this image. |
||
| 968 | * |
||
| 969 | * @return int The number of formatted images deleted |
||
| 970 | */ |
||
| 971 | public function deleteFormattedImages() { |
||
| 989 | |||
| 990 | /** |
||
| 991 | * Get the dimensions of this Image. |
||
| 992 | * @param string $dim If this is equal to "string", return the dimensions in string form, |
||
| 993 | * if it is 0 return the height, if it is 1 return the width. |
||
| 994 | * @return string|int|null |
||
| 995 | */ |
||
| 996 | public function getDimensions($dim = "string") { |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * Get the width of this image. |
||
| 1011 | * @return int |
||
| 1012 | */ |
||
| 1013 | public function getWidth() { |
||
| 1016 | |||
| 1017 | /** |
||
| 1018 | * Get the height of this image. |
||
| 1019 | * @return int |
||
| 1020 | */ |
||
| 1021 | public function getHeight() { |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Get the orientation of this image. |
||
| 1027 | * @return ORIENTATION_SQUARE | ORIENTATION_PORTRAIT | ORIENTATION_LANDSCAPE |
||
| 1028 | */ |
||
| 1029 | public function getOrientation() { |
||
| 1040 | |||
| 1041 | public function onAfterUpload() { |
||
| 1045 | |||
| 1046 | protected function onBeforeDelete() { |
||
| 1054 | } |
||
| 1055 | |||
| 1116 |