Forum Moderators: coopster

Message Too Old, No Replies

Problem with resizing images.

Please HELP

         

gamesnik

12:34 am on Jul 14, 2005 (gmt 0)

10+ Year Member



I'm learning how to resize JPG image using PHP.
Actaly it's resized but the image lost it's colors.

I know that this is lame code, but I'm just trying to learn it.

Please coul'd you tell me, how to improve quality of resized images? Thanks a lot.

Here is the code

<html>

<head>
<title></title>
</head>

<body>

<?

$img_info = getimagesize("1.jpg");

$src_width = $img_info[0];
$src_height = $img_info;

echo $src_width;
echo $src_height;

if (!function_exists('imagecreatefromjpeg')) {
echo "<br>fce doesn't exist :(";
}else{
echo "<br>fce exists :)<br>";
};

$dst_width = $src_width / 2;
$dst_height = $src_height / 2;

$src_img = imagecreatefromjpeg("1.jpg");
$dst_img = imagecreate($dst_width, $dst_height);
imagecopyresized( $dst_img, $src_img, 0, 0, 0, 0,$dst_width, $dst_height,"686","520");
imagejpeg($dst_img, "2.jpg", 100);

$img_info2 = getimagesize("2.jpg");
echo $img_info2[0]." x ";
echo $img_info2[1];
?>
<br>
<img src="1.jpg">
<br>
<img src="2.jpg">

</body>

</html>

[1][edited by: jatar_k at 1:21 am (utc) on July 14, 2005]
[edit reason] no personal urls thanks [/edit]

jatar_k

1:25 am on Jul 14, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld gamesnik,

what about trying imagecreatetruecolor instead of imagecreate?

not sure if that is the right track but it might work off the top of my head.

you could take a look at this from our PHP library [webmasterworld.com]

Image upload and Thumbnail Generator [webmasterworld.com] message 29

might give you some ideas

gamesnik

10:00 am on Jul 14, 2005 (gmt 0)

10+ Year Member



jatar_K : Super...it works. Thanks a lot.