how to expand canvas area of an image in a particular direction

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
laxmi131
Posts: 9
Joined: 2017-04-05T07:01:17-07:00
Authentication code: 1151

how to expand canvas area of an image in a particular direction

Post by laxmi131 » 2017-06-07T08:30:14-07:00

Hi team,
we have a question on if we could expand canvas area of an image in a particular direction.
Here is a screencap of what I’m referring to.
https://www.screencast.com/t/ExB1T9iNFj
(the link can be opened in internet explorer)

Let us know if there is any command with the ImageMagick scripting. Most importantly is the ability to perform percentage based expansion from a particular anchor point/direction.It would be helpful if you can give a "convert" script for expanding canvas area of an image


The IMM version which we use is ImageMagick-6.6.9-Q16 and the ghost script version is gs9.05. We have a limitation and hence we cannot upgrade the IMM version.
Thanks
lakshmi

snibgo
Posts: 11694
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to expand canvas area of an image in a particular direction

Post by snibgo » 2017-06-07T08:42:57-07:00

Code: Select all

convert rose: -gravity East -extent 120%x100% e.png
This extends the image in the x-direction only, putting the image to the east (the right) side of the new image.

I don't know if this works in v6.6.9.
snibgo's IM pages: im.snibgo.com

laxmi131
Posts: 9
Joined: 2017-04-05T07:01:17-07:00
Authentication code: 1151

Re: how to expand canvas area of an image in a particular direction

Post by laxmi131 » 2017-06-08T03:46:03-07:00

Hi ,
Thank you so much for the below code is not working
convert rose: -gravity East -extent 120%x100% e.png
unfortunately the command is not working in v6.6.9

can you please give me an command which will work in 6.6.9

thanks

snibgo
Posts: 11694
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to expand canvas area of an image in a particular direction

Post by snibgo » 2017-06-08T05:25:24-07:00

This might work:

Code: Select all

convert rose: ( +clone -scale 120%x100% -fill White -colorize 100 ) +swap -gravity East -composite out.png
That is Windows CMD syntax. For bash, escape the parentheses: \( and \).
snibgo's IM pages: im.snibgo.com

laxmi131
Posts: 9
Joined: 2017-04-05T07:01:17-07:00
Authentication code: 1151

Re: how to expand canvas area of an image in a particular direction

Post by laxmi131 » 2017-06-08T06:26:46-07:00

Hi ,
Thank you for the reply,
both the above mentioned codes are working . I did a mistake by not replacing Rose ;)

however I would want to expand the image on all side
hence I tried the below command and it is working . All the sides has an equal expansion (top and bottom of equal size , and left and right are of equal size )

Code: Select all

convert "%1"[0] -gravity  center -extent 120%x120% "%2".
Is it possible to expand the top more than the bottom and the sides less than the top but more than the bottom.
in other words can we perform mutilple expansion in one command
.
Please let me know if the above condition can be acheived

snibgo
Posts: 11694
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to expand canvas area of an image in a particular direction

Post by snibgo » 2017-06-08T06:45:32-07:00

You can do as many operations as you want in a single command, eg:

Code: Select all

convert rose: -gravity East -extent 120%x100% -gravity North -extent 100%x130% e.png
snibgo's IM pages: im.snibgo.com

laxmi131
Posts: 9
Joined: 2017-04-05T07:01:17-07:00
Authentication code: 1151

Re: how to expand canvas area of an image in a particular direction

Post by laxmi131 » 2017-06-08T22:34:51-07:00

Thank you so much it is working :)

User avatar
fmw42
Posts: 25029
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to expand canvas area of an image in a particular direction

Post by fmw42 » 2017-06-08T22:57:09-07:00

You can also use +-X+-Y added to the extent. The + sign moves it up and to the left. The - sign moves it down and to the right.

Compare:

Code: Select all

convert rose: -gravity center -extent 200%x200% tmp1.png
with

Code: Select all

convert rose: -gravity center -extent 200%x200%-10-10 tmp2.png
The X and Y are always in pixels.

Post Reply