Resizing images with PHP - loss of quality?

Hi, I'm using this code to resize images in 'main' directory and place them in 'tumb' directoy:

$new_w = 200;
$cfg_fullsizepics_path = "main";
$cfg_thumb_path = "thumb";
$filepath = "main";
$dir = dir($filepath);
while($entry=$dir->read()) {
    if($entry == "." || $entry == "..") {
    $fp = @fopen("$filepath/$entry","r");
 $photo_filename = "$entry";
$image_stats = GetImageSize($cfg_fullsizepics_path."/".$entry);
$imagewidth = $image_stats[0];
$imageheight = $image_stats[1];
$img_type = $image_stats[2];
$ratio = ($imagewidth / $new_w);
$new_h = round($imageheight / $ratio);
if (!file_exists($cfg_thumb_path."/".$entry))  {
 if ($img_type=="2") {
 $src_img = imagecreatefromjpeg($cfg_fullsizepics_path."/".$entry);
 $dst_img = imagecreate($new_w,$new_h);
imagejpeg($dst_img, "$cfg_thumb_path"."/$entry");
 } elseif  ($img_type=="3") {
 Imagepng($dst_img, "$cfg_thumb_path"."/$entry");
 } elseif  ($img_type=="1") {
  echo "$entry";
  echo "

It works well, BUT the images that are resized come out with what looks like 256 colours with a blue tint. Can anyone tell me how to resize images but preserver the colour quality in php?

BTW, I can't use GD library as i don't have permissions to install it :(
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

change imagecreate() into imagecreatetruecolor()

See also:
> We recommend the use of imagecreatetruecolor().



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>BTW, I can't use GD library as i don't have permissions to install it :(

You ARE using GD lib, aren't you? Even imagecreate is a GD function. to my knowledge at least.


spikeyjamesAuthor Commented:
Thanks very much!!!
Such a simple solution! sigh.

I'm not sure if i'm using GD lib?...maybe my hosts have it installed after do I check?
php_info (or was it phpinfo()?)

At least, one of the two shows info on what modules are installed at your server.

<?php phpinfo(); ?>


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.