Question on using GD in PHP to size/resize images

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • eholz1

    #1

    Question on using GD in PHP to size/resize images

    Hello PHP group,

    I am using some php code to check the size of images, and then
    resize or determine new dimension for the image. GD seems quite slow.
    It takes about 5 seconds (plus or minus) to calulate dimension for 7
    jpeg images.

    I have a 700mhz processor (Pentium III, remember those??)! with almost
    a gb of memory.
    Is that the way GD is??? Here is a snippet of the dode I use: I pass
    the image from an array to this function:

    function imageDimensions ($img) {

    //get size create an original image from file above

    $orig = imagecreatefrom jpeg($img);

    if ($orig) {

    //get height and width

    $orig_x = imagesx($orig);

    $orig_y = imagesy($orig);

    $pic_size[0] = $orig_x; //width

    $pic_size[1] = $orig_y; //height
    if ($orig_x 799) {

    $image_x = 800;
    }else{
    $image_x = $orig_x;
    }

    // $thumb_x = $_REQUEST['thumb_x'];

    $image_y = round(($orig_y * $image_x) / $orig_x);

    // $thumb_y = round(($orig_y * $thumb_x) / $orig_x);

    $pic_size[2] = $image_y;

    $pic_size[3] = $image_x;

    return $pic_size;

    //echo("Image width: " . $orig_x . ". Image height: " . $orig_y);

    } else {

    echo 'No Image!';

    }

    }
    I am open to any suggestions on improving my "code" as it were!

    Thanks for a good group,
    eholz1

  • Curtis

    #2
    Re: Question on using GD in PHP to size/resize images

    If you're trying to make thumbnails, you should actually resample the
    images, otherwise, your web page will take a while to load, even if you
    change the dimensions in the image tag.

    See: http://php.net/manual/en/function.im...yresampled.php

    On Jan 5, 10:01 pm, "eholz1" <ewh...@gmail.c omwrote:
    Hello PHP group,
    >
    I am using some php code to check the size of images, and then
    resize or determine new dimension for the image. GD seems quite slow.
    It takes about 5 seconds (plus or minus) to calulate dimension for 7
    jpeg images.
    >
    I have a 700mhz processor (Pentium III, remember those??)! with almost
    a gb of memory.
    Is that the way GD is??? Here is a snippet of the dode I use: I pass
    the image from an array to this function:
    >
    function imageDimensions ($img) {
    >
    //get size create an original image from file above
    >
    $orig = imagecreatefrom jpeg($img);
    >
    if ($orig) {
    >
    //get height and width
    >
    $orig_x = imagesx($orig);
    >
    $orig_y = imagesy($orig);
    >
    $pic_size[0] = $orig_x; //width
    >
    $pic_size[1] = $orig_y; //height
    if ($orig_x 799) {
    >
    $image_x = 800;
    }else{
    $image_x = $orig_x;
    }
    >
    // $thumb_x = $_REQUEST['thumb_x'];
    >
    $image_y = round(($orig_y * $image_x) / $orig_x);
    >
    // $thumb_y = round(($orig_y * $thumb_x) / $orig_x);
    >
    $pic_size[2] = $image_y;
    >
    $pic_size[3] = $image_x;
    >
    return $pic_size;
    >
    //echo("Image width: " . $orig_x . ". Image height: " . $orig_y);
    >
    } else {echo 'No Image!';
    >
    }
    }I am open to any suggestions on improving my "code" as it were!
    >
    Thanks for a good group,
    eholz1

    Comment

    • Geoff Berrow

      #3
      Re: Question on using GD in PHP to size/resize images

      Message-ID: <1168063261.502 489.160810@v33g 2000cwv.googleg roups.comfrom
      eholz1 contained the following:
      >I am using some php code to check the size of images, and then
      >resize or determine new dimension for the image. GD seems quite slow.
      >It takes about 5 seconds (plus or minus) to calulate dimension for 7
      >jpeg images.
      You don't need GD to get image sizes


      --
      Geoff Berrow (put thecat out to email)
      It's only Usenet, no one dies.
      My opinions, not the committee's, mine.
      Simple RFDs http://www.ckdog.co.uk/rfdmaker/

      Comment

      • Michael Austin

        #4
        Re: Question on using GD in PHP to size/resize images

        Geoff Berrow wrote:
        Message-ID: <1168063261.502 489.160810@v33g 2000cwv.googleg roups.comfrom
        eholz1 contained the following:
        >
        >
        >>I am using some php code to check the size of images, and then
        >>resize or determine new dimension for the image. GD seems quite slow.
        >>It takes about 5 seconds (plus or minus) to calulate dimension for 7
        >>jpeg images.
        >
        >
        You don't need GD to get image sizes

        >
        if you are doing thumbnails you need neither.

        <a href='<?php echo $path ?>'>
        <img src='<?php echo $imagelist[$i] ?>' width='50' height='50' class='thumb'>

        I found this in a php script called imagebrowser.ph p (a google search should
        locate it...)

        --
        Michael Austin.
        Database Consultant

        Comment

        • Jerry Stuckle

          #5
          Re: Question on using GD in PHP to size/resize images

          Michael Austin wrote:
          Geoff Berrow wrote:
          >
          >Message-ID: <1168063261.502 489.160810@v33g 2000cwv.googleg roups.comfrom
          >eholz1 contained the following:
          >>
          >>
          >>I am using some php code to check the size of images, and then
          >>resize or determine new dimension for the image. GD seems quite slow.
          >>It takes about 5 seconds (plus or minus) to calulate dimension for 7
          >>jpeg images.
          >>
          >>
          >>
          >You don't need GD to get image sizes
          >http://uk2.php.net/manual/en/function.getimagesize.php
          >>
          >
          if you are doing thumbnails you need neither.
          >
          <a href='<?php echo $path ?>'>
          <img src='<?php echo $imagelist[$i] ?>' width='50' height='50'
          class='thumb'>
          >
          I found this in a php script called imagebrowser.ph p (a google search
          should locate it...)
          >
          And this is exactly what yous should NOT do. It causes the entire
          (large) image to load, then be resized by the browser.

          It is much better to create thumbnails and send an image of the
          appropriate size. Depending on the original image size, the size
          difference is enormous. For instance, if the original image size is
          500x500, your thumbnail may be as much as 99% smaller than the original.

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • eholz1

            #6
            Re: Question on using GD in PHP to size/resize images

            Hello Curtis and the others,

            This is exactly what I needed. I am doing some testing with images,
            etc. My plan is to read/check a
            given image file, and load its name, size, filetype, etc into a
            database, and display the image (via a thumbnail link, etc). So the
            link to the php stuff is very useful, and all i need at this point is
            to get image data, and do not need to process image yet (like make a
            thumbnail, resize image to browser size (maybe 900 x 600, etc).

            Thanks again,

            eholz1,

            Curtis wrote:
            If you're trying to make thumbnails, you should actually resample the
            images, otherwise, your web page will take a while to load, even if you
            change the dimensions in the image tag.
            >
            See: http://php.net/manual/en/function.im...yresampled.php
            >
            On Jan 5, 10:01 pm, "eholz1" <ewh...@gmail.c omwrote:
            Hello PHP group,

            I am using some php code to check the size of images, and then
            resize or determine new dimension for the image. GD seems quite slow.
            It takes about 5 seconds (plus or minus) to calulate dimension for 7
            jpeg images.

            I have a 700mhz processor (Pentium III, remember those??)! with almost
            a gb of memory.
            Is that the way GD is??? Here is a snippet of the dode I use: I pass
            the image from an array to this function:

            function imageDimensions ($img) {

            //get size create an original image from file above

            $orig = imagecreatefrom jpeg($img);

            if ($orig) {

            //get height and width

            $orig_x = imagesx($orig);

            $orig_y = imagesy($orig);

            $pic_size[0] = $orig_x; //width

            $pic_size[1] = $orig_y; //height
            if ($orig_x 799) {

            $image_x = 800;
            }else{
            $image_x = $orig_x;
            }

            // $thumb_x = $_REQUEST['thumb_x'];

            $image_y = round(($orig_y * $image_x) / $orig_x);

            // $thumb_y = round(($orig_y * $thumb_x) / $orig_x);

            $pic_size[2] = $image_y;

            $pic_size[3] = $image_x;

            return $pic_size;

            //echo("Image width: " . $orig_x . ". Image height: " . $orig_y);

            } else {echo 'No Image!';

            }
            }I am open to any suggestions on improving my "code" as it were!

            Thanks for a good group,
            eholz1

            Comment

            • eholz1

              #7
              Re: Question on using GD in PHP to size/resize images

              Hello Jerry,

              I love your posts!!!

              Thanks,

              ehozl1


              Jerry Stuckle wrote:
              Michael Austin wrote:
              Geoff Berrow wrote:
              Message-ID: <1168063261.502 489.160810@v33g 2000cwv.googleg roups.comfrom
              eholz1 contained the following:
              >
              >
              >I am using some php code to check the size of images, and then
              >resize or determine new dimension for the image. GD seems quite slow.
              >It takes about 5 seconds (plus or minus) to calulate dimension for 7
              >jpeg images.
              >
              >
              >
              You don't need GD to get image sizes

              >
              if you are doing thumbnails you need neither.

              <a href='<?php echo $path ?>'>
              <img src='<?php echo $imagelist[$i] ?>' width='50' height='50'
              class='thumb'>

              I found this in a php script called imagebrowser.ph p (a google search
              should locate it...)
              >
              And this is exactly what yous should NOT do. It causes the entire
              (large) image to load, then be resized by the browser.
              >
              It is much better to create thumbnails and send an image of the
              appropriate size. Depending on the original image size, the size
              difference is enormous. For instance, if the original image size is
              500x500, your thumbnail may be as much as 99% smaller than the original.
              >
              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • eholz1

                #8
                Re: Question on using GD in PHP to size/resize images

                One last question,

                In terms of making thumbnails, resizing images, etc are there any other
                programs that work better
                (whatever "better" means) than GD??? I have a version of gallery
                (menalto opensource program) and it seems to like netpbm, ImageMagik,
                etc. are either of these better or faster, etc. Or are they more or
                less equal??? My goal is to check size of original image (typically
                3000px by 3072 px) and make a thumbnail, and resize the "big" image to
                appropriate browser size (a poor man's gallery program).
                and when a viewer clicks the thumbnail, display the bigger image via
                php in browser.

                eholz1

                eholz1 wrote:
                Hello Jerry,
                >
                I love your posts!!!
                >
                Thanks,
                >
                ehozl1
                >
                >
                Jerry Stuckle wrote:
                Michael Austin wrote:
                Geoff Berrow wrote:
                >
                >Message-ID: <1168063261.502 489.160810@v33g 2000cwv.googleg roups.comfrom
                >eholz1 contained the following:
                >>
                >>
                >>I am using some php code to check the size of images, and then
                >>resize or determine new dimension for the image. GD seems quite slow.
                >>It takes about 5 seconds (plus or minus) to calulate dimension for 7
                >>jpeg images.
                >>
                >>
                >>
                >You don't need GD to get image sizes
                >http://uk2.php.net/manual/en/function.getimagesize.php
                >>
                >
                if you are doing thumbnails you need neither.
                >
                <a href='<?php echo $path ?>'>
                <img src='<?php echo $imagelist[$i] ?>' width='50' height='50'
                class='thumb'>
                >
                I found this in a php script called imagebrowser.ph p (a google search
                should locate it...)
                >
                And this is exactly what yous should NOT do. It causes the entire
                (large) image to load, then be resized by the browser.

                It is much better to create thumbnails and send an image of the
                appropriate size. Depending on the original image size, the size
                difference is enormous. For instance, if the original image size is
                500x500, your thumbnail may be as much as 99% smaller than the original.

                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • Andy Hassall

                  #9
                  Re: Question on using GD in PHP to size/resize images

                  On 6 Jan 2007 09:18:15 -0800, "eholz1" <ewholz@gmail.c omwrote:
                  >In terms of making thumbnails, resizing images, etc are there any other
                  >programs that work better
                  >(whatever "better" means) than GD??? I have a version of gallery
                  >(menalto opensource program) and it seems to like netpbm, ImageMagik,
                  >etc. are either of these better or faster, etc. Or are they more or
                  >less equal??? My goal is to check size of original image (typically
                  >3000px by 3072 px) and make a thumbnail, and resize the "big" image to
                  >appropriate browser size (a poor man's gallery program).
                  >and when a viewer clicks the thumbnail, display the bigger image via
                  >php in browser.
                  ImageMagick is generally more suited to processing photographic images; GD is
                  mostly for computer-generated "block" graphics. ImageMagick is also somewhat
                  faster for image processing (resize etc.) and can give subjectively better
                  results as there's many options for filters and convolutions.

                  See also http://groups.google.co.uk/group/com...76e8f1a175b4ed

                  The downside is that (a) it has to be installed in the first place and (b) you
                  may need to shell out to the "convert" command, although there are a couple of
                  PHP APIs that give you direct access to the ImageMagick API.

                  --
                  Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
                  http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

                  Comment

                  • eholz1

                    #10
                    Re: Question on using GD in PHP to size/resize images

                    Hello Andy,

                    Thanks for the info. I do have both netpbm and ImageMagik installed on
                    my "test" server, so that is ok.
                    I can convert images, and them move them to my production web site.


                    Thanks again,

                    ewholz

                    (how come all the image stuff seems to come from the UK???, I guess no
                    one uses it in the US :)


                    Andy Hassall wrote:
                    On 6 Jan 2007 09:18:15 -0800, "eholz1" <ewholz@gmail.c omwrote:
                    >
                    In terms of making thumbnails, resizing images, etc are there any other
                    programs that work better
                    (whatever "better" means) than GD??? I have a version of gallery
                    (menalto opensource program) and it seems to like netpbm, ImageMagik,
                    etc. are either of these better or faster, etc. Or are they more or
                    less equal??? My goal is to check size of original image (typically
                    3000px by 3072 px) and make a thumbnail, and resize the "big" image to
                    appropriate browser size (a poor man's gallery program).
                    and when a viewer clicks the thumbnail, display the bigger image via
                    php in browser.
                    >
                    ImageMagick is generally more suited to processing photographic images; GD is
                    mostly for computer-generated "block" graphics. ImageMagick is also somewhat
                    faster for image processing (resize etc.) and can give subjectively better
                    results as there's many options for filters and convolutions.
                    >
                    See also http://groups.google.co.uk/group/com...76e8f1a175b4ed
                    >
                    The downside is that (a) it has to be installed in the first place and (b) you
                    may need to shell out to the "convert" command, although there are a couple of
                    PHP APIs that give you direct access to the ImageMagick API.
                    >
                    --
                    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
                    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: Question on using GD in PHP to size/resize images

                      eholz1 wrote:
                      One last question,
                      >
                      In terms of making thumbnails, resizing images, etc are there any other
                      programs that work better
                      (whatever "better" means) than GD??? I have a version of gallery
                      (menalto opensource program) and it seems to like netpbm, ImageMagik,
                      etc. are either of these better or faster, etc. Or are they more or
                      less equal??? My goal is to check size of original image (typically
                      3000px by 3072 px) and make a thumbnail, and resize the "big" image to
                      appropriate browser size (a poor man's gallery program).
                      and when a viewer clicks the thumbnail, display the bigger image via
                      php in browser.
                      >
                      eholz1
                      >
                      eholz1 wrote:
                      >
                      >>Hello Jerry,
                      >>
                      >>I love your posts!!!
                      >>
                      >>Thanks,
                      >>
                      >>ehozl1
                      >>
                      >>
                      >>Jerry Stuckle wrote:
                      >>
                      >>>Michael Austin wrote:
                      >>>
                      >>>>Geoff Berrow wrote:
                      >>>>
                      >>>>
                      >>>>>Message-ID: <1168063261.502 489.160810@v33g 2000cwv.googleg roups.comfrom
                      >>>>>eholz1 contained the following:
                      >>>>>
                      >>>>>
                      >>>>>
                      >>>>>>I am using some php code to check the size of images, and then
                      >>>>>>resize or determine new dimension for the image. GD seems quite slow.
                      >>>>>>It takes about 5 seconds (plus or minus) to calulate dimension for 7
                      >>>>>>jpeg images.
                      >>>>>
                      >>>>>
                      >>>>>
                      >>>>>You don't need GD to get image sizes
                      >>>>>http://uk2.php.net/manual/en/function.getimagesize.php
                      >>>>>
                      >>>>
                      >>>>if you are doing thumbnails you need neither.
                      >>>>
                      >>>><a href='<?php echo $path ?>'>
                      >>>><img src='<?php echo $imagelist[$i] ?>' width='50' height='50'
                      >>>>class='thum b'>
                      >>>>
                      >>>>I found this in a php script called imagebrowser.ph p (a google search
                      >>>>should locate it...)
                      >>>>
                      >>>
                      >>>And this is exactly what yous should NOT do. It causes the entire
                      >>>(large) image to load, then be resized by the browser.
                      >>>
                      >>>It is much better to create thumbnails and send an image of the
                      >>>appropriat e size. Depending on the original image size, the size
                      >>>difference is enormous. For instance, if the original image size is
                      >>>500x500, your thumbnail may be as much as 99% smaller than the original.
                      >>>
                      >>>--
                      >>>============ ======
                      >>>Remove the "x" from my email address
                      >>>Jerry Stuckle
                      >>>JDS Computer Training Corp.
                      >>>jstucklex@at tglobal.net
                      >>>============ ======
                      >
                      >
                      I agree with Andy. ImageMagick is the best way to go, if you can
                      install it.

                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • Geoff Berrow

                        #12
                        Re: Question on using GD in PHP to size/resize images

                        Message-ID: <1168103895.105 414.175050@51g2 000cwl.googlegr oups.comfrom
                        eholz1 contained the following:
                        >
                        >In terms of making thumbnails, resizing images, etc are there any other
                        >programs that work better
                        >(whatever "better" means) than GD??? I have a version of gallery
                        >(menalto opensource program) and it seems to like netpbm, ImageMagik,
                        >etc. are either of these better or faster, etc. Or are they more or
                        >less equal??? My goal is to check size of original image (typically
                        >3000px by 3072 px) and make a thumbnail, and resize the "big" image to
                        >appropriate browser size (a poor man's gallery program).
                        >and when a viewer clicks the thumbnail, display the bigger image via
                        >php in browser.
                        Done that :-)


                        Code:

                        --
                        Geoff Berrow (put thecat out to email)
                        It's only Usenet, no one dies.
                        My opinions, not the committee's, mine.
                        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                        Comment

                        Working...