cropping images

Discussion in 'Java' started by Roedy Green, Aug 19, 2011.

  1. Roedy Green

    Roedy Green Guest

    I have 1200 square PNG images of national flags in various sizes. I
    would like to crop them to rectangles. I thought of writing a
    one-shot java utility for the purpose, then I wondered if I would be
    reinventing the wheel. Suggestions?
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The modern conservative is engaged in one of man’s oldest exercises in moral philosophy; that is,
    the search for a superior moral justification for selfishness.
    ~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97)
     
    Roedy Green, Aug 19, 2011
    #1
    1. Advertising

  2. On 19.08.2011 01:18, Roedy Green wrote:
    > I have 1200 square PNG images of national flags in various sizes. I
    > would like to crop them to rectangles. I thought of writing a
    > one-shot java utility for the purpose, then I wondered if I would be
    > reinventing the wheel. Suggestions?


    pngtopnm | pnmcrop
     
    Thomas Richter, Aug 19, 2011
    #2
    1. Advertising

  3. Roedy Green

    Roedy Green Guest

    On Thu, 18 Aug 2011 16:18:34 -0700, Roedy Green
    <> wrote, quoted or indirectly quoted
    someone who said :

    > I thought of writing a
    >one-shot java utility for the purpose, then I wondered if I would be
    >reinventing the wheel. Suggestions?


    I have been googling and trying out various utilities that promise to
    do the job, but even a $60 utility can't see to get this right.

    I get quite annoyed when a vendor advertises a product as free when it
    isn't or that it will do some task when it does not even attempt it.
    It seems there is no penalty for lying.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The modern conservative is engaged in one of man’s oldest exercises in moral philosophy; that is,
    the search for a superior moral justification for selfishness.
    ~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97)
     
    Roedy Green, Aug 19, 2011
    #3
  4. On 8/18/2011 6:18 PM, Roedy Green wrote:
    > I have 1200 square PNG images of national flags in various sizes. I
    > would like to crop them to rectangles. I thought of writing a
    > one-shot java utility for the purpose, then I wondered if I would be
    > reinventing the wheel. Suggestions?


    ImageMagick can do a lot of stuff with image manipulation, especially
    combined with some simple shell scripts.

    --
    Beware of bugs in the above code; I have only proved it correct, not
    tried it. -- Donald E. Knuth
     
    Joshua Cranmer, Aug 19, 2011
    #4
  5. Roedy Green

    Roedy Green Guest

    On Thu, 18 Aug 2011 20:29:35 -0700, Peter Duniho
    <> wrote, quoted or indirectly quoted
    someone who said :

    >If you know in advance that every image will need the same cropping
    >applied to it, then I think the batch features in the other programs are
    >more likely to suit your needs.


    I think there are 4 different croppings, one for each directory. I
    will find out if I need something smart to chop off the transparent
    border at differently centred images. One catch is there is a feather
    edge transparency.

    I found an off-by-one bug in Batch It Ultra, but at least the author
    seems to be interested in tracking it down.

    I am so often tempted to write my own utilities simply because other
    people's code is invariable buggy, or awkward to use, and you can
    waste so much time trying to get the authors to fix it.

    What is really getting annoying is people writing completely bogus
    feature lists.

    On an unrelated project, I downloaded what was advertised to be free
    drivers for a foot pedal only to discover it was an expensive program
    to scan your drivers and tell you which ones were out of date.
    I want revenge!
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The modern conservative is engaged in one of man's oldest exercises in moral philosophy; that is,
    the search for a superior moral justification for selfishness.
    ~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97)
     
    Roedy Green, Aug 19, 2011
    #5
  6. Roedy Green

    Tom Anderson Guest

    On Thu, 18 Aug 2011, Roedy Green wrote:

    > On Thu, 18 Aug 2011 16:18:34 -0700, Roedy Green
    > <> wrote, quoted or indirectly quoted
    > someone who said :
    >
    >> I thought of writing a one-shot java utility for the purpose, then I
    >> wondered if I would be reinventing the wheel. Suggestions?

    >
    > I have been googling and trying out various utilities that promise to do
    > the job, but even a $60 utility can't see to get this right.


    Really? Wow.

    Wait, is that 60 dollars Canadian?

    > I get quite annoyed when a vendor advertises a product as free when it
    > isn't or that it will do some task when it does not even attempt it. It
    > seems there is no penalty for lying.


    I guess you don't read the news much, huh.

    Fortunately, there is a place which still values honesty, hard work, and
    doing the best job you can. It's called open source, and there we find:

    http://www.imagemagick.org/script/index.php

    Costs nothing, and a suitable invocation of the convert command will do
    what you want. ImageMagick is pretty simple to use for single images; it
    gets a bit more more twisted for multiple images, so you can either figure
    it out, or call it repeatedly from a batch script or something.

    tom

    --
    Punk's not sexual, it's just aggression.
     
    Tom Anderson, Aug 19, 2011
    #6
  7. Roedy Green

    Tom Anderson Guest

    On Thu, 18 Aug 2011, Peter Duniho wrote:

    > On 8/18/11 4:18 PM, Roedy Green wrote:
    >
    >> I have 1200 square PNG images of national flags in various sizes. I
    >> would like to crop them to rectangles. I thought of writing a one-shot
    >> java utility for the purpose, then I wondered if I would be reinventing
    >> the wheel. Suggestions?

    >
    > There are _tons_ of image manipulating programs out there. Nearly all
    > of them support some kind of cropping.
    >
    > The problem I found was that none provided an efficient workflow to deal
    > with a large number of images where each image needed to be cropped
    > differently (or at least, a large number of the set did).
    >
    > Irfanview and ImageMagick are both well-known utilities, and they offer
    > decent batch processing features. But neither allow per-image
    > customization of the batch processing.


    I wonder if ImageMagick could do this indirectly by using a mask. I'm not
    sure how you'd generate the masks, though.

    Even if you could do this, driving ImageMagick with a shell script is
    still going to be easier.

    > A few year ago I got tired of cropping thousands of images in Photoshop
    > one at a time (too much clicking), so I wrote a very simple utility to
    > do it for me. The main feature of the tool is that it will crop,
    > optionally scaling the image, with a minimum number of clicks.
    >
    > If you're curious, you can check it out here:
    > http://harveyosity.org/dragncrop/index.html


    I suppose your problem is really not manipulating a large number of
    images, but entering a large number of crop rectangles. If you had the
    rectangles in a file already, bash+convert could do the job easily.

    I've occasionally been pained by the absence of an easy way to script GUI
    interactions with images. I spend ages going through holiday pictures
    choosing which of N shots of a scene i want to post on Flickr; if i had a
    simple way of popping up two images and prompting myself to click the
    better one, i could use that as a comparison function in a sort, and
    largely mechanise the decision process.

    tom

    --
    Punk's not sexual, it's just aggression.
     
    Tom Anderson, Aug 19, 2011
    #7
  8. In article <>,
    Roedy Green <> wrote:

    > I have 1200 square PNG images of national flags in various sizes. I
    > would like to crop them to rectangles. I thought of writing a
    > one-shot java utility for the purpose, then I wondered if I would be
    > reinventing the wheel. Suggestions?


    I use ImageJ's built-in macro language to resample large numbers of
    images using Image > Adjust > Size... (25.2.6), but Image > Crop...
    (25.8) is available, too.

    <http://rsbweb.nih.gov/ij/>
    <http://rsbweb.nih.gov/ij/developer/macro/macros.html>
    <http://rsbweb.nih.gov/ij/docs/guide/userguide-Part-V.html>

    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
     
    John B. Matthews, Aug 19, 2011
    #8
  9. On 19.08.2011 02:34, Roedy Green wrote:
    > On Thu, 18 Aug 2011 16:18:34 -0700, Roedy Green
    > <> wrote, quoted or indirectly quoted
    > someone who said :
    >
    >> I thought of writing a
    >> one-shot java utility for the purpose, then I wondered if I would be
    >> reinventing the wheel. Suggestions?

    >
    > I have been googling and trying out various utilities that promise to
    > do the job, but even a $60 utility can't see to get this right.


    I pointed you to a pair of two utilities which do that rather nicely and
    cost $0. Where is the problem?
     
    Thomas Richter, Aug 19, 2011
    #9
  10. Roedy Green

    Roedy Green Guest

    On Fri, 19 Aug 2011 11:28:46 +0100, Tom Anderson
    <> wrote, quoted or indirectly quoted someone who
    said :

    >Really? Wow.
    >
    >Wait, is that 60 dollars Canadian?


    A Canadian dollar is worth about $1.01 US just now. It dropped down
    from $1.05 when the debt ceiling crisis resolved.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The modern conservative is engaged in one of man's oldest exercises in moral philosophy; that is,
    the search for a superior moral justification for selfishness.
    ~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97)
     
    Roedy Green, Aug 20, 2011
    #10
  11. Roedy Green

    Roedy Green Guest

    On Fri, 19 Aug 2011 21:48:06 +0200, Thomas Richter
    <-berlin.de> wrote, quoted or indirectly quoted someone
    who said :

    >I pointed you to a pair of two utilities which do that rather nicely and
    >cost $0. Where is the problem?


    they don't run under windows, or at least not with minimal fuss the
    way most windows utilities do.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The modern conservative is engaged in one of man's oldest exercises in moral philosophy; that is,
    the search for a superior moral justification for selfishness.
    ~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97)
     
    Roedy Green, Aug 20, 2011
    #11
  12. Roedy Green

    Nigel Wade Guest

    On 20/08/11 01:14, Roedy Green wrote:
    > On Fri, 19 Aug 2011 21:48:06 +0200, Thomas Richter
    > <-berlin.de> wrote, quoted or indirectly quoted someone
    > who said :
    >
    >> I pointed you to a pair of two utilities which do that rather nicely and
    >> cost $0. Where is the problem?

    >
    > they don't run under windows,


    apparently they do:
    http://www.imagemagick.org/Usage/windows

    > or at least not with minimal fuss the
    > way most windows utilities do.


    and exactly how many of the minimal-fuss Windows utilities that you have
    installed and tried so far have provided you with the functionality that
    you require?

    At some point you may realize that it's a more cost-effective use of
    your time to install something which you know works, even if it will
    take up some of your time, rather than continue to waste time installing
    minimal-fuss applications which don't work.

    --
    Nigel Wade
     
    Nigel Wade, Aug 22, 2011
    #12
  13. Roedy Green

    Jeff Higgins Guest

    On 08/22/2011 09:36 AM, bugbear wrote:
    > Nigel Wade wrote:
    >> On 20/08/11 01:14, Roedy Green wrote:
    >>> On Fri, 19 Aug 2011 21:48:06 +0200, Thomas Richter
    >>> <-berlin.de> wrote, quoted or indirectly quoted someone
    >>> who said :
    >>>
    >>>> I pointed you to a pair of two utilities which do that rather nicely
    >>>> and
    >>>> cost $0. Where is the problem?
    >>>
    >>> they don't run under windows,

    >>
    >> apparently they do:
    >> http://www.imagemagick.org/Usage/windows

    >
    > The utilities posted by Thomas were pngtopnm, pnmcrop
    > which are part of the netpbm suite,
    > not ImageMagick.
    >
    > It appears (quick google) that netpbm was runnable on windows at
    > one stage, and may still be.
    >
    > However, since netpbm is essentially built on
    > the principle of pipelining the components
    > together, Unix is very much its natural habitat.
    >

    I'm sure that the Cygwin environment for Windows is not for everyone
    but installing a basic Cygwin and the libnetpbm certainly qualifies
    as painless in my opinion.
    <http://www.cygwin.com/packages/>
     
    Jeff Higgins, Aug 22, 2011
    #13
  14. Roedy Green

    Nigel Wade Guest

    On 22/08/11 14:36, bugbear wrote:
    > Nigel Wade wrote:
    >> On 20/08/11 01:14, Roedy Green wrote:
    >>> On Fri, 19 Aug 2011 21:48:06 +0200, Thomas Richter
    >>> <-berlin.de> wrote, quoted or indirectly quoted someone
    >>> who said :
    >>>
    >>>> I pointed you to a pair of two utilities which do that rather nicely
    >>>> and
    >>>> cost $0. Where is the problem?
    >>>
    >>> they don't run under windows,

    >>
    >> apparently they do:
    >> http://www.imagemagick.org/Usage/windows

    >
    > The utilities posted by Thomas were pngtopnm, pnmcrop
    > which are part of the netpbm suite,
    > not ImageMagick.


    Ah, my mistake. Unfortunately I'd been following this thread last week
    when ImageMagick was suggested by several people. The actual apps.
    suggested by Thomas had been trimmed from this sub-thread, and I'd
    mistakenly assumed they were referring to ImageMagick.

    >
    > It appears (quick google) that netpbm was runnable on windows at
    > one stage, and may still be.
    >
    > However, since netpbm is essentially built on
    > the principle of pipelining the components
    > together, Unix is very much its natural habitat.
    >


    Probably so. I've never used them. I tend to stick to GIMP and
    ImageMagick when I need to do image manipulation on Linux.

    I still think Roedy would be best served by installing ImageMagick. If
    not on Windows, then in a Linux virtual machine hosted by Windows. I'm
    sure that it would be more productive in the long run than testing more
    and more Windows utilities that promise everything, yet deliver very
    little. It's also not going to carry a virus/trojan payload -
    downloading and installing random Windows utilities off the 'net is a
    route to perdition.

    --
    Nigel Wade
     
    Nigel Wade, Aug 22, 2011
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. FrankV
    Replies:
    0
    Views:
    394
    FrankV
    Nov 8, 2005
  2. Andrew Neiderer

    JAI example of cropping

    Andrew Neiderer, Sep 14, 2005, in forum: Java
    Replies:
    2
    Views:
    10,010
    Martin Trobec
    Sep 17, 2005
  3. Darrel

    Cropping an image

    Darrel, Apr 23, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    486
    Kevin Spencer
    Apr 23, 2006
  4. Kamus of Kadizhar

    Cropping log files

    Kamus of Kadizhar, Dec 16, 2003, in forum: Python
    Replies:
    6
    Views:
    322
    Gerrit Holl
    Dec 17, 2003
  5. JJ
    Replies:
    3
    Views:
    716
    PJ on Development
    Nov 19, 2007
Loading...

Share This Page