exif_image and imagejpeg

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

    exif_image and imagejpeg

    I'm sketching out an application that would automagically do a photo gallery.

    As part of this, I want to examine each graphic in the a given directory, look
    for an embedded thumbnail and, if present, output it instead of the image.

    Version 2... If there is no embedded thumbnail, create one and save it in the
    directory.

    I have an image from my Sony camera I'm using to test and it does have an
    embedded thumbnail. I'm now trying to extract the image and display it
    through imagejpeg.

    The code fails with

    Warning: imagejpeg(): supplied argument is not a valid Image resource


    <?
    $iname="DSC0052 7.JPG";
    $image = exif_thumbnail( $iname, $width, $height, $type);
    $type=exif_imag etype($iname);
    echo $type;
    if ($image!==false ) {
    imagejpeg($imag e);
    } else {
    // no thumbnail available, handle the error here
    echo "No thumbnail available";
    }
    ?>

    If I replace the call to imagejpeg with

    header("Content-type: " .image_type_to_ mime_type($type ));
    echo $image;

    I see the thumbnail. $type is 2, which is IMAGETYPE_JPEG.

    Is the image resource returned from exif_thumbnail different from the resource
    expected by imagejpeg?

    What has gone over my head?

    Thanks.
  • B. Johannessen

    #2
    Re: exif_image and imagejpeg

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Steven Stern wrote:[color=blue]
    > <?
    > $iname="DSC0052 7.JPG";
    > $image = exif_thumbnail( $iname, $width, $height, $type);
    > $type=exif_imag etype($iname);
    > echo $type;
    > if ($image!==false ) {[/color]

    $image = imagecreatefrom string($image):
    [color=blue]
    > imagejpeg($imag e);
    > } else {
    > // no thumbnail available, handle the error here
    > echo "No thumbnail available";
    > }
    > ?>[/color]


    Bob

    - --
    | B. Johannessen <bob@db.org> +47 97 15 20 09 - http://db.org/
    | Mail & Spam - News, Drafts & Standards - http://db.org/blog/
    | On The Origin Of Spam; Spam Statistics - http://db.org/spam/
    - --
    -----BEGIN PGP SIGNATURE-----

    iD8DBQFANZqLooi sUyMOFlgRAkI1AJ 984NKyP8B8ydJ5J A3ndFThJ9glBQCf Q/lX
    wj23I6U5SZecTCA Epbo/GWc=
    =3o2y
    -----END PGP SIGNATURE-----

    Comment

    • Steven Stern

      #3
      Re: exif_image and imagejpeg

      On Fri, 20 Feb 2004 05:26:35 +0000 (more or less), "B. Johannessen"
      <bob@db.org> wrote:
      [color=blue]
      >-----BEGIN PGP SIGNED MESSAGE-----
      >Hash: SHA1
      >
      >Steven Stern wrote:[color=green]
      >> <?
      >> $iname="DSC0052 7.JPG";
      >> $image = exif_thumbnail( $iname, $width, $height, $type);
      >> $type=exif_imag etype($iname);
      >> echo $type;
      >> if ($image!==false ) {[/color]
      >
      > $image = imagecreatefrom string($image):
      >[/color]



      Thank you!

      Comment

      • Reply via newsgroup

        #4
        Re: exif_image and imagejpeg

        Steven Stern wrote:
        [color=blue]
        > I'm sketching out an application that would automagically do a photo gallery.
        >
        > As part of this, I want to examine each graphic in the a given directory, look
        > for an embedded thumbnail and, if present, output it instead of the image.
        >
        > Version 2... If there is no embedded thumbnail, create one and save it in the
        > directory.
        >
        > I have an image from my Sony camera I'm using to test and it does have an
        > embedded thumbnail. I'm now trying to extract the image and display it
        > through imagejpeg.
        >
        > The code fails with
        >
        > Warning: imagejpeg(): supplied argument is not a valid Image resource
        >
        >
        > <?
        > $iname="DSC0052 7.JPG";
        > $image = exif_thumbnail( $iname, $width, $height, $type);
        > $type=exif_imag etype($iname);
        > echo $type;
        > if ($image!==false ) {
        > imagejpeg($imag e);
        > } else {
        > // no thumbnail available, handle the error here
        > echo "No thumbnail available";
        > }
        > ?>
        >
        > If I replace the call to imagejpeg with
        >
        > header("Content-type: " .image_type_to_ mime_type($type ));
        > echo $image;
        >
        > I see the thumbnail. $type is 2, which is IMAGETYPE_JPEG.
        >
        > Is the image resource returned from exif_thumbnail different from the resource
        > expected by imagejpeg?
        >
        > What has gone over my head?
        >
        > Thanks.[/color]

        I can't recall where I read this, but don't depend on the jpeg having
        the thumbnail in the first place - If the jpeg was created properly,
        then it will have it, however some of the newer digital camera's out
        there are breaking this standard to create smaller files... I have a
        Sony camera and it works fine, but I believe (but not certain) that
        Kodak camera's are just one of a few that break the rule...

        I know someone else solved your earlier question, but I thought I'd
        throw in my two pence worth and point that out.

        randelld

        Comment

        • Steven Stern

          #5
          Re: exif_image and imagejpeg

          On Sat, 21 Feb 2004 06:50:54 GMT (more or less), Reply via newsgroup
          <reply-to-newsgroup@pleas e.com> wrote:

          [color=blue]
          >I can't recall where I read this, but don't depend on the jpeg having
          >the thumbnail in the first place - If the jpeg was created properly,
          >then it will have it, however some of the newer digital camera's out
          >there are breaking this standard to create smaller files... I have a
          >Sony camera and it works fine, but I believe (but not certain) that
          >Kodak camera's are just one of a few that break the rule...
          >
          >I know someone else solved your earlier question, but I thought I'd
          >throw in my two pence worth and point that out.
          >
          >randelld[/color]

          Thanks. When I get off my butt and write the code, it will look for a
          thumbnail in the image and save it to disk if there. If not, it will create
          one.


          Comment

          Working...