FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Resize image in PNG Problem





AOP Web Development
Hello guys i just like to do a favor from you if you have any idea to change or if there is something in my code i try to create a function regarding on resizing image file. In both JPEG AND GIF files everything works fine but the problem is when i try to resize PNG file it doesn't work.. although it resize but when i try to preview the image i doesn't show. do you have any idea about it? here is my code

Code:
<?php

$origimage = 'design1.png';
$w="100";
$h="500";

$thumbheight = $image_y * $ratio;

list($image_x,$image_y) = getimagesize($origimage);
$ws= ($w<= $image_x)?$w:$image_x;
$hs= ($h<= $image_y)?$h:$image_y;
   if ($image_x < $image_y) {
      $ws = ($hs / $image_y) * $image_x;
   }else {
        $hs = ($ws / $image_x) * $image_y;
   }
   
   #$img  = imagecreatefromjpeg($origimage);
   $img  = imagecreatefrompng($origimage);
   $src = imagecreatetruecolor($ws,$hs);
      
   imagecopyresampled($src,$img,0,0,0,0,$ws,$hs,$image_x,$image_y);
   #imagejpeg($src,'design1-s.jpg');
   imagepng($src,'design1-s.png');
   imagedestroy($src);

?>
Aredon
I took a screenshot of my desktop and saved it as img1.png and img1.jpg.
I placed both images on my desktop and ran the follow PHP file from my desktop:
Code:

<?php

$origimage = 'img1.jpg';
$w="100";
$h="500";
//$ratio=5;
$thumbheight = $image_y * $ratio;

list($image_x,$image_y) = getimagesize($origimage);
$ws= ($w<= $image_x)?$w:$image_x;
$hs= ($h<= $image_y)?$h:$image_y;
   if ($image_x < $image_y) {
      $ws = ($hs / $image_y) * $image_x;
   }else {
        $hs = ($ws / $image_x) * $image_y;
   }
   
   $img  = imagecreatefromjpeg($origimage);
   #$img  = imagecreatefrompng($origimage);
   $src = imagecreatetruecolor($ws,$hs);
     
   imagecopyresampled($src,$img,0,0,0,0,$ws,$hs,$image_x,$image_y);
   imagejpeg($src,'design1-s.jpg');
   #imagepng($src,'design1-s.png');
   imagedestroy($src);

?>

and I found the thumbnail design1-s.jpg on my desktop.
Then I ran:
Code:

<?php

$origimage = 'img1.png';
$w="100";
$h="500";
//$ratio=5;
$thumbheight = $image_y * $ratio;

list($image_x,$image_y) = getimagesize($origimage);
$ws= ($w<= $image_x)?$w:$image_x;
$hs= ($h<= $image_y)?$h:$image_y;
   if ($image_x < $image_y) {
      $ws = ($hs / $image_y) * $image_x;
   }else {
        $hs = ($ws / $image_x) * $image_y;
   }
   
   #$img  = imagecreatefromjpeg($origimage);
   $img  = imagecreatefrompng($origimage);
   $src = imagecreatetruecolor($ws,$hs);
     
   imagecopyresampled($src,$img,0,0,0,0,$ws,$hs,$image_x,$image_y);
   #imagejpeg($src,'design1-s.jpg');
   imagepng($src,'design1-s.png');
   imagedestroy($src);

?>

and I found the thumbnail design1-s.jpg on my desktop.
I tried double clicking both thumbnails and they both worked.
Related topics
GD-library header probs
751 Useful Windows XP Files
PHP image
fdas
Image Display Problem
Picture resizing software :?:
Uploading and resizing an image
Create,Resize,Thumb, Shadow of your Images
[PHP] Problem with Dynamic Sig's Font Color
Image posting problem
what is the problem with this script
PHP imagecreate + CSS problem.
PHP imagecreate + CSS problem.
header already sent? (and now introducing a mysql problem)
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.