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

Re: Tile Image over another Image

Post by fmw42 »

Not quite sure what you are asking? If you want to overlay a transparent image over a pattern, then here is an example:

Transparent Image:
Image

convert \( -size 370x81 tile:pattern:checkerboard \) cairo_banner.png -composite cairo_banner_checks.jpg


Image


see
http://www.imagemagick.org/Usage/compose/
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/script/forma ... n-patterns

You can also create your own background pattern and tile that image (tile:tileimage.gif)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Tile Image over another Image

Post by anthony »

The "composite" command can do this directly. It is about the only function not coversed simply by "convert"

See http://www.imagemagick.org/Usage/compose/#tile

Other methods involve creating the second tiles image the same size of larger and composing as fwm42 did.

Methods for timing an existing image (to get the right size and preserve image meta-data is shown in Canvas Creation...
http://www.imagemagick.org/Usage/canvas/#tile
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 over another Image

Post by fmw42 »

Anthony wrote:The "composite" command can do this directly. It is about the only function not coversed simply by "convert"

See http://www.imagemagick.org/Usage/compose/#tile
Thanks for this clue. I was wondering if there was a way to tile without having to expand the tile to the size of the other image. You are right. Too bad you cannot do that with convert. It would make things much easier and more up to date as composite may go away in the future (IM 7?).
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Tile Image over another Image

Post by anthony »

The closest method in convert is to reset all the pixels using

Code: Select all

-tile tile_image -draw 'color 0,0 reset'
Its one of the methods listed
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 over another Image

Post by fmw42 »

OK. I see that now. The problem is that I want to use the virtual canvas info in the image I want to overlay on the tile background. Thus I guess I need to use -flatten.

This seems to work where frame [0] is 300x300 and frame [1] is 128x128+86+86

convert test1_transback.psd[0] -tile ps_checks.gif -draw "color 0,0 reset" \
test1_transback.psd[1] -flatten test1_transback_tile.jpg


It would be kind of neat is one could do the same with gradient to match the size of the input image as in your tile example.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Perfect Gradients in image

Post by anthony »

A little off topic... BUT (note change of subject).
fmw42 wrote:It would be kind of neat is one could do the same with gradient to match the size of the input image as in your tile example.
You can... It is called -sparse-color!!!!

Two point Barycentric to be precise!

IM automatically calculates the third point needed so that a linear gradient is place between the two points with the gradient perpendicular to the line between the two points. But you can create a your own thrid point using the same color as one of the other two to set the 'angle' of the gradient.

It takes percent escapes too, so you can specify the image size! How about one across the image...

Code: Select all

   convert rose:     -sparse-color Barycentric '0,0 black  %w,0 white'     horizonal_gradient.png
That by the way is a perfect mathematical gradient across the image, using 'image coodinates', so that the color points are positioned at the exactly image edge. As such the fist and last pixel is not actually exactly white or black.

Gradient however calculates using 'pixel coodinates' from top row of pixels to bottom row of pixels, which if you remember was why you had 'noise' in your FFT transforms of your gradient -> sine_evaluate -> FFT results. The starting gradient was not 'mathematically perfect and thus not 'tileable' as it was one pixel short!

To get EXACTLY the same as gradient: (vertical) with the same image size, you need to specify pixel locations using 'image coordinates.

Code: Select all

  convert rose:     -sparse-color Barycentric '0,0.5 white  0,%[fx:h-0.5] black'     rose_gradient.png
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply