We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13445 ☆ A M B ☆
    • 18 Posts
    I thought I would share this as I needed this for a client site for updating all their old press releases/events headline image. I thought I would share in case this was helpful to anyone. One of their issues was their headline images were always 20-40px off in width, some larger than the new container others smaller. So I made this to help automate a lot of the process

    Snippet name: imageSizer
    $output = '';
    if (isset($scriptProperties['width']))
    	{
    	$newWidth = $scriptProperties['width'];
    	};
    if (isset($scriptProperties['height']))
    	{
    	$newHeight = $scriptProperties['height'];
    	};
    $theImage = $link = $modx->config['base_path'] . $input;
    list($width, $height, $type, $attr) = getimagesize($theImage);
    if (isset($newWidth))
    	{
    	$newHeight = floor(($newWidth * $height) / $width);
    	$output.= 'width="' . $newWidth . 'px" height="' . $newHeight . 'px"';
    	};
    if (isset($newHeight))
    	{
    	$newWidth = floor(($newHeight * $width) / $height);
    	$output.= 'width="' . $newWidth . 'px" height="' . $newHeight . 'px"';
    	};
    if (!isset($newHeight) && !isset($newHeight))
    	{
    	$output.= 'width="' . $width . 'px" height="' . $height . 'px"';
    	};
    return $output;
    


    I'm calling it in an image tag in my templates:
    <img src="[[*introImage]]" alt="[[*pagetitle]]" [[imageSizer? &input=`[[*introImage]]` &width=`610`]] />

    This lets me set the width and it returns the width and height proportional to the width paramater I set. You could set a height the same way and it returns a proportional width.

    I also use it as a regular Output filter in places:
    <img src="[[*galleryImage]]" alt="[[*pagetitle]]" [[*galleryImage:imageSizer]] />
    Just drops in the width and height without any scaling at all.

    Not sure if it's the most efficient thing but it's come in rather handy.
    Hope this is helpful to folks!

      Senior Designer at Arketi Group - http://www.arketi.com
      Twitter - @jalterixnar - https://twitter.com/jalterixnar

      “There is no dishonor in failing, only in the failure to try.” – Elder fire dragon Kaernyth
      • 40045
      • 534 Posts
      Was there something that did not work with phpthumbof filter? because for tasks like that I usually use this extra =)