Where to begin...

To make a long story short I've written a script for a client that does an image resize and thumbnail operation. This works on my localhost, but not on the actual server. I've traced the problem to the imagecreatefromjpeg() function. The image path is an URL, and from what I have read in the PHP manual you need to use fopen() first. I really don't know how to go about this. I did the following:

$handle = fopen($img_path, "r");
$img_content = fread($handle, filesize($img_path));
fclose($handle);

$im = imagecreatefromjpeg($img_content);

if(!$im){
print "Image not created";
}

When I run the script I get my error message. First I'd love for someone to point out if I am approaching this wrong, and second, are there any PHP settings that would affect this function? I'd been able to view the phpinfo of the server I'm working on before, but now all I get is a blank page with no info... Can a host shut off access to phpinfo? Quite frustrating.

Much appreciated,
Jamie

    Most likely they aren't allowing fopen with urls, to check this do an ini get of allow_url_fopen and see if it's set.

    You can pass the url straight into imagecreatefrom jpeg, according to the manual.

    Also I would do fopen($img_path, "rb") just out of habit to ensure it's doing a binary open.

      when the manual says fopen wrappers, it doesnt mean you have to use fopen, if your fopen supports http or ftp protocols (among others) it will use these wrappers to fetch the image...

      $im = imagecreatefromjpeg("http://www.site.com/image.jpg");
      

      that is sufficient to load the image located at that url into a gd resource.

        Hi Drakla.

        Ini set and ini get are both disabled. This server has everything disabled for 'security reasons'. I have never worked with such a useless server in all my life. I've exhausted all possible options to get this to work, but it's just not possible. :-\

        I appreciate the help, however! Thanks much for your time.

          Drew, that is precisely what I did to begin with, but $im comes up empty.

          $im = imagecreatefromjpeg($img_path);

          if (!$im){
          print "Image not created";
          }

          When running this script I get the error. I see absolutely no reason why. GD is current and enabled.

            If you're not too attached to your solution for generating thumbnails on the fly, you may want to look at:

            http://us2.php.net/manual/en/function.imagecopyresampled.php

            I've used one of the user-contributed comments listed for that function and I was better pleased with:

            1. the quality of the image (over imagecreatefromjpeg()).

            2. the ease of using it, since the user/contributor has done a good job with his example. Unfortunately, I can't remember from which contributor I finally used, but experiment with a few of the postings.

              if gd is current, then the problem must be the opening of remote files. it seems to me if the host disables phpinfo (which is possible, php gives options to disable any functions) then they probably dont provide a lot of functionality. best you can do at this point is email them and bug them to death about all the different ini settings and see if they'll either turn a few on for your or at least let you know what is available. i suppose you can tell them things like "what is the point of having php if half the features are disabled..." and see what they do. you may just need to move on to a new host if they dont help with it.

                I agree completely.

                Thanks for the help Drew!

                  Write a Reply...