How to control the size of images and graphics?

I am having trouble setting graphical elements properly. Here is an example:

im1 = Import["http://upload.wikimedia.org/wikipedia/commons/5/5c/London_2010_Tower_Bridge.jpg"]; GraphicsRow[{im1, ImageAdd[im1, Graphics[Disk[]]], Graphics[Disk[]]}] 

example of problems

The circles are both indicated the same, but displayed at different scales, so the chart that tries to show how it works is not very satisfactory. Obviously, one scales to fit the image, but I don’t understand why they do not have the same size. Row is similar to GraphicsRow , but gives me the same problem.

+6
source share
3 answers

The problem arises because on the display the disk used in the mask has a diameter equal to the height of the image, while the stand-alone disk has a diameter equal to the width of the image. You can fix this by specifying the disk size explicitly.

 im1 = Import[ "http://upload.wikimedia.org/wikipedia/commons/5/5c/London_2010_\ Tower_Bridge.jpg"]; disk = Graphics[Disk[], ImageSize -> ImageDimensions@im1 ]; GraphicsRow[{im1, ImageAdd[im1, disk], disk}, Spacings -> 0, ImageSize -> Full] 

enter image description here

+8
source

Another option is to wrap the images in Pane with automatic width and fixed height, for example.

 Row[Pane[#, {Automatic, 200}] & /@ {im1, ImageAdd[im1, Graphics[Disk[]]], Graphics[Disk[]]}] 

scaled to have the dame height

+6
source

There are spaces in the images, but not around the black disk. Knowing the aspect ratio of the imported image (obtained from ImageDimensions) and setting a specific size for GraphicsRow and for the black disk, you can control the appearance:

 GraphicsRow[{im1, ImageAdd[im1, Graphics[Disk[]]], Graphics[Disk[], ImageSize -> 90, ImagePadding -> 15]}, ImageSize -> 360, Spacings -> 0] 
+5
source

Source: https://habr.com/ru/post/903556/


All Articles