(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.
<? //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.
Back to the parent page