xenia Posted June 13, 2006 Share Posted June 13, 2006 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 imagecopy($_FILES['image']['tmp_name'],"../enlarge_". $_FILES['image']['name']);?><? //make the image largeecho $_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 smallecho $_POST['txt'];$uploadedfile = $_FILES['image']['tmp_name'];$src = imagecreatefromjpeg($uploadedfile);list($width,$height)=getimagesize($uploadedfile);$newwidth=36;$newheight=40;$tmp=imagecreatetruecolor($newwidth,$newheight);//smallimagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);//small$filename = "../small_". $_FILES['image']['name'];//smallimagejpeg($tmp,$filename,100);//smallimagedestroy($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 Quote Link to comment https://forums.phpfreaks.com/topic/11866-images-displayed-black/ Share on other sites More sharing options...
nogray Posted June 13, 2006 Share Posted June 13, 2006 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 Link to comment https://forums.phpfreaks.com/topic/11866-images-displayed-black/#findComment-45116 Share on other sites More sharing options...
xenia Posted June 16, 2006 Author Share Posted June 16, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/11866-images-displayed-black/#findComment-46201 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.