Tile image horizontally over a bckground vertically centered

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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tile image horizontally over a bckground vertically cent

Post by fmw42 »

tile the image out to size 500x18 and then composite it over your background using -gravity center.

see
http://www.imagemagick.org/Usage/canvas/#tile
http://www.imagemagick.org/Usage/compose/
http://www.imagemagick.org/Usage/layers/#convert

so

convert background \( -size 500x18 tile:image2tile \) -gravity center -compose over -composite result

In Windows, leave off the two \
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Tile image horizontally over a bckground vertically cent

Post by anthony »

A double backslash is probably because you are using a PHP system call in double quotes.

That API method results in the command being parsed 3 times, PHP, Shell and by IM.

See PHP using Shell Commands, Watch the extra quotes
http://www.imagemagick.org/Usage/api/#php_quotes
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tile image horizontally over a bckground vertically cent

Post by fmw42 »

now i only need to figure out how to tile it for 100% of the destination image (that is the background) width as it is not always 500 px wide
I do not believe there is any way to do that automatically in IM6. (IM7 will likely allow that). You will have to extract the background image width in a separate command and then feed that as a variable to the -size $(Width)x18.

Alternately, make the width larger than any image you want to use. The composite should automatically crop it to fit the background image.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Tile image horizontally over a bckground vertically cent

Post by anthony »

fmw42 wrote:
now i only need to figure out how to tile it for 100% of the destination image (that is the background) width as it is not always 500 px wide
I do not believe there is any way to do that automatically in IM6. (IM7 will likely allow that).
You can do this in IMv6 by using -distort viewports and virtual pixels to do the tiling..
For example tiling a "rose:" image, across the center of a "logo:" image

Code: Select all

convert logo: -set option:my:width '%[w]'  \
            \( rose: -set option:distort:viewport '%[my:width]x%[h]' \
               -virtual-pixel tile -filter point -distort SRT 0 \) \
            -gravity center -composite show:
Note the first -set is to save the width of the background logo image as a global option so it is available when defining the viewport using the second -set.

EXTRA: if you want to 'roll' the tiled image, you can set offsets to the viewport!



IMv7 will eventually allow you to do the tile much more directly...
For example this will eventually work (but doesn't at this time)

Code: Select all

    magick logo: rose: -size '%wx%[fx:v.h]' +delete \
           tile:rose:  -gravity center -composite  show:
at the moment you can not use % escapes with settings like -size, only with operators.... :-(
Also there is plans for proper 'tiling' operator that uses in-memory images!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply