General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 22nd, 2003, 12:27 AM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
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

Reply With Quote
  #2  
Old December 2nd, 2003, 01:10 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
thecharking,

Try using "imageCopyResampled()" as opposed to "imageCopyResized()".

I read in the GD documentation that using this method can yield better results, as it tries to interpolate the pixels, as well as closely match colors of the same palette:

http://www.boutell.com/gd/manual2.0...mageCopyResized

Read the notes about that function, as well as ImageCopyResampled() which is directly underneath!

HTH!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > resize pics makes poor quality


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway