For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > June 2004 > Image Resize









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Image Resize
Kenny

2004-06-26, 8:55 am

Hi All,

Does anyone know if you can resize a tif image?
I have created a photo gallery and the client want to be able to upload
Jpeg and Tiff files, Unfortunately I have never worked with Tiff

Here is my code for Jpg files, But tiff has me stumped

<?php
$extra_path = "";
if ($mode == "small") {
$thumbnailsize = 100;
} else if ($mode == "med") {
$thumbnailsize = 140;
} else if ($mode == "large") {
$thumbnailsize = 200;
} else if ($mode == "smalladmin") {
$thumbnailsize = 150;
$extra_path = "../";
}

$path = $extra_path . "data/$file";
$img = ImageCreateFromJPEG($path);
$originalX = imagesx($img);
$originalY = imagesy($img);
if ($originalX > $originalY) {
$sf = (double) $thumbnailsize / $originalX;
} else {
$sf = (double) $thumbnailsize / $originalY;
}
$neww = $originalX * $sf;
$newh = $originalY * $sf;
$tn = ImageCreateTrueColor($neww, $newh); //ImageCreate
ImageCopyResampled($tn, $img, 0,0,0,0, $neww, $newh, $originalX,
$originalY); //ImageCopyResized
Header("Content-Type: image/jpeg");
ImageJPEG($tn);
ImageDestroy($tn);
ImageDestroy($img);
?>

K-

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com