The 404 module has received a security update for any version below v1.6!
If you are using this module on your website you are advised to upgrade the module as soon as possible!

Sorry, this page is only available in one language

Experimental Image Resizer script - WebsiteBaker

(Note: The droplet is also included in the download)

Unpack the zip on your local computer.
The script (image.php) must be placed in the /media/ directory.
It should have sufficient rights to create a cache directory for the cache to function. ( /media/cached_images/ )
The content of droplet.txt should be used to create your droplet.

Droplet code (v4)

<? //Scan page and replace all <img src=''> with a width or height set found in attributes of inline style information
//Should also work with images sized in CK-Editor

$sMediaUrl = WB_URL.MEDIA_DIRECTORY;
$wb_page_data = str_replace('{ SYSVAR:MEDIA_REL }', $sMediaUrl, $wb_page_data );

preg_match_all('/<img [^>]*>/im',$wb_page_data,$matches);
if(!count($matches))return true; // nothing found
foreach($matches[0] as $match){

    $width=0;
    $height=0;
    if(preg_match('/width="[0-9]*"/i',$match) && preg_match('/height="[0-9]*"/i',$match)){
        $width=preg_replace('/.*width="([0-9]*)".*/i','\1',$match);
        $height=preg_replace('/.*height="([0-9]*)".*/i','\1',$match);
    } elseif(preg_match('/style="[^"]*width: *[0-9]*px/i',$match) && preg_match('/style="[^"]*height: *[0-9]*px/i',$match)){
        $width=preg_replace('/.*style="[^"]*width: *([0-9]*)px.*/i','\1',$match);
        $height=preg_replace('/.*style="[^"]*height: *([0-9]*)px.*/i','\1',$match);
    } elseif(preg_match('/style="[^"]*width: *[0-9]*px/i',$match)){
        $width=preg_replace('/.*style="[^"]*width: *([0-9]*)px.*/i','\1',$match);
    } elseif(preg_match('/style="[^"]*height: *[0-9]*px/i',$match)){
        $height=preg_replace('/.*style="[^"]*height: *([0-9]*)px.*/i','\1',$match);
    }
    if(!$width || !$height) continue;
    $imgsrc = preg_replace('/.*src="([^"]*)".*/i','\1',$match);
    if(strpos($imgsrc,WB_URL.MEDIA_DIRECTORY) !== false ){ 
        $src = str_replace(WB_URL.MEDIA_DIRECTORY.'/','', $imgsrc);
        if(!file_exists(WB_PATH.MEDIA_DIRECTORY.'/'.urldecode($src))) continue;
        list($x,$y)=getimagesize(WB_PATH.MEDIA_DIRECTORY.'/'.urldecode($src));
        if(!$x || !$y || ($x==$width && $y==$height))continue;
          
        $search[]  = 'src="'.$imgsrc.'"';
        if($width) {
            $replace[] = 'src="'.WB_URL.'/media/images.php?i='.$src.'&w='.$width.'"';
        } else {
            $replace[] = 'src="'.WB_URL.'/media/images.php?i='.$src.'&h='.$height.'"';
        }
    }
}
if(isset($search)) $wb_page_data = str_replace($search,$replace,$wb_page_data);
return true;

Note: do not copy/paste the code above. It is modified a little bit to show the SYSVAR:MEDIA_REL in this page. Use the dropletcode in the download only!
Name the droplet something like "imgresizer" and include it on a page where you want the images to be resized.

Download

Imageresizer.v0.5.1.zip

Version 0.5.1
- fixes orientation (like vertical images from mobile phones)
- also handles webp images (creating jpg!)
- improved browser caching for resized images

* Droplet *
- dropletcode (v4) checks for existing files
License: GNU / GPL
Timestamp: 24-06-2020
Version: 0.5.1
Filesize: 2.61 KB
Downloads: 572

Imageresizer.v03.zip
Version: 0.3, Timestamp: 24-08-2017, Downloads: 793
Version 0.3
Bugfix - Droplet now first rewrites { SYSVAR:MEDIA_REL }.
The file images.php is not changed.

imageresizer.v02.zip
Version: 0.2, Timestamp: 17-08-2012, Downloads: 1663
Version 0.2
Imageresizer code similar to v0.1 but an improved droplet.
Now also supports inline style width/height settings (for CK-Editor)

imageresizer-v01.zip
Version: 0.1, Timestamp: 04-06-2012, Downloads: 1847
Version 0.1
Note: this is an experiment. It is not advised (yet) to use this in production websites

Back to the parent page