Solved

PHP SERVER converting png image

Posted on 2012-04-04
7
512 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 108

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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 108

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now