[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 527
  • Last Modified:

PHP SERVER converting png image

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
pep477
Asked:
pep477
  • 3
  • 2
  • 2
1 Solution
 
ahoffmannCommented:
does the browser (request) upload the image data?
if so, do you get the complete data in your script?
0
 
Ray PaseurCommented:
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
 
pep477Author Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
ahoffmannCommented:
# 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
 
pep477Author Commented:
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
 
Ray PaseurCommented:
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
 
pep477Author Commented:
I was able to determine that the problem is with the gd library.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now