Jump to content

Images displayed black


xenia

Recommended Posts

Hello everyone,

I have a very strange problem with uploading and resizing images.
I have developed an e-commerce website that the customers can buy online cloths.I have also created an administrator panel for the admin to insert items in the database uploading also their image. The image of the item will be displayed in three different sizes in the e-commerce site, the enlarge,large and small. The image that the user uploads has the dimension width:310 and from that width I use to make the dimensions of the large and small image.

The code that I am using to upload the image is the following:

[code=php:0]
<? //copy the image to the server named enlarge_name of image

copy($_FILES['image']['tmp_name'],"../enlarge_". $_FILES['image']['name']);

?>

<? //make the image large
echo $_POST['txt'];

$uploadedfile = $_FILES['image']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
list($width,$height)=getimagesize($uploadedfile);
$newwidth=$width * 0.35 ;
$newheight=$height * 0.35;


$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$filename = "../large_". $_FILES['image']['name'];
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp);

?>


<? //make the image small

echo $_POST['txt'];
$uploadedfile = $_FILES['image']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
list($width,$height)=getimagesize($uploadedfile);
$newwidth=36;
$newheight=40;


$tmp=imagecreatetruecolor($newwidth,$newheight);//small
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);//small
$filename = "../small_". $_FILES['image']['name'];//small
imagejpeg($tmp,$filename,100);//small

imagedestroy($src);
imagedestroy($tmp);
?>
[/code]
The problem I get is that in some images that I upload it displays a black square instead of the image.
The strange thing is that some times the same image might display it and the next time it will not.
As I can understand it uploads them in the server but cannot display them correctly.

I have search everywhere and I did a lot of testing to find the problem but I haven't yet ,so I would be very greatful if you could help me.

Thank you ,
Xenia
Link to comment
Share on other sites

[!--quoteo(post=383365:date=Jun 13 2006, 12:07 PM:name=nogray)--][div class=\'quotetop\']QUOTE(nogray @ Jun 13 2006, 12:07 PM) [snapback]383365[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You are most likely uploading gif images, and using the imagecreatefromjpeg() function. You'll need to check if the image is jpg or gif and use the appropriate function.
[/quote]

Thanks nogray but I found the error,as I increased the maximun size of the uploded and not it is working.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.