Inserting blank lines between parts of an image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
jwes
Posts: 3
Joined: 2017-08-29T09:04:12-07:00
Authentication code: 1151

Inserting blank lines between parts of an image

Post by jwes »

I have a number of images that are 536x536 pixels. I want to insert 10 pixels of blank space every 67 pixels while shifting the rest of the image down. The result should be images that are 536x606 pixels as below. Can someone help me do this?

Original
67 pixels image
67 pixels image
67 pixels image
67 pixels image
67 pixels image
67 pixels image
67 pixels image
67 pixels image

New
67 pixels image
10 pixels blank
67 pixels image
10 pixels blank
67 pixels image
10 pixels blank
67 pixels image
10 pixels blank
67 pixels image
10 pixels blank
67 pixels image
10 pixels blank
67 pixels image
10 pixels blank
67 pixels image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Inserting blank lines between parts of an image

Post by fmw42 »

What is your IM version and Platform? Please alway provide that when asking question since syntax may vary, especially if scripting. Once we know that, we can probably help.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620

For novices, see

viewtopic.php?f=1&t=9620
http://http://www.imagemagick.org/scrip ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Inserting blank lines between parts of an image

Post by snibgo »

What version of IM? I'll assume v6. For v7, use "magick" instead of "convert".

What platform? But that makes no difference to my suggestion.

Code: Select all

convert -size 536x536 gradient: -crop 0x67 -background None -gravity North -extent 0x77 -append -crop 0x606+0+0 +repage out.png
"-size 536x536 gradient:" makes a sample input image. You would use your own file.

Then I crop into multiple images, each 67 pixels high. I extend each downwards to 77 pixels height, with the extra rows colour "none", which is transparent black. Then I append these vertically. The result has an extra 10 rows at the bottom, so the final "-crop" removes them.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Inserting blank lines between parts of an image

Post by fmw42 »

input image (dimensions 640x480)

Image

Code: Select all

convert logo.png -crop 640x67 +repage -gravity south -background none -splice 0x67 -append -chop 0x10 logo_stripe.png
Image

see
http://www.imagemagick.org/Usage/crop/#crop_tile
http://www.imagemagick.org/Usage/crop/#splice
http://www.imagemagick.org/Usage/crop/#chop
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Inserting blank lines between parts of an image

Post by GeeMack »

jwes wrote: 2017-08-29T09:22:42-07:00I have a number of images that are 536x536 pixels. I want to insert 10 pixels of blank space every 67 pixels while shifting the rest of the image down. The result should be images that are 536x606 pixels as below. Can someone help me do this?
There are several ways to go about this task. Look over the good solutions fmw42 and snibgo have provided above. Here's another similar approach...

Code: Select all

convert input.png -alpha set -crop 0x67 -bordercolor none -border 0x5 -append -shave 0x5 output.png
That uses "-crop 0x67" to cut your input image into slices of the full width and 67 pixels high. Then it sets the border color to "none" and uses "-border 0x5" to add a 5 pixel transparent border to the top and bottom of each piece. Next it uses "-append" to re-assemble the pieces vertically. It eliminates the extra 5 pixels from the top and bottom of the final image using "-shave 0x5". Then it finishes by giving it an output file name.

If you're using IM7 you would start the command with "magick" instead of "convert".
jwes
Posts: 3
Joined: 2017-08-29T09:04:12-07:00
Authentication code: 1151

Re: Inserting blank lines between parts of an image

Post by jwes »

Thank you all for the help.
Post Reply