This ExpressionEngine plugin will resize any JPG GIF or PNG image to the desired size specified
in your EE tag and cache the resized image to the cache folder. If you update
the original image a new resized version will be created. If the image is not on the server the tag will not return anything.
The general architecture of this plug-in is setup in a way that it only processes images when needed.
{exp:imgsizer:size}
- src= (required) the path from "webroot" to the image or the URL to the image
/images/news/moped.jpg or http://www.lumis.com/images/news/moped.jpg
- width= the width you wish the image to resized to. the height is resized proportionately
or
- height= the height you wish the image to resized to. the width is resized proportionately
or
- auto= the size of the longest side. If the image is landscape, then this sets the width, else it sets the height.
NOTE:
- if you use both width and height, width will take precedence
- if you use auto, the width and height parameters are ignored.
- if "width" is = to "height" the image will be cropped from image center to make a square sized image.
- quality="90" (optional for JPG images) ranges from 0 (worst quality, smaller file) to 100 (best quality, biggest file). The default is the default value is (90).
- greyscale="yes" (optional) if set to yes imagesizer will convert color images to greyscale
- mask="90" (optional) Applys a Unsharp mask if the image is a jpg (only numerical Values)
- mask_radius="0.5" (optional) defaults to 0.5 if not provided
- mask_threshold="3" (optional) defaults to 3 if not provided
- justcheck= (Single Tag only) if set to yes the tag will return a 1 if the source image exists. useful for php post processing
- justurl= (Single Tag only) if set to yes the tag will only return the relative path to the image from http root useful for css background images or XML nodes
- title= (Single Tag only) the title attribute of the image
- alt= (Single Tag only) the alt attribute of the image
- id= (Single Tag only) the id of the image
- class= (Single Tag only) the class of the image
- cache="no" allows you to turn off image caching (not a good idea) setting this to "no" means your images will be reprocessed every time the page is loaded (this param defaults to yes)
Example {exp:imgsizer:size}
updated v.2.0.2
- quality param for JPG output Compression
- added greyscale output option
updated v.2.0
- no longer uses EE's Image lib (requires GD lib be installed)
- Transparency on GIF and PNG are maintained.
- no longer creates a intermediate image for square sizing saving disk space
- large image files are processed.
updated v.1.6.5
- added options to turn of caching and more control over Unsharp Mask
updated v.1.6.1
- Added Unsharp Mask - if you have your Image settings in the ExpressionEngine CP set to use GD2 and your image type is a jpg
updated v.1.6
- Square sizing if "width" is = to "height" the image will be cropped from image center to make a square sized image
updated v.1.5.3 (Thanks to Erin Dalzell )
- Auto Sizing = the size of the longest side. If the image is landscape, then this sets the width, else it sets the height.
updated v.1.5.1
- uses Expression Engines filename security
- Fixes a bug if EE was not installed in web-root. (Thanks to Gonzalingui)
Requirements / setup:
- ExpressionEngine 1.6+ (it may work on older version but i started developing this on 1.6 and there is no reason i can think of not to upgrade)
- requires GD lib be installed
- setup: put pi.imgsizer.php in your plug-ins folder.
Download: ExpressionEngine image sizer 2.0.2
I get this warning:
Warning: imagejpeg() [function.imagejpeg]: SAFE MODE Restriction in effect. The script whose uid is 1043 is not allowed to access..
Anyone know what to do?
I wanted to be able to automatically crop images that were the wrong aspect ratio.
Just two lines need to be changed to add an additional ‘force_crop’ parameter.
~ line 77 under
$auto = ( ! $TMPL->fetch_param(’auto’)) ? ‘’ : $TMPL->fetch_param(’auto’);
add
$force_crop = ( ! $TMPL->fetch_param(’force_crop’)) ? ‘’ : $TMPL->fetch_param(’force_crop’);
~ line 286 change
if($max_width == $max_height && $auto == “"){
to:
if(($max_width == $max_height && $auto == “")||($force_crop == “true")){
Perfic!
Good work David, this is a fantastic plugin.
The images that are resized have a lot of jpeg artifacts. Where is the jpeg compression set? --in the GD libary or by Image Sizer? There doesn’t seem to be any parameters to set it.
I love this plugin, is there any planned functionality for cropping to a rectangle (non-square)?
@Mark @David
Sorry, guys. The problem turned out to be a bad path variable on my part. Easy to miss. Hard to find. That said, Image Sizer 2.x is working fine with 1.6.3.
While I’m here, how about a feature request?
In 1.6.8, if an image source was below the dimensions requested in image sizer, it was not modified. If I fed Image Sizer a 200x200 pixel image and requested it to be 300x300, it would be left alone. At least, that’s the way it worked with ImageMagick.
The new version is upsizing when I don’t want that to happen.
Can there be a parameter added for GD2 to behave similarly?
{exp:imgsizer:size up="no" ... }
Actually it looks as though i am wrong, sorry both David & Richard. I just noticed your updated post on EE Richard.
David sorry for the two comments. Please delete them if you need to.
Hope you all have a great weekend though just before I get deleted!! :-)
Best wishes,
Mark
I could be wrong Richard but I think this works just with the GD lib now?
Sorry if that’s incorrect David?
Best wishes,
Mark
Image Sizer was working perfectly with EE 1.6.2 and ImageMagick.
After upgrade to EE 1.6.3 - Image Sizer is no longer functioning.
Hey
Love it. Just a small error though, line 434, the second alt= does not have a space before it - this causes an XHTML validity fail. Currently
$out_tag .= ($alt ? “ alt=\"$alt\"” : “alt=\"\"");
Should be
$out_tag .= ($alt ? “ alt=\"$alt\"” : “ alt=\"\"");
David,
You are a true genius!!! :-)
Thank you thank you thank you for updating the plugin. This is really really appreciated. No longer having the intermediary image is literally a life-saver for me so thank you so much for that.
This is truly one of those plugins that should go down in history as saving a man’s bacon…
…mine that is!! :-)
Thanks again David, absolutely brilliant!
Best wishes,
Mark