Getting and using binary image data from ImageMagick

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

    Getting and using binary image data from ImageMagick

    I am trying to use ImageMagick to create thumbnails on the fly - without
    having to save the image to a file.

    I have gotten it to work by using passthru($cmd, $retval), but I want to
    use something else that will give me the complete output returned as a
    string that I can convert to a GD lib image resource so I can verify the
    operation worked before sending the Content-type header for the image.

    This works:
    ---------------------------------------------------------
    // $photo = path to image file
    $cmd = "convert.ex e -size 250x250 \"$photo\"" .
    ' -resize 125x125' .
    ' -strip' .
    ' -unsharp 0.2x0.6+1.0' .
    ' -quality 87 JPG:-';

    header("Content-type: image/jpeg");
    passthru($cmd, $retval);
    ---------------------------------------------------------

    Using this, the resized image is displayed in my browser.

    However, I would rather get the binary output from ImageMagick into a
    variable and then test retval (or use some other method) to determine if
    the operation was successful.

    I've tried shell_exec ...
    $output = shell_exec($cmd );
    .... but the data in $output appears truncated (ÿØÿà�JFIF� ,,ï¿½ï¿½Ã¿Ã›ï¿ ½C�
    - is all there is ). ??

    Has anyone done anything like this? Any suggestions?

    --
    *************** **************
    Chuck Anderson • Boulder, CO

    *************** **************
  • petersprc

    #2
    Re: Getting and using binary image data from ImageMagick

    You can use this code, but change the command:



    That will only print the header if the command starts generating good
    output.

    By the way, for a generic resize script with more options and file
    caching, use:

    phpThumb() is the PHP thumbnail generator. Many image processing options (blur, sharpen, colorize, saturation, gamma, etc) and support for many input image formats across all versions of GD, including JPEG, PNG, GIF and BMP (even without ImageMagick).


    On Jul 19, 1:30 am, Chuck Anderson <websiteaddr... @seemy.sigwrote :
    I am trying to use ImageMagick to create thumbnails on the fly - without
    having to save the image to a file.
    >
    I have gotten it to work by using passthru($cmd, $retval), but I want to
    use something else that will give me the complete output returned as a
    string that I can convert to a GD lib image resource so I can verify the
    operation worked before sending the Content-type header for the image.
    >
    This works:
    ---------------------------------------------------------
    // $photo = path to image file
    $cmd = "convert.ex e -size 250x250 \"$photo\"" .
    ' -resize 125x125' .
    ' -strip' .
    ' -unsharp 0.2x0.6+1.0' .
    ' -quality 87 JPG:-';
    >
    header("Content-type: image/jpeg");
    passthru($cmd, $retval);
    ---------------------------------------------------------
    >
    Using this, the resized image is displayed in my browser.
    >
    However, I would rather get the binary output from ImageMagick into a
    variable and then test retval (or use some other method) to determine if
    the operation was successful.
    >
    I've tried shell_exec ...
    $output = shell_exec($cmd );
    ... but the data in $output appears truncated (ÿØÿà?JFIF? ,,??ÿÛ?C?
    - is all there is ). ??
    >
    Has anyone done anything like this? Any suggestions?
    >
    --
    *************** **************
    Chuck Anderson · Boulder, CO

    *************** **************

    Comment

    • Chuck Anderson

      #3
      Re: Getting and using binary image data from ImageMagick

      petersprc wrote:
      You can use this code, but change the command:
      >

      >
      That will only print the header if the command starts generating good
      output.
      >
      Thanks. (I take it that's yours.) It'll take me a little while to wrap
      my head around that, but I will.
      By the way, for a generic resize script with more options and file
      caching, use:
      >
      phpThumb() is the PHP thumbnail generator. Many image processing options (blur, sharpen, colorize, saturation, gamma, etc) and support for many input image formats across all versions of GD, including JPEG, PNG, GIF and BMP (even without ImageMagick).

      >
      Some things I like doing myself, but that sure is a robust,
      all-encompassing thumbnail generator. I think it does, too much.

      Thanks,
      Chuck
      On Jul 19, 1:30 am, Chuck Anderson <websiteaddr... @seemy.sigwrote :
      >
      >I am trying to use ImageMagick to create thumbnails on the fly - without
      >having to save the image to a file.
      >>
      >I have gotten it to work by using passthru($cmd, $retval), but I want to
      >use something else that will give me the complete output returned as a
      >string that I can convert to a GD lib image resource so I can verify the
      >operation worked before sending the Content-type header for the image.
      >>
      >This works:
      >---------------------------------------------------------
      >// $photo = path to image file
      >$cmd = "convert.ex e -size 250x250 \"$photo\"" .
      > ' -resize 125x125' .
      > ' -strip' .
      > ' -unsharp 0.2x0.6+1.0' .
      > ' -quality 87 JPG:-';
      >>
      >header("Conten t-type: image/jpeg");
      >passthru($cm d, $retval);
      >---------------------------------------------------------
      >>
      >Using this, the resized image is displayed in my browser.
      >>
      >However, I would rather get the binary output from ImageMagick into a
      >variable and then test retval (or use some other method) to determine if
      >the operation was successful.
      >>
      >I've tried shell_exec ...
      >$output = shell_exec($cmd );
      >... but the data in $output appears truncated (ÿØÿà?JFIF? ,,??ÿÛ?C?
      >- is all there is ). ??
      >>
      >Has anyone done anything like this? Any suggestions?
      >>
      >--
      >************** ***************
      > Chuck Anderson · Boulder, CO
      > http://www.CycleTourist.com
      >************** ***************
      >>
      >
      >
      >

      --
      *************** **************
      Chuck Anderson • Boulder, CO

      Everyone's journey should be different,
      so that we all are enriched
      in new and endless ways
      *************** **************

      Comment

      Working...