How to splice on the right side instead of the left

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
LunaEqualsLuna

How to splice on the right side instead of the left

Post by LunaEqualsLuna »

I am trying to splice a white background onto an image i have using the splice command.

convert in.png -background white -splice 200x0 out.png

problem is this adds the white space to the left side and i want it on the right.

I tried messing around with the -gravity option

but the command

convert in.png -gravity East -background white -splice 200x0 out.png

gives an error
convert: geometry does not contain image `in.png'.

and does nothing to the image.

How do i splice on the right side?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to splice on the right side instead of the left

Post by fmw42 »

LunaEqualsLuna wrote:I am trying to splice a white background onto an image i have using the splice command.

convert in.png -background white -splice 200x0 out.png

problem is this adds the white space to the left side and i want it on the right.

I tried messing around with the -gravity option

but the command

convert in.png -gravity East -background white -splice 200x0 out.png

gives an error
convert: geometry does not contain image `in.png'.

and does nothing to the image.

How do i splice on the right side?

This works for me on IM 6.4.5-8 Q16

convert rose: -gravity east -background blue -splice 20x0 splice_right.gif


See if this works for you. What release are you using? Are you sure your input image is valid?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to splice on the right side instead of the left

Post by anthony »

WARNING -spice should normally have a offset.
The command should be...

Code: Select all

  convert rose: -gravity east -background blue -splice 20x0+0+0 splice_right.gif
See IM examples, Splice...
http://www.imagemagick.org/Usage/crop/#splice

If you are interested. -splice was a comunity developed operator added in the early days of IM v6. For details see

Splice: Creating a New Image Operator
http://www.imagemagick.org/Usage/misc/#splice
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: How to splice on the right side instead of the left

Post by fmw42 »

anthony wrote:WARNING -spice should normally have a offset.
The command should be...

Code: Select all

  convert rose: -gravity east -background blue -splice 20x0+0+0 splice_right.gif

Interesting as all of your examples, Anthony, with -gravity do not show offsets??? :?

I thought the offsets were optional and defaulted to +0+0. Is there some reason that this is not the case?
Last edited by fmw42 on 2008-11-18T20:01:23-07:00, edited 1 time in total.
LunaEqualsLuna

Re: How to splice on the right side instead of the left

Post by LunaEqualsLuna »

This works for me on IM 6.4.5-8 Q16

convert rose: -gravity east -background blue -splice 20x0 splice_right.gif


See if this works for you. What release are you using? Are you sure your input image is valid?
I'm using 6.37 on linux.
I'm not sure what you mean by if the input image is valid though.
It is a normal image and and it works fine if i splice it on the left so i guess its valid :?
convert rose: -gravity east -background blue -splice 20x0+0+0 splice_right.gif
is that ':' supposed to be there? if i put that in it says it can't find the file 'in.png:' if i leave it off it gives the same error as before.

is there a workaround this? Can i like splice it on the left and then shift the image to the left? kind of weird that i can splice one side but not the other :?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to splice on the right side instead of the left

Post by fmw42 »

LunaEqualsLuna wrote:
This works for me on IM 6.4.5-8 Q16

convert rose: -gravity east -background blue -splice 20x0 splice_right.gif


See if this works for you. What release are you using? Are you sure your input image is valid?
I'm using 6.37 on linux.
I'm not sure what you mean by if the input image is valid though.
It is a normal image and and it works fine if i splice it on the left so i guess its valid :?
convert rose: -gravity east -background blue -splice 20x0+0+0 splice_right.gif
is that ':' supposed to be there? if i put that in it says it can't find the file 'in.png:' if i leave it off it gives the same error as before.
The rose is a special IM image and needs the colon. If you are getting an error saying in.png does not exist and it is not even in this command line, then you likely have a problem with your system or IM version.

Perhaps IM 6.3.7 had a bug with splice. Have you tried upgrading to the current version?
LunaEqualsLuna

Re: How to splice on the right side instead of the left

Post by LunaEqualsLuna »

fmw42 wrote:
LunaEqualsLuna wrote:
This works for me on IM 6.4.5-8 Q16

convert rose: -gravity east -background blue -splice 20x0 splice_right.gif


See if this works for you. What release are you using? Are you sure your input image is valid?
I'm using 6.37 on linux.
I'm not sure what you mean by if the input image is valid though.
It is a normal image and and it works fine if i splice it on the left so i guess its valid :?
convert rose: -gravity east -background blue -splice 20x0+0+0 splice_right.gif
is that ':' supposed to be there? if i put that in it says it can't find the file 'in.png:' if i leave it off it gives the same error as before.
The rose is a special IM image and needs the colon. If you are getting an error saying in.png does not exist and it is not even in this command line, then you likely have a problem with your system or IM version.

Perhaps IM 6.3.7 had a bug with splice. Have you tried upgrading to the current version?
I will probably try and download the latest version, a quick fix i've done is to rotate the image 180, splice it on the left then rotate it 180 again. Messy for sure, but for now it gets the job done since i'm in a hurry to get something done at the moment. I will check out the latest version and see if i still have this issue tho later.

interestingly i can splice the rose picture on the right side though, so there must be something up with the image i'm using,

edit

I've narrowed it down to using the mogrify -trim command. First i trim the image using mogrify trime, then if i try splice on the right i get an error. if i don't trim, it splices on the right as expected. Is there something else i need to know about mogrify -trim? that would cause this behaviour?

thx for your help!
LunaEqualsLuna

Re: How to splice on the right side instead of the left

Post by LunaEqualsLuna »

Well i sorta solved the problem myself on a hunch by using the -repage command while trimming.

I would be interested though in an explanation as to why NOT using -repage after trimming causes splicing on the right to fail but not the left... I don't like 'fixing' things without really knowing how i fixed them.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to splice on the right side instead of the left

Post by fmw42 »

LunaEqualsLuna wrote:Well i sorta solved the problem myself on a hunch by using the -repage command while trimming.

I would be interested though in an explanation as to why NOT using -repage after trimming causes splicing on the right to fail but not the left... I don't like 'fixing' things without really knowing how i fixed them.
+repage removes any virtual canvas that will occur if you use -crop. So you must use +repage after -crop.

Perhaps your original image had a virtual canvas to begin with. You could try:

convert in.png +repage -gravity East -background white -splice 200x0 out.png
Post Reply