Skip to content

Image Resize

Important: I am no longer maintaining this plugin. If you would like to take over development, please let me know below and I will be happy to transfer it’s development to you. There have also been several forks of it which you can use:


Text only. No markup allowed.


This slick plugin takes care of the need for resized thumbnails in articles without the need for a complicated thumbnail component.  If you want to put a thumbnail size image in an article but keep the full size available on the server, this is for you.  Details below.

Written by Daniel Beck

To give credit where it is due, I am not the author of this plugin.  It was written by my friend Daniel Beck; the most I did was provide a few ideas for its implementation.  Now I host it for him and will field any bug reports and feature requests.

Current Version: .5

Version .5 of the image resize plugin is available from http://joomlacode.org/gf/project/imageresize/frs/.

There is a feature request and bug tracker open at http://joomlacode.org/gf/project/imageresize/tracker/.

Usage:

This plugin is completely transparent to the user.  (That’s the beauty of it.)  Simply upload the image using Joomla!’s normal image upload function.  Then grab the image and drag it to resize, or use the dialog box to specify a width for the image.

When an article is accessed, the image resize plugin will find all the images in the article and resize them per the defined “width” attribute, caching the resized version.  If there is no width attribute it will leave the image at its normal size.  It only does this resizing the first time the image is accessed at any given width; after that it pulls the image from the already cached version.  Then the plugin replaces the src attribute on the image tag with the URL for the resized version.  Thus the user never sees the plugin, and the URLs still point straight to images instead of passing a size as a parameter, which could be a security flaw.

So whenever you access the article from the front-end, any image will be scaled to exactly the size specified in the width attribute.  When you access the article in the editor it still pulls the original image, not the resized version, so you can easily change the image’s size.

One thing to note: if you set the image width larger than the original width of the image it will, of course, become fuzzy.

Installation:

  1. Make sure you have Imagemagick on your server
  2. Install the plugin
  3. Go to your Plugin Manager and enable the plugin
  4. That’s it, you’re done!
29 Comments
  1. 14 August 2008 13:38

    Slick is an understatement.

    I really loved the auto thumbnail ability of WordPress and not having it with joomla seemed very short-sighted.

    Great work lads!

  2. 14 August 2008 16:55

    Thank you

  3. Eric permalink
    14 August 2008 22:22

    Great, but dear author use the right joomla name.

    not
    image_resize_.5.zip

    but
    plg_image_resize_v5.zip

  4. 14 August 2008 22:26

    Just Tested it, works very well :), although Simple Image Gallery and Image Resize cannot be used in the same page. Looks like am gonna be using it in any case, thank you very much :)

  5. 15 August 2008 08:46

    Now that sounds like a great tool. So some clients we have, that can not work with adobe or does not understand resizing tool at JCE pro,can now easely resize at Joomla editor. Could be just the thing we needed. We are going to test and use it!

    Thanks!!

  6. Sunny permalink
    16 August 2008 14:42

    I received an error stating that there was no XML file to read. The XML file is clearly there in the zipped folder. Joomla 1.5.

    Any help? Thanks.

  7. 18 August 2008 01:32

    Anyone know if there is a plugin that will show thumbnails of images when inside the ‘intro text’ preview, but full images on the article page?

    Or should I just put two copies of the image in the article, one small one in the intro and a large one below the “Read more…” cut off? Then I have to hide the intro text on article pages, but that may be easier … Thoughts?

    Sorry if this is a noob-ish question, just learning Joomla.

    Thanks!

  8. 18 August 2008 02:23

    I’m getting the following error on a Dreamhost Joomla install:

    Warning: mkdir() expects at most 2 parameters, 3 given in [path omitted -J]/plugins/content/imageresize.php on line 52

    • 13 June 2009 11:57

      I too am havinng the

      ‘Warning: mkdir() expects at most 2 parameters, 3 given in [path omitted -J]/plugins/content/imageresize.php on line x’ problem. Did anybody find a cure for it in the end? can it be sorted?

  9. 18 August 2008 02:55

    @Jonah: Perfectly fine question, I’ve come up against the same problem myself. My answer was what you decided upon, putting the image in twice. I’m sure you could write a plugin that finds the first image tag, resizes it to a set size, and places that in the article. It just feels like there would be a lot of potential problems with that.

    As far as mkdir(), what version of PHP are you running, and with what server stack? Feel free to email me and we can work on it.

    • 18 March 2009 10:36

      Did you come up with any solution to the mkdir() problem? I am having the same issue and would be grateful if you could share some knowledge!

  10. Jeroen permalink
    4 September 2008 09:25

    Thanks, this is just the resize extension which does nothing less or more than I need. Very simple installation and usage.

  11. Hans Peeters permalink
    11 December 2008 07:31

    Is there a way to let this wonderfull little gem run as a other user then the apache user, im getting trouble that the directories created in the cache folder have the wrong permissions

  12. 11 December 2008 08:29

    @Hans: I think that will be less a problem of this particular module as what user you have PHP running under. I’ll try to look into it sometime.

  13. 29 January 2009 14:12

    Just Tested it, works very nice

  14. 10 February 2009 10:17

    Looks nice…
    i will try it

    A-D-I

  15. JoePoika permalink
    20 February 2009 05:28

    This functionality is really something I would have expected to build into Joomla core. Thanks for sharing.

    I had only on problem: this plugin uses exec-function which is disabled for security reasons in the web-hotel I am using. So I changed the plugin little bit to suit my needs. Thought I’d share it here in case anyone else faces same kinda problems. Here goes:

    The are actualy three image-resize methods: the first commented line is the original using exec. Then using Imagemagick-extension (which my web-hotel neither provided) and finally using GD. Note that the implementation below only works for jpgs. So if you need support for gifs and pngs you must check the extension and call propriate gd functions for each type.

    // create the file if it doesn’t exist
    if(!file_exists($cache)) {
    //exec(‘convert -resize “‘ . $width . ‘” “‘ . $imageDir . “/” . $fileName . ‘” “‘ . $cache . ‘”‘);
    //$thumb = new Imagick($imageDir . “/” . $fileName);
    //$thumb->resizeImage($width,0,Imagick::FILTER_LANCZOS,1);
    //$thumb->writeImage($cache);
    //$thumb->destroy();
    $original = imagecreatefromjpeg($imageDir . “/” . $fileName);
    $imgSize = getimagesize($imageDir . “/” . $fileName);
    $oWidth = $imgSize[0];
    $oHeight = $imgSize[1];
    $height = $width * ($oHeight/$oWidth);
    $thumb = imagecreatetruecolor($width, $height);
    imagecopyresampled($thumb, $original, 0, 0, 0, 0, $width, $height, $oWidth, $oHeight);
    imagejpeg($thumb, $cache, 75);
    imagedestroy($thumb);
    imagedestroy($original);
    }

  16. 24 February 2009 12:55

    Wonder why this isn’t a core feature already. Great work but I guess I have found a bug: the plugin discards several images on my host.

  17. 24 February 2009 13:13

    I could track the problem down. Guess it was a typical I/O Error (Incompetent Operator) in combination with a bug on handling images having blanks in their name…

  18. Jesse van Bekkum permalink
    1 March 2009 08:30

    Fantastic extension. I had one issue, my cache had 755 permissions, but then I had a permission error. Setting the cache to 777 solved it, but I would rather not do that. You think it’s possible to have this work through the ftp layer of joomla1.5?

  19. 9 April 2009 15:07

    Great extention. It has not been updated for a while. I implemented the bugfixes at joomlacode.org myself, and it seems to run smoothly. Thanks a lot, guys.

  20. 24 April 2009 05:50

    Problem with JoomlaPack, XAMPP and ImageResize

    Hi, just thought I would share this.
    Recently I tried to backup/migrate a site from a webhost to my computer running XAMPP. I backed up with JoomlaPack and used kickstart.php to install the site on my XAMPP in windows.
    The Joomla site does not run a lot of extensions, however I have installed Image Resize. http://extensions.joomla.org/extensions/5694/details a great plugin.
    When I installed the site on my local machine, no images would display in the front-end, but they did display in the backend. I tried several options; backing up the site using FTP and PhpMyadmin – i.e. not using JoomlaPack, disabling .htaccess, purging the cache, saving articles. Nothing worked. When I tried migrating to a sub-domain on my webhost, the images would display in the frontend without any problems.

    Solution: After running kickstart.php, enter the backed and un-publish the Image Resize Plugin, purge the cache and expired cache and publish the Image Resize Plugin again. Presto!.

    Is it weird that this problem would occur on migrating to XAMPP but not to a linux-based webhost. Oh, well I found a solution.

    A big thank you to the developers of Joomla, JoomlaPack and Image Resize.

    • 24 April 2009 06:22

      so sorry. I just found out, that when I re-publish the Image Resize Plugin the problem returns…

      • GLjungberg permalink
        25 November 2009 13:39

        … and the same happens to me on a Linux-server

  21. Jesse van Bekkum permalink
    20 October 2009 17:18

    One comment: The dragging/resizing does not work in Google chrome, but displaying the image does. Resizing does work in Firefox

  22. joe2night permalink
    19 November 2009 10:05

    Hi!

    Since the public servers (even the paid ones) NEVER have imagemagic it’s completely useless to write code which relies on it. Here is a modified version (open up imageresize.php and replace the getCache function) which doesn’t require imagemagic. It works perfectly, enjoy:
    function getCache($imagePath, $restofTag)
    {

    //first, check to see if the rest of the tag has the width parameter
    $wPattern = ‘/width=”([^"]*)”/’;
    preg_match($wPattern, $restofTag, $match);

    if($match[1] > 0) {
    $imgData = getimagesize($imagePath);
    $width = $match[1];
    $height = round(($width/$imgData[0])*$imgData[1]);
    } else{
    $imgData = getimagesize($imagePath);
    $width = $imgData[0];
    $height = round(($width/$imgData[0])*$imgData[1]);
    }

    $fileName = getFileName($imagePath);
    if($imgData['mime'] == “image/png” || $imgData['mime'] == “image/x-png”){
    $source = imagecreatefrompng($imagePath);
    } elseif($imgData['mime'] == “image/gif”){
    $source = imagecreatefromgif($imagePath);
    } else{
    $source = imagecreatefromjpeg($imagePath);
    }
    $imageDir = getDir($imagePath);
    $imageCacheDir = “cache/” . getDir($imagePath);

    $fileNameCache = $width . “-” . $fileName;

    $cache = $imageCacheDir . “/” . $fileNameCache;

    // create the cache if it doesn’t exist
    if(!is_dir($imageCacheDir))
    mkdir($imageCacheDir,0777,true);

    // create the file if it doesn’t exist
    if(!file_exists($cache)) {
    $new_image = imagecreatetruecolor($width,$height);
    imagecopyresampled($new_image,$source,0,0,0,0,$width,$height,$imgData[0],$imgData[1]);
    imagejpeg($new_image,$cache);
    chmod($cache, 0777);
    //exec(‘convert -resize “‘ . $width . ‘” “‘ . $imageDir . “/” . $fileName . ‘” “‘ . $cache . ‘”‘);
    }

    if(!file_exists($cache))
    return null;

    return “”;
    }

  23. 24 November 2009 10:42

    Hi I have the same problem

    Warning: mkdir() [function.mkdir]: File exists in …content/imageresize.php on line 52

    Warning: mkdir() [function.mkdir]: File exists in …plugins/content/imageresize.php on line 52

    I use php5 on ovh server please give me a solution

  24. 15 January 2010 14:46

    Thanks for the great extention

    I do some tweak including
    – apply patch from bug tracker
    – apply with image inside “images/stories/” only
    – with a longer width image only

    code (only php file ) is available at
    http://www.thairobotics.com/index.php?option=com_phocadownload&view=category&id=5:joomlacode&download=4:imageresizephp&Itemid=17

  25. Mike permalink
    16 January 2010 14:15

    The idea behind this plugin is great. Unfortunately, the coding-style of this plugin is not perfect and may lead to others problems:

    * there is no (built-in) way deleting images from the cache.
    * images with the right width are also cached. why?
    * only works when there is exactly one space and no other tags between ‘<img' and 'src=":..:"'. This makes is not working with JCE image-manager and others

    If will improve the code and send if to the author.

    reg, m

Comments are closed.