Solved

PHP SERVER converting png image

Posted on 2012-04-04
7
519 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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 110

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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 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