
November 22nd, 2003, 12:27 AM
|
|
Contributing User
|
|
Join Date: Apr 2003
Posts: 187
Time spent in forums: < 1 sec
Reputation Power: 6
|
|
|
resize pics makes poor quality
i recently have been trying to do some image resizing for a website I'm making. This is the script I'm using. It is producing poor wuality images, and also I was wondering if there is a way to take this and make it resize the width to 300 and make the height in porper proportian.
PHP Code:
<?php
header("Content-type: image/jpeg");
header("Content-type: image/png");
$new_width=300; //Image width, Change if needed
$new_height=300; //Image height, Change if needed
$source_path = "pics/pending/" . $userid . "/"; //Source File path
$destination_path = "pics/pending/" . $userid . "/thumbs/"; //Destination file path
$db = mysql_connect("localhost", "admin","") or die("Cannot Connect"); // Database Connection
mysql_select_db("passedtime",$db) or die("Cannot open database"); //Database Name
$sql = mysql_query("SELECT current FROM pics WHERE userid = " . $userid) or die("Query failed"); //Query
while ($row = mysql_fetch_array($sql))
{
$image_name = $row["current"]; //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
}
}
//JPEG function
function thumb_jpeg($image_name)
{
global $source_path;
global $destination_path;
global $new_width;
global $new_height;
$destimg=ImageCreate($new_width,$new_height) or die("Problem In Creating image");
$srcimg=ImageCreateFromJPEG($source_path.$image_na me) or die("Problem In opening Source Image");
ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_wid th,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die("Problem In resizing");
ImageJPEG($destimg,$destination_path.$image_name) or die("Problem In saving");
}
//PNG function
function thumb_png($image_name)
{
global $source_path;
global $destination_path;
global $new_width;
global $new_height;
$destimg=ImageCreate($new_width,$new_height) or die("Problem In Creating image");
$srcimg=ImageCreateFromPNG($source_path.$image_nam e) or die("Problem In opening Source Image");
ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_wid th,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die("Problem In resizing");
ImagePNG($destimg,$destination_path.$image_name) or die("Problem In saving");
}
?>
thanks
__________________
hey it's the CHARKING
|