• PHP Help General Help
  • [RESOLVED] Call to undefined function: imagecreatefromjpeg() But gd is enabled in php set up!

gd
GD Support enabled

GD Version bundled (2.0.22 compatible)

GIF Read Support enabled

PNG Support enabled

WBMP Support enabled

XBM Support enabled

The above is my php set up.

But when I run this function

<?php

$image_path=$_SERVER['DOCUMENT_ROOT']."/SITEADMIN/z_test/";
$image_name="test.jpg";
$thumb_path=$image_path;
$thumb_width=120;

function thumbnail($image_path,$thumb_path,$image_name,$thumb_width)
{
$src_img = imagecreatefromjpeg("$image_path/$image_name");
$origw=imagesx($src_img);
$origh=imagesy($src_img);
$new_w = $thumb_width;
$diff=$origw/$new_w;
$new_h=$new_w;
$dst_img = imagecreate($new_w,$new_h);
imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));

imagejpeg($dst_img, "$thumb_path"."/t-"."$image_name"); 
//imagejpeg($dst_img, "$thumb_path/thumbnail.jpg");
return true; 

}

thumbnail($image_path,$thumb_path,$image_name,$thumb_width);

?>

I got the error

Call to undefined function: imagecreatefromjpeg() ?

What else set up I should do?

Thanks

    Try
    imagecreatefrompng

    I know that works, I haven't tried the jpg function yet.

    You'll have to make a .png file though

      my php is 4.3.6

      './configure' '--prefix=/usr/local/php' '--with-mysql' '--enable-sapi=cli' '--with-apxs2=/usr/local/httpd/bin/apxs' '--with-curl' '--with-xml' '--enable-wddx' '--with-pgsql=/usr/local/postgres' '--with-openssl' '--with-interbase=/usr/local/firebird' '--enable-sockets' '--with-png' '--with-gd' '--with-zlib-dir=/usr/include'

      So do I have to install jpeg library and configure '--with-jpeg'

      How about gif?

      Due to install and configure is a little bit tricky. If it is possible, could you also give the steps of install and configure te jpeg library to php.

      Thanks!

      Also, do most hosting companies configure their server to support these functions, such as with jpeg library and support imagecreatefromjpeg() ? I want to write some codes that my clients can easily find the hosting services.

        serain wrote:

        How about gif?

        Previously:

        serain wrote:

        GIF Read Support enabled

          7 days later

          Now my server is updated like this

          './configure' '--prefix=/usr/local/php' '--with-mysql' '--enable-sapi=cli' '--with-apxs2=/usr/local/httpd/bin/apxs' '--with-curl' '--with-xml' '--enable-wddx' '--with-pgsql=/usr/local/postgres' '--with-openssl' '--with-interbase=/usr/local/firebird' '--enable-sockets' '--with-png' '--with-gd' '--with-zlib-dir=/usr/include' '--with-jpeg' '--with-gif' '--with-jpeg-dir=/usr/local/lib/'

          gd
          GD Support enabled

          GD Version bundled (2.0.28 compatible)

          GIF Read Support enabled

          GIF Create Support enabled

          JPG Support enabled

          PNG Support enabled

          WBMP Support enabled

          XBM Support enabled

          The Image creation and manipulation for gif, png are fine. But for jpg, the thumbnail I get is a dark broken image.

          But no php errors shows.

          Anything else I need to do to solve this problem?

          Thanks!

            This maybe the stupidest thing I have suggested but instead of naming it test.jpg
            Name it test.jpeg

            Maybe something as stupid as that will work.

              6 days later

              './configure' '--prefix=/usr/local/php' '--with-mysql' '--enable-sapi=cli' '--with-apxs2=/usr/local/httpd/bin/apxs' '--with-curl' '--with-xml' '--enable-wddx' '--with-pgsql=/usr/local/postgres' '--with-openssl' '--with-interbase=/usr/local/firebird' '--enable-sockets' '--with-png' '--with-gd' '--with-zlib-dir=/usr/include' '--with-jpeg' '--with-gif' '--with-jpeg-dir=/usr/local/lib/'

              gd
              GD Support enabled
              GD Version bundled (2.0.28 compatible)
              GIF Read Support enabled
              GIF Create Support enabled
              JPG Support enabled
              PNG Support enabled
              WBMP Support enabled
              XBM Support enabled

              '--with-jpeg' '--with-gif' '--with-jpeg-dir=/usr/local/lib/'

              is this config right? I can work on png, gif, but I got broken image on jpg. Cannot figure out why, help please!

              Could it be because the jpeg-6b [url]ftp://ftp.uu.net/graphics/jpeg/[/url] is not installed?

                Note about English usage: If you ask "is it because jpeglib isn't installed?" you're saying that jpeglib isn't installed and you're asking if that's the problem.

                Since GDLib wouldn't have compiled without it, and phpinfo is saying that jpeg support is enabled, then jpeglib probably is installed and your question is spurious.

                So you get a broken image. Have you looked at the contents of that broken image file to see if there's anything like an error message in there?

                  It is just a black square. Nothing else.

                    So it's a valid JPEG image. It's not a broken image because you aren't getting a broken image icon (I may be wrong about that which is why I asked what the contents of the image file were. The contents of the file is not a black image, it's a sequence of bytes and I wanted to know if the sequence of bytes had any clues.)

                    Assuming that it is a JPEG image (like, have you tried saving it and viewing it in an image viewer? Have you tried looking at it in a hex viewer to see what the file contained?): the problem is with how you're generating the image, and nothing to do with stuff like whether GD Lib is installed or whether jpeg support is enabled or stuff like that.

                    Since this is a different problem from the one you started out with, it would be nice to know what if anything has changed in your code.

                    http://catb.org/~esr/faqs/smart-questions.html
                    Describe the problem's symptoms, not your guesses
                    It's not useful to tell hackers what you think is causing your problem. (If your diagnostic theories were such hot stuff, would you be consulting others for help?) So, make sure you're telling them the raw symptoms of what goes wrong, rather than your interpretations and theories. Let them do the interpretation and diagnosis. If you feel it's important to state your guess, clearly label it as such and describe why that answer isn't working for you.

                      Thanks. I re-tested it.

                      OK, first of all. There is a small bug in the original script.

                      <?php

                      $image_path=$_SERVER['DOCUMENT_ROOT']."/SITEADMIN/z_test/";
                      $image_name="test.jpg";
                      $thumb_path=$image_path;
                      $thumb_width=120;

                      function thumbnail($image_path,$thumb_path,$image_name,$thumb_width)
                      {
                      $src_img = imagecreatefromjpeg("$image_path/$image_name");
                      $origw=imagesx($src_img);
                      $origh=imagesy($src_img);
                      $new_w = $thumb_width;
                      $diff=$origw/$new_w;
                      $new_h=$new_w;

                      $dst_img = imagecreate($new_w,$new_h);
                      imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));

                      imagejpeg($dst_img, "$thumb_path"."/t-"."$image_name");
                      //imagejpeg($dst_img, "$thumb_path/thumbnail.jpg");
                      return true;
                      }

                      thumbnail($image_path,$thumb_path,$image_name,$thumb_width);

                      ?>

                      it should be

                      $new_h=$origh/$diff;

                      Second, it does create the thumbnail. But the sample image I picked for jpg was small and too dark. The quality of the thumbnail is so poor. The thumbnail become just a black image (exactly). But I tested with some other images. It does create thumbnails but the quality is really poor.

                      Now my questions are:

                      Are there anyway to increase the quality of the thumbnails created by php image functions?

                      The thumbnails I created manually from photo shop. The size is 1/2, but the quality is 3 times better.

                      If php can only create these very poor quality but large size thumbnails, it doesn't help me very much. I may have to go back to the approach to create thumbnails offline manually.

                      Any advices?

                        for better quality thumbnails use [man]imagecopyresampled[/man]

                          I tried, the quality is still not good. And I use 100 instead of 75 as the quality too.

                          My sample image is an evening photo. With beautiful highrise buildings' lights etc. But my thumbnail is only with ugly and unclear blue color.

                          PHP created thumbnail images quality is way worse than the manually photoshop works. Is that a fact that I have to live with?

                          I prefer to use php to create thumbnail, but if the quality as it is, I have no problems to persuade my clients to use offline way to create thumbnails manually. But I need to know the fact of the quality before I make any suggestions.

                          Thanks!

                            For truecolour images, use [man]imagecreatetruecolor[/man] instead of imagecreate.

                              13 years later

                              Getting the error with php7.2 and docker "imagecreatefromjpeg()" undefined function but GD is already installed please help.

                                ZOMBIE THREAD ALERT ... dude, this is 13 years old!

                                (Did you restart the webserver?)

                                  Write a Reply...