|
|
#1 (permalink) |
|
New Member
![]() Join Date: Jun 2007
Posts: 1
|
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. |
|
|
|
|
|
#3 (permalink) |
|
New Member
![]() Join Date: Sep 2007
Location: Los Angeles, California
Posts: 12
|
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 . "&maxW=" . $max_width . "&maxH=" . $max_height . "&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,$res izedH); 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'); ?>
__________________
Imagn Design: Los Angeles Web Design Firm |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|