Page 1 of 1

Image Problem

Posted: Wed Jun 23, 2004 10:27 am
by leebo
Hi

Can anyone tell me what is wrong with this code ? It used to work fine but my server has uploaded a newer version of php and it when the image resizes it loses most of its colour as though is was from 32bit to 6 colours ??

Code: Select all

<?php

#copy the original image to images/

if(!(copy($_FILES['strFile']['tmp_name'], "../images/" . $_FILES['strFile']['name'])));
session_register("nameimage1");
session_save_path();
$IMG_WIDTH = "250";
$IMG_HEIGHT = "120";

$IMG_ROOT = "../images";

$fileName = explode(".", $_FILES['strFile']['name']);
$name = str_replace(' ', '_', $fileName[0]);

error_reporting(53);
$acceptedTypes = array('image/jpeg', 'image/jpg', 'image/pjpeg');

if(!in_array($_FILES['strFile']['type'], $acceptedTypes) || trim($_FILES['strFile']['tmp_name']) == "" || trim($_FILES['strFile']['tmp_name']) =="none")
{

}
else
{
$img_orig_size = getimagesize($_FILES['strFile']['tmp_name']);
$img_orig_width = $img_orig_size[0];
$img_orig_height = $img_orig_size[1];
$img_original = ImageCreateFromJpeg($_FILES['strFile']['tmp_name']);
$image_stored = $ref. "_main.jpg";
ImageJPEG($img_original, "$IMG_ROOT/$image_stored");
$mlt_w = $IMG_WIDTH / $img_orig_width;
$mlt_h = $IMG_HEIGHT / $img_orig_height;
$mlt = $mlt_w < $mlt_h ? $mlt_w:$mlt_h;

#### Calculate new dimensions
$img_new_width = round($img_orig_width * $mlt);
$img_new_height = round($img_orig_height * $mlt);
$img_resized = ImageCreate($img_new_width, $img_new_height);

imagecopyresized($img_resized, ImageCreateFromJpeg($_FILES['strFile']['tmp_name']), 0 , 0 , 0 , 0, $img_new_width, $img_new_height, $img_orig_width, $img_orig_height);
$img_name = "$image_stored";

Imagejpeg($img_resized, "$IMG_ROOT/$img_name");

ImageDestroy($img_resized);

$mg_new_size = filesize("$IMG_ROOT/$img_name");

        $newimage1 = "<img border= '1' src='$IMG_ROOT/$img_name'>";
        $nameimage1 =  str_replace('./', '', $image_stored);

}

?>
?>

Posted: Wed Jun 23, 2004 10:51 am
by redmonkey
GD FAQs wrote: Q. Why do my JPEG thumbnails have missing colors with gd 2.0.x?

A. When creating truecolor images, you need to call gdImageCreateTrueColor, not gdImageCreate. This used to "work" in gd 1.x, but only in the sense that gd 1.x had no support for real truecolor at all, so it faked it by dithering your image. gd 2.x supports real truecolor, and also has a better way of reducing to palette color when you really want to do that; see the gdImageTrueColorToPalette function -- but you don't need it for this job. PHP and Perl programmers: the function names for you are similar, just leave off the gd prefix.
FAQs are here