Skip to content

Instantly share code, notes, and snippets.

@jonom
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save jonom/b6faf6e32d7cb21241e1 to your computer and use it in GitHub Desktop.

Select an option

Save jonom/b6faf6e32d7cb21241e1 to your computer and use it in GitHub Desktop.

Revisions

  1. jonom revised this gist May 20, 2015. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions MaxWidthHeightImageExtension.php
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,5 @@
    <?php

    //Untested. Please let me know if it works :)

    class MaxWidthHeightImageExtension extends DataExtension {

    /**
  2. jonom created this gist May 19, 2015.
    30 changes: 30 additions & 0 deletions MaxWidthHeightImageExtension.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    <?php

    //Untested. Please let me know if it works :)

    class MaxWidthHeightImageExtension extends DataExtension {

    /**
    * Crop an image if it exceeds a certain height.
    * Use in templates e.g. $Image.SetWidth(200).MaxHeight(200)
    *
    * @param integer $maxHeight Max height of image
    * @return Image
    */
    public function MaxHeight($maxHeight) {
    if ($this->owner->height > $maxHeight) return $this->owner->CroppedImage($this->owner->width, $maxHeight);
    return $this->owner;
    }

    /**
    * Crop an image if it exceeds a certain width.
    * Use in templates e.g. $Image.SetHeight(200).MaxWidth(200)
    *
    * @param integer $maxWidth Max width of image
    * @return Image
    */
    public function MaxWidth($maxWidth) {
    if ($this->owner->width > $maxWidth) return $this->owner->CroppedImage($maxWidth, $this->owner->height);
    return $this->owner;
    }
    }