[GRLUG] image processing question

Michael Mol mikemol at gmail.com
Sun May 3 15:35:47 EDT 2009


Actually, with libpng, writing a C program to do autocrop is fairly
trivial; It amounts to:

1. Load in the PNG file with libpng.
2. Save off the width of the image.
3. Discard each row until you get a non-background pixel.
4. Save all remaining rows into a temporary buffer.
5. Walk through your temporary buffer from the bottom up, discarding
each row until you hit a non-background pixel.
6. Save all remaining rows into a temporary buffer.
7. Walk through your temporary buffer left-to-right, discarding each
column until you hit a non-background pixel.
8. Save all remaining rows into a temporary buffer.
9. Walk through your temporary buffer right-to-left, discarding each
column until you hit a non-background pixel.
10. Your remaining rows are the image you want.  Give them to libpng
to save to a new file.

On Sun, May 3, 2009 at 1:56 PM, Ben DeMott <ben.demott at gmail.com> wrote:
> I'm not sure if I understand what you are trying to do exactly...
> But it sounds like a PHP or Python command line script would be perfect for
> this job, both have GD and Image Magic libraries and functions.
> PHP Even has a library to do OCR.
> Not near the investment of writing a C  application, but you get the
> reliability/control of a programming language!
> I would be happy to write you a quick script because I'm that nice - if you
> can't do it on your own let me know further details and I'll whip something
> together.
>
> On Sun, May 3, 2009 at 1:22 PM, Michael Mol <mikemol at gmail.com> wrote:
>>
>> Long story short:
>> 1. I have a bunch of HTML snippets.
>> 2. I've successfully managed to batch-convert them to PostScript using
>> html2ps
>> 3. I can batch-convert them to PNG with ImageMagick, but I wind up
>> with a tiny snippet of text on a much larger image.
>>
>> I don't need a PNG that scales out to 8.5x11, or any other constant
>> size.  What I need is a PNG image that's just large enough to contain
>> the text.
>>
>> Now, I could load each image into the GIMP and use the auto-crop tool,
>> but as you might have guessed by now, my goal is to do everything in
>> batches. I'm also not real keen on the idea of writing an autocropper
>> in C, but I'd rather do that before delving into the GIMP's Script Fu
>> interface.
>>
>> Is there an way to batch the automatic cropping of such images?
>>
>> --
>> :wq
>> _______________________________________________
>> grlug mailing list
>> grlug at grlug.org
>> http://shinobu.grlug.org/cgi-bin/mailman/listinfo/grlug
>
>
> _______________________________________________
> grlug mailing list
> grlug at grlug.org
> http://shinobu.grlug.org/cgi-bin/mailman/listinfo/grlug
>



-- 
:wq


More information about the grlug mailing list