http://qs321.pair.com?node_id=11118010


in reply to Shrink Images and PDFs

Nice. If convert is on your system, chances are so is Image::Magick. Is there a reason to not use a pure Perl implementation rather than forking a convert process? You may want to look for a Perl interface to gs as well. I'd be surprised if a decent one didn't exist.

Replies are listed 'Best First'.
Re^2: Shrink Images and PDFs
by haukex (Archbishop) on Jun 13, 2020 at 14:24 UTC
    If convert is on your system, chances are so is Image::Magick.

    Not in my experience; usually the Perl module has to be installed separately. How easy that is depends on what Perl you're using, for example, one could use the system Perl and just install libimage-magick-perl, but building ImageMagick (or GraphicsMagick nowadays, apparently) and its Perl module can be a can of worms.

    Is there a reason to not use a pure Perl implementation rather than forking a convert process?

    Simplicity, mostly. This was only intended for *NIX (for now), I wasn't concerned about performance, and since I'm using my own IPC::Run3::Shell module, I can be sure to avoid all the pitfalls of running external commands. Using the Perl module would be better if I was doing multiple operations on the image that are hard to do in a single command line, but the convert command line I'm using is simple enough.

      >usually the Perl module has to be installed separately

      Sorry, I meant that the Perl module comes with installing ImageMagick itself if you do it from source. From my experience installing it from source is straightforward (they make it so necessarily). Just a thought I wanted to mention since I've use gone down a similar route with image manipulation. I didn't do any shrinking, but added some watermarks to images I was serving. I also served up different "sizes". But it was all done via the Perl library, not convert itself. Anyway, I think your use of Perl is really neat here.