Solved

PHP SERVER converting png image

Posted on 2012-04-04
7
515 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powershell md/mkdir/New-item   -Quiet 10 245
Powershell File Sort 8 45
Perl script to process a .csv file 18 66
storing csv file in table variable in Python 2 67
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)…
Adults who share images on social media aren’t the only ones who need to worry about their privacy. Our culture’s tendency to share every move and celebration affects the privacy of our children, too.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

730 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