Daily I make an image composition with background (background) in alpha channel in the following dimensions: 558px (length) and 465px (height)


I always have an image with pixels left over that I want to insert in the lower left corner of the image that I usually call img1:


enter image description here

I always have an image with pixels left over that I want to insert in the upper left corner of the image that I usually call img2:

enter image description here

Usually, both images are larger than the area of the final image (background). And I eliminate the background and do a better framing.


I'm trying to make the bottom layer the image "background" file.

The second layer is the img1Fit file in the lower left corner.

And the third layer is the img2Fit file in the upper right corner.

So that the images img1Fit and img2Fit do not overlap and can be resized so that they are in the background.

I tried a code, but it didn't work ...


Expected result (something similar):

enter image description here

Another important information is that the "finalImage" has AlphaChannel = True.

  • $\begingroup$ ImageCompose has other arguments for position. ImageCompose[image,overlay,pos,opos] places the point opos in overlay at position pos in image. $\endgroup$
    – flinty
    Commented Sep 17, 2020 at 20:06
  • $\begingroup$ Try ImageCompose[ImagePad[img1, {{0, 200}, {0, 350}}], img2, {400, 500}] $\endgroup$
    – flinty
    Commented Sep 17, 2020 at 20:10
  • $\begingroup$ Right but that's only dependent on the image sizes which you can figure out with ImageDimensions. Maybe you should use ImageCollage[{img1,img2}] if you need it fully automatic, but the layout is then more up to Mathematica in that case. $\endgroup$
    – flinty
    Commented Sep 17, 2020 at 20:16
  • $\begingroup$ The scale is indifferent. The important thing is that the images do not overlap $\endgroup$
    – LCarvalho
    Commented Sep 17, 2020 at 20:20

1 Answer 1



enter image description here


Show[backgr, img1Fit]


This is a Graphics object and can be saved to image formats i. e. by Export. img1Fit is already cropped and transparent.

Show aligns the size and is able to use different formats of images.

The built-in of choice is


Overlay[{Graphics[{Disk[]}], Slider2D[]}, All, 2, Alignment -> Center]

Overlay of Mathematica 2D objects

Transparency with Overlay:

Overlay[{ExampleData[{"TestImage", "Clock"}], 
  Plot[Cos[x], {x, 0, 6}, 
   Background -> Directive[{Opacity[0.5], LightOrange}]]}, 
 Alignment -> Center]

Transparency with Overlay

It is possible to use Overlay in Manipulate and position and mix images interactively.

The last of the requirements is independent of the rest because Mathematica has a built-in AlphaChannel. Before exporting this built-in can be applied. This too works with 2D and 3D objects designed in Mathematica.

I am using Version 12.0.0.!

I did not receive img2 nor can I derive img2Fit but I was able to do with the variation:

finalImage = 
  backgr, {ImageResize[img1Fit, {232}], 
   ImageResize[img1Fit, {232}]}, {{Left, Bottom}, {Right, Top}}]

enter image description here

 SetAlphaChannel[i, ColorNegate[a]]


a = AlphaChannel[i] enter image description here

SetAlphaChannel[finalImage, ColorNegate[a]]

AphaChannel negated

The problem is that the image is White and only a mask with overlay remains after the negation is processed.




enter image description here

Most interest in AlphaChannel intent to use Adobe products. Google finds a vast amount of community discussion about that topic:

problem AlphaChannel photoshop.

It is well known that Mathematica is somewhat cheap in images. For example if to attempt to upload a sized image output from Mathematica via Export into the Adobe graphics and foto community, Mathematica fails. I expect so that it is the very same with AlphaChannel. Mathematica gains input and advances from libraries that have advantages and disadvantages. This is the same with nearly all other programs offering AlphaChannel. So this can be taken as the sole property behavior of Adobe.

So the workaround of recommendation might be Adobe Capture. But for hard insider, this seems to depend on the license set installed on Your workstation, whether this has impact on the Adobe alpha channel. But Your question is not that detailled. Lost cost can be the idea to save the output into a pdf. Open that in Adobe Acrobat Reader and use the screenshot function in the menu Edit>Take a Snapshot.

If You stay inside the Mathematica influence program sphere this might pose the desired result, but to the Python sphere this might be different and fail.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.