External image size.

TBuck

New Member
I was wondering if anyone could write a script that will adjust the image width/height from an external javascript file.

I have the same image on alot of pages and don't want to adjust the size on everyone when i decide to change it.

So if there was some way to input a single number into one file and have it adjust it on all of the other pages that would be great... i know the basic basics of javascript but know a lot in HTML so i'll try to follow what your saying.
 

zkiller

Super Moderator
Staff member
i use the aspjpeg component from persists to do this on the fly. however, to use it you would need to find a host that offers it. i am sure their are also ways to do this using php, i don't know about basic javascript though.
 

Imagn

New Member
PHP Solution:

-----------------------------------------------------
FUNCTION
-----------------------------------------------------

function createThumbnail($img_file, $max_width, $max_height, $img_quality, $img_path='images', $class='', $alt_tag='') {

$nameparts = pathinfo($img_file);
$file_extension = $nameparts['extension'];

$thumb_script = "create_thumbs.php";

$z = "<img src=\"" . $thumb_script . "?photo_file=" . $img_path . "/" . $img_file . "&amp;maxW=" . $max_width . "&amp;maxH=" . $max_height . "&amp;quality=" . $img_quality . "\" alt=\"" . $alt_tag . "\" class=\"" . $class . "\" />";
echo $z;
}




-----------------------------------------------------
'create_thumbs.php' PAGE
-----------------------------------------------------

<?php
!isset($_GET['maxW']) ? $_GET['maxW']=400 : NULL;
!isset($_GET['maxH']) ? $_GET['maxH']=400 : NULL;
!isset($_GET['quality']) ? $_GET['quality']=100 : NULL;
$ratio=1;
$sourceHandle=imagecreatefromjpeg($_GET['photo_file']);
$sourceW=imagesx($sourceHandle);
$sourceH=imagesy($sourceHandle);
if ($sourceW>$sourceH) { $sourceW>$_GET['maxW'] ? $ratio=$_GET['maxW']/$sourceW : NULL; } elseif ($sourceW<$sourceH) { $sourceH>$_GET['maxH'] ? $ratio=$_GET['maxH']/$sourceH : NULL; } else { $ratio=min($_GET['maxH'],$_GET['maxW'])/$sourceH; }
$resizedW=$sourceW*$ratio;
$resizedH=$sourceH*$ratio;
$resizedHandle=imagecreatetruecolor($resizedW,$resizedH);
imagecopyresampled($resizedHandle,$sourceHandle,0,0,0,0,$resizedW,$resizedH,$sourceW,$sourceH);
//$resizedHandle=imagecreate($resizedW,$resizedH);
//imagecopyresized($resizedHandle,$sourceHandle,0,0,0,0,$resizedW,$resizedH,$sourceW,$sourceH);
header('Content-type: image/jpeg');
imagejpeg($resizedHandle,'',$_GET['quality']);
imagedestroy($sourceHandle);
imagedestroy($resizedHandle);
?>



-----------------------------------------------------
CALL TO IMAGE WITHIN HTML
-----------------------------------------------------

<?php createThumbnail($FILENAME,130,130,90,'FILE_PATH'); ?>
 
Top