Page 1 of 1
Possible?: Changing the "Line Height" of a Text in an Image
Posted: 2010-09-05T15:57:56-07:00
by vielhuber
Hello friends!
I think this is a hard task and I need your help.
Is it possible to reach the following effect with ImageMagick:
--------------------------------------------------------------------
to
--------------------------------------------------------------------
IM has to trim the white space not around the edges (this is easy), but INSIDE the document.
It has to recognize areas (width: 100%, height: variable, say minimum 5px) and trim them (like splice them out of the document).
Is this possible? THANKS IN ADVANCE.
Please tell me also, if this is NOT possible.
Re: Possible?: Changing the "Line Height" of a Text in an Im
Posted: 2010-09-05T16:50:29-07:00
by fmw42
Not easily if these are images (though I suspect it is possible with some scripting work to locate non-white areas and crop them out and append them back again).
If you are starting with text and creating the images, then you can adjust the line height when converting text to image via -interline-spacing. see
http://www.imagemagick.org/Usage/text/# ... ne-spacing
Re: Possible?: Changing the "Line Height" of a Text in an Im
Posted: 2010-09-05T18:19:17-07:00
by anthony
Download the script divide_vert from
http://www.imagemagick.org/Usage/scripts/
This script divides images into a sequence blank and non-black row divisions. A -i option has it ignore blank divisions. As such to remove all blank rows use...
Code: Select all
divide_vert -i input_image.png miff:- | convert - -append gaps-removed.png
To replace blank rows with say 5 pixel gaps... use...
Code: Select all
divide_vert -i - miff:- |\
convert - -splice 0x5 -append \
-gravity south -splice 0x5 gaps_replaced.png
YES divide_vert is a shell script and as such quite slow.
The divide_vert script was a proof of concept script whcih I hope to implement in a new 'segmentation' section of IM Examples. Along with 'morphological object labelling' and something like what Fred
multicrop script provides. However I just don't have time to do any programing in IM at this time.
Re: Possible?: Changing the "Line Height" of a Text in an Im
Posted: 2010-09-06T08:07:01-07:00
by vielhuber
Hi!
Thanks for all answers and time.
I tried the script and indeeed it seems to work, but it is very very slow, as you mentioned.
Another idea is to use the liquid rescale thing
http://www.imagemagick.org/Usage/resize/#liquid-rescale
Please inform me in this thread if you can release your script not as bash but in full speed!
Thanks in advance.
Re: Possible?: Changing the "Line Height" of a Text in an Im
Posted: 2010-09-06T10:38:23-07:00
by fmw42
this seems to work for me
convert before.jpg -liquid-rescale 100x30% before_lr_100x30.png
Note I tried this to get an estimate of the amount to scale, but it was an over estimate for some unknown reason with respect to -liquid-rescale
Stretch to full dynamic range, average all columns to one column, negate and threshold to black and white, get average graylevel
convert before.jpg -auto-level -scale 1x461! -negate -threshold 0 -format "%[fx:mean]" info:
0.466377
Re: Possible?: Changing the "Line Height" of a Text in an Im
Posted: 2010-09-06T19:24:39-07:00
by anthony
As I like to say...
There are lots of ways to skin a cat, and what method you use depends
on what you want that skin for, and how messy you like the results!
The script I provided was a concept script. Their are probably ways to speed it up significantly. For example by scaling an image to one column of pixels will get you a nice average of all the values. If that value is white then that row can be removed. However that only works for black and white images.
A little extra color replacement work, can make this work for any single soild-color background.
Hmmmm.....
Yes... it works, and should work for any fixed solid color background! If it wasn't for the need to gather the 'height' of the image, or posibly collect the background color from the top-left corner pixel, it would not even need any temporary files at all!
Look at the script "divide_vert_bg" when it becomes available in
IM Examples scripts area in an hour or two...
http://www.imagemagick.org/Usage/scripts/divide_vert_bg