zero-perfoliate
zero-perfoliate

Author Topic: [SOLVED] Problem with imagecreatefromjpeg()  (Read 424 times)

Offline Mattachoo

  • New PHP Members
  • Posts: 4
  • Karma: +0/-0
[SOLVED] Problem with imagecreatefromjpeg()
« on: February 20, 2009, 10:45:02 AM »
Hello there!  I have a problem here that is bugging the hell out of me and was wondering if anyone could give me some insight.  I will try to explain my problem in the greatest amount of detail that I can. 

I have written a script for a client that allows him to "add new products" to his webpage.  In this form, the user can select a hi-res picture of the product for upload.  Upon upload, my script takes this image and makes two copies of the image; one of width 50px, and one of width 183px, for thumbnail purposes. 

The client contacted me for this project before owning webspace himself.  So, while I was writing the code, I tested it on my own site.  I finished writing all the code, and everything worked fine on my end.  Now he has bought the webspace, and I have started transferring all the files over to his site so we can get this thing up and running.  This is where the problem comes in.

After I transferred the scripts and such over to his site, the image resizing script stopped working.  I was able to traack down where my script was failing, and it happens when I try and invoke a imagecreatefromjpeg() function.  I have tried contacting the tech support people for the website, but they have been useless to me.  Here is the snippet of my code:

Code: [Select]
<?php

$shit 
"http://www.theguyswebsite.com/images/products/";
// The file
$filename $_POST['fname'];

$path_parts pathinfo($filename);

$imageWithExt $path_parts['basename'];
$extension $path_parts['extension'];
$imageWithoutExt basename($imageWithExt".".$extension);
//echo "with ".$imageWithExt." without ".$imageWithoutExt."<br>";

list(
$width2$height2$type2$attr2) = getimagesize($filename);
//echo "<h4>width ".$width2." height ".$height2." type ".$type2." attr ".$attr2."</h4>";

//do the second thumbnail
$width_2 183;
$num183 183/$width2;
$height_2 $height2*$num183;
//working

// Resample

$image_p2 imagecreatetruecolor($width_2$height_2);

////////////////////////////////////////////////////////
//CODE FAILS HERE!!!  DAMNIT!
$image4 imagecreatefromjpeg($filename);
////////////////////////////////////////////

imagecopyresampled($image_p2$image40000$width_2$height_2$width2$height2);

// Output
ob_start();
imagejpeg($image_p2null100);
$thefile2 ob_get_contents();
ob_end_clean();

//the thumbnail name will be the 
//same, only it will have a "_thumb2" added to 
//the end of its filename
$newname2 $imageWithoutExt.'_thumb2';

$destination2 'images/products/'.$newname2.'.jpg';

if (!
$handle2 fopen($destination2'w')) {
echo 'Cannot Open (' $destination2 ')';
} else {
if (fwrite($handle2$thefile2) === FALSE) {
echo 'Cannot write to file (' $destination2 ')';
} else {
echo 'Thumbnail 2 was sucessfully saved!';
}
fclose($handle2);
fclose($handle);
}

?>



I know my code is sloppy, and my variable names are a bit weird, but this code works I tell ya!  Oh, and I switched out the real website name with theguyswebsite.com, so don't mind that.   

I know for a fact that this code works.  The problem does not lie there.  If this snippet won't work, that is because it is a snippet, and not the complete file.  The problem doesn't lie with my code, is has to do with the web host. 

So, my question for you guys is, what could possible make the function imagecreatefromjpeg() fail?  I have a hunch there is some funny business going on in my php.ini file that is causing this problem, but I haven't the slightest idea what it actually is.  I also know this isn't a function that the web host blocks because my website, (the one where this code executes just fine and does what it is supposed to do), yeah, my website is hosted through the same company. 

If anyone has any information on this or could give me any insight to where to look to see where the problem in (by looking at the information by doing a phpinfo() maybe?) I would greatly appreciate it.  I just can't figure this one out.  Sorry for the long post, but I didn't want to leave anything out.  Again, thank you very much in advance if you help me out!

I almost forgot, I also got this error message one time:
Code: [Select]
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 5760 bytes) in /usr/local/psa/home/*******/addproduct.php on line 218"
Thanks again!

-Matt
« Last Edit: February 20, 2009, 12:01:57 PM by Mattachoo »

Offline PhPHelper

  • http://Digiscapers.com
  • Full Member
  • PHP Problem Solvers
  • ****
  • Posts: 179
  • Karma: +50/-0
    • Bad Apple Mail
Re: Problem with imagecreatefromjpeg()
« Reply #1 on: February 20, 2009, 10:58:58 AM »
to increase the memory limit put this in your file

Code: [Select]
ini_set("memory_limit","10M");
It increases the memory limit to 12 mb increase as needed or to make it a default put

Code: [Select]
memory_limit = 12M
in a php.ini file.

Offline Mattachoo

  • New PHP Members
  • Posts: 4
  • Karma: +0/-0
Re: Problem with imagecreatefromjpeg()
« Reply #2 on: February 20, 2009, 12:01:14 PM »
fml, that was the problem.  I had this happen to me before with a completely different website; you'd think I would have thought of that. 

The memory_limit on the site that was working was set to 16M while to one on the site where it wasn't working was set to 8MB.  I set it to 16 and it worked fine.  Thank you VERY much for you help.  Man!  I still can't believe I didn't think to try that.  You have no idea how long I've been trying to fix this.  Thanks again!

Offline PhPHelper

  • http://Digiscapers.com
  • Full Member
  • PHP Problem Solvers
  • ****
  • Posts: 179
  • Karma: +50/-0
    • Bad Apple Mail
Re: [SOLVED] Problem with imagecreatefromjpeg()
« Reply #3 on: February 20, 2009, 01:09:37 PM »
your very welcome we don't always think of the obvious things its our nature lol

 

zero-perfoliate