Hi Guys,
I have this thumbnail script, but I want to set the width to 200px wide and the height constrained automaticically to the width.
Can anyone please help:
<?
header("Content-type: image/jpeg");
Header("Content-type: image/png");
$new_width=200; //Image width Change if needed
$new_height=200; //Image height THIS NEEDS TO BE MODIFIED
$source_path="pics/"; //Source File path
$destination_path="small/"; //Destination file path
$db = mysql_connect("localhost", "*********","**********") or die("Cannot Connect"); // Database Connection
mysql_select_db("sleaz_green",$db) or die("Cannot open database"); //Database Name
$sql = mysql_query("SELECT * FROM **********") or die("Query failed"); //Query
while ($row = mysql_fetch_array($sql))
{
$image_name = $row["url"]; //Image path retrived
//Identifying Image type
$len = strlen($image_name);
$pos =strpos($image_name,".");
$type = substr($image_name,$pos + 1,$len);
if ( $type=="jpeg" || $type=="jpg")
{
thumb_jpeg ($image_name); //Call to jpeg function
}
else if($type="png" || $type="PNG")
{
thumb_png ($image_name); //Call to PNG function
}
echo "<b>Done........</b>";
}
// JPEG function
function thumb_jpeg($image_name) {
global $source_path, $destination_path, $new_width, $new_height;
$destimg = imagecreatetruecolor($new_width, $new_height) or die('Problem creating image');
$srcimg = imagecreatefromjpeg($source_path . $image_name) or die('Problem opening source image');
imagecopyresampled($destimg, $srcimg, 0, 0, 0, 0, $new_width, $new_height, imagesx($srcimg), imagesy($srcimg)) or die('Problem resizing image');
imagejpeg($destimg, $destination_path . $image_name) or die('Problem saving image');
}
// PNG function
function thumb_png($image_name) {
global $source_path, $destination_pth, $new_width, $new_height;
$destimg = imagecreatetruecolor($new_width, $new_height) or die('Problem creating image');
$scrimg = imagecreatefrompng($source_path . $image_name) or die('Problem opening source image');
imagecopyresampled($destimg, $srcimg, 0, 0, 0, 0, $new_width, $new_height, imagesx($srcimg), imagesy($srcimg)) or die('Problem resizing');
imagepng($destimg, $destination_path . $image_name) or die('Problem saving image');
}
?>