Solved

PHP SERVER converting png image

Posted on 2012-04-04
7
514 Views
Last Modified: 2012-04-05
I have a problem with the imagecreatefrompng in my server i mean, the code works fine in my local server but when i upload it to my host i have a problem, i´ll explain, my code is:
###############################
if($type == "image/png") {
                                                      $path_img = "$caminho";
                                                      $path_img_png = "$caminho";
                                                      $im = @imagecreatefrompng($path_img);
                                                      $imagem_white = imagecreatetruecolor($width,$height);
                                                      $black = imagecolorallocate($imagem_white, 0, 0, 0);
                                                      $red = imagecolorallocate($imagem_white, 255, 255, 255);
                                                      imagecolortransparent($imagem_white, $black);
                                                      imagefilledrectangle($imagem_white, 0, 0, $width, $height, $red);
                                                      $quality = 99;
                                                      $path_img_jpg = $path_img.".jpg";
                                                      imagecopyresampled($imagem_white, $im, 0, 0, 0, 0, $width, $height, $width, $height);
                                                      imagejpeg($imagem_white, $path_img_jpg, $quality);
                                                      mysql_query("UPDATE imagem set caminho = '$path_img_jpg' WHERE caminho = '$path_img' AND dia = '$dia' AND mes = '$mes' AND ano = '$ano'");
                                                      imagedestroy($im);
                                                      imagedestroy($imagem_white);
                                                      $imagem = imagecreatetruecolor($newwidth,$newheight);
                                                      $path_img = $path_img_jpg;
                                                      $imagem_orig = imagecreatefromjpeg($path_img);
                                                      imagecopyresampled($imagem, $imagem_orig, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
                                                      imagejpeg($imagem, $path_img, 60);
                                                      unlink($path_img_png);
                                                      
                                                }
###############################

I work fine with jpg images, but i think the problem is because when php create the png image it puts in bitmap and then if the size is to high it breaks, i really don´t know why because if the image size and when i talk in size i say width and height, if size is smaller it works fine. And i have already put the memory_limit to 2048M in php.ini so it can convert the bitmap size image without any problem. I think the problem is not im my code because it works fine in local server, i think the problem is somewhere in php.ini. Please someone help me.
0
Comment
Question by:pep477
  • 3
  • 2
  • 2
7 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37809734
does the browser (request) upload the image data?
if so, do you get the complete data in your script?
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 37809756
Start by removing the @ from the function calls and setting error_reporting(E_ALL) so you can see if the script is relying on undefined variables.  Try testing the return values from the PHP functions to see if the functions actually worked.  Almost every line of code above seems to assume that the function calls worked, and that is not a very good assumption.  You can use var_dump() to print out the return values from PHP functions.

You might also want to tell us who your host is?  Is Suhosin in play?  Is safe mode on?  These things can play havoc with simple stuff like writing a file.

If you want to step back from the technical details and tell us in plain language what you're trying to achieve, we may be able to offer a good design pattern.  Just a thought...
0
 

Author Comment

by:pep477
ID: 37811179
The data is going through fine, for example if i upload a image with 5000x3000 it goes fine and convert the image to jpg just fine, but if i upload a 8000x5000 image then it does not work, i asked arround and tryed to see error removing the @ but nothing and most of the people told me that may be a problem with the gd of the server because i am in a shared server, if that´s the case i don´t have access to some server configuration because like i said it´s a shared server, but i am willing  to change my host, not for no but in a few time if you could tell me some good cloud servers that was not much expensive but good, i mean if that is the problem. Some people told me about http://www.vps.net but i do not know then.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 37811609
# you have to check apache configuration:
LimitRequestBody

# and php.ini configuration:
upload_max_filesize =
post_max_size =

# the smallest value will be your upload size
0
 

Author Comment

by:pep477
ID: 37811630
I have checked and it is larger then necessary, the problem is not the file size because when converting jpg image that has 8000x4000 or more it works fine, the problem is just with png, and that´s why i think the problem it´s on the gd
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37811852
Amazon AWS is well respected.

To find out about GD, run this script, shown here in its entirety: <?php phpinfo(); and look in the output for "GD" about halfway down the page.  You would want to find these settings:

GD Support       enabled
GD Version       bundled (2.0.34 compatible)
PNG Support       enabled
libPNG Version       1.2.10

A JPG image is typically a smaller file size than an equivalent PNG image.  JPG compression is "lossy" meaning that it discards image information, whereas PNG does not discard information.

Have you been able to determine with certainty whether the issue is the file upload or the code you posted with the original question?
0
 

Author Comment

by:pep477
ID: 37811868
I was able to determine that the problem is with the gd library.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a previous article here at Experts Exchange (http://www.experts-exchange.com/articles/18414/Create-a-PDF-file-with-Contact-Sheets-montage-of-thumbnails-for-all-JPG-files-in-a-folder-and-each-of-its-subfolders-using-an-automated-batch-method.html)…
This article shows how to convert a multi-page PDF file into multiple image files, with one image file created for each page of the PDF. It does this by utilizing an excellent, free software package called GraphicsMagick. The solution is amazingly s…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question