PHP Picture Resize Limit?

Ok, I have the following code to take an image from a blob and resize the image, then it passes the image to the parent file as an HTML image.
This works great because if I have a file like 1MB it changes the file you see to smaller like 300k. And it doesn't slow the browsers down by sending too much data.

The problem is, I got a routine working that will allow me to save large files, up to 20MB if I wanted to. But when I try to Retrieve the picture that is over 1.5MB and make it say... 200px wide, it displays nothing. But if I retrieve the raw picture in an HTML image it displays fine, it's huge, but it's fine.

This solution seems to be the standard one for resizing pics. Is there a size limit to some of the functions? I really need it to display what I give it because the Customer isn't very computer savy, and would get confused resizing pics.


<?php
            // Connect to server and select database
            $conn2 = mysql_connect("localhost", "user", "password");
            mysql_select_db("database", $conn2) or die(mysql_error());
            
            $query2 = mysql_query("SELECT * FROM `main_page_info`");
            
$pic = $_GET[imagename];
$row = mysql_fetch_array($query2);
$content = $row[$pic];

// Print Picture
$im = imagecreatefromstring($content);
$x = imagesx($im);
$y = imagesy($im);

if( $_GET[pwidth] == "F")
{
      $desired_width = $x;
}
else
{
      $desired_width = $_GET[pwidth];
}
$desired_height = $y/($x/$desired_width);

$new = imagecreatetruecolor($desired_width, $desired_height);
imagecopyresampled($new, $im, 0, 0, 0, 0, $desired_width, $desired_height, $x, $y);

header('Content-type: <span class="posthilit">image</span>/jpeg');
imagejpeg($new, null, 75);

imagedestroy($im);
exit;
?>
StarThunderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
You may be exceeding the size appropriate for retrieval from the data base.  I recommend that you change the process so that you store images in the file system instead of the data base.

Here is a teaching example of how to create a thumbnail from a larger image.  See if it gives you any good ideas.

<?php // RAY_image_thumbnail.php
error_reporting(E_ALL);


// RESIZE AN IMAGE TO FIT INSIDE A DEFINED TRANSPARENT SPACE
// USE CASE: <img src="RAY_image_thumbnail.php?img=RAY_image_thumbnail.jpg&w=150&h=100" />


// ACQUIRE THE ARGUMENTS - MAY NEED SOME SANITY TESTS?
$thumb_w   = $_GET["w"];
$thumb_h   = $_GET["h"];
$image_url = $_GET["img"];

// CREATE THE THUMBNAIL IMAGE RESOURCE AND FILL IN TRANSPARENT
$thumb = imagecreatetruecolor($thumb_w, $thumb_h);
imagesavealpha($thumb, TRUE);
$empty = imagecolorallocatealpha($thumb,0x00,0x00,0x00,127);
imagefill($thumb, 0, 0, $empty);

// GET ORIGINAL IMAGE DIMENSIONS
$array = getimagesize($image_url);
if ($array)
{
    list($image_w, $image_h) = $array;
}
else
{
    trigger_error("NO IMAGE $image_url", E_USER_ERROR);
}

// ACQUIRE THE ORIGINAL IMAGE
$image_ext = trim(strtoupper(end(explode('.', $image_url))));
switch(strtoupper($image_ext))
{
    case 'JPG' :
    case 'JPEG' :
        $image = imagecreatefromjpeg($image_url);
        break;

    case 'PNG' :
        $image = imagecreatefrompng($image_url);
        break;

    default : trigger_error("UNKNOWN IMAGE TYPE: $image_url", E_USER_ERROR);
}

// GET THE LESSER OF THE RATIO OF THUMBNAIL H OR W DIMENSIONS
$ratio_w = ($thumb_w / $image_w);
$ratio_h = ($thumb_h / $image_h);
$ratio   = ($ratio_w < $ratio_h) ? $ratio_w : $ratio_h;

// COMPUTE THUMBNAIL IMAGE DIMENSIONS
$thumb_w_resize = $image_w * $ratio;
$thumb_h_resize = $image_h * $ratio;

// COMPUTE THUMBNAIL IMAGE CENTERING OFFSETS
$thumb_w_offset = ($thumb_w - $thumb_w_resize) / 2.0;
$thumb_h_offset = ($thumb_h - $thumb_h_resize) / 2.0;

// COPY THE IMAGE TO THE CENTER OF THE THUMBNAIL
imagecopyresampled
( $thumb
, $image
, $thumb_w_offset
, $thumb_h_offset
, 0
, 0
, $thumb_w_resize
, $thumb_h_resize
, $image_w
, $image_h
)
;

// SHOW THE NEW THUMB IMAGE
header('Content-type: image/png');
imagepng($thumb);

// RELEASE THE MEMORY USED BY THE RESOURCES
imagedestroy($thumb);
imagedestroy($image);

Open in new window

HTH, ~Ray
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
When you don't engage in any dialog and mark a grade down, it requires an explanation.  Please explain.
http://support.experts-exchange.com/customer/portal/articles/481419
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.