dongyi5070 2014-10-07 07:48
浏览 23
已采纳

我可以使用imagemagick从右侧复合吗?

In this normal case, when we need to composite a image on another image, we use :

exec("convert  1.jpg  2.jpg  -geometry +0+0 -compose DstOver -composite result.jpg);

and 0,0 points are the start line in left site of picture. I need to use my points from right side for example i have a jpg file with 500px height and 500px width and i need to composite image2 from 500,0 . its not good because if your image2 file has 100px in 100px height and width, your result hasn't any change in view.

my goal is compose from right side of image because my image2 has different width and height every time.

enter image description here

i mean i need compose from 3 and 4 point like picture. I try Imagemagick place image in bottom right corner but this solution compose with SouthEast , SouthWest and ... I need use my geometry size and points..

enter image description here

With image with fixed size i do not have any problem but i create text with imagemagick and it may with 1 charachter or more and in in this case my width of png text has different size.

Edit : In fact i get text from input and with different length then compose with background picture like:

enter image description here

ok, i need compose with right corner of "Sample Text 2" like picture, not left like "Text1" when i create text png file it may be created by different width and height . (sorry i can't explain better and sorry for my bad english)

  • 写回答

1条回答 默认 最新

  • douji0073 2014-10-07 12:29
    关注

    Edited

    Ok, I am getting closer to understanding what you want, First observation is that if you specify -gravity then the offset in the geometry is relative to the gravity - it moves the overlaid image INWARDS from the gravity corner by the amount you specify in the geometry offset. So let's start by setting the gravity to NorthEast to put the overlay in the top-right corner:

    convert background.jpg overlay.jpg -gravity northeast -composite out.jpg
    

    Now let's get the width of the overlay and use it to calculate the geometry you require, assuming you want the overlaid image to have its right edge 50 pixels in from the background's right edge:

    geom=$(convert overlay.jpg -print "+%[fx:w+50]+0" null:)
    
    echo $geom   # this is just to show what is happening - you don't need it
    +150+0
    
    convert background.jpg overlay.jpg -gravity northeast -geometry $geom -composite out.jpg
    

    Of course you can do that in a single command like this:

    convert background.jpg overlay.jpg -gravity northeast -geometry $(convert overlay.jpg -print "+%[fx:w+50]+0" null:) -composite out.jpg
    

    enter image description here

    Original Answer

    I am sorry, but I still don't understand exactly what you are asking, so I will answer what I think you mean and maybe you can explain what is wrong with my understanding.

    convert -size 500x500! xc:red  background.jpg    # make a big red background
    convert -size 100x100! xc:blue overlay.jpg       # make a smaller blue overlay
    
    # place overlay on image at desired position
    convert background.jpg overlay.jpg -geometry +360+40 -composite out.jpg    
    

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题