New to Imagemagick, need something to be clarified
New to Imagemagick, need something to be clarified
Hello,
I am very new to Imagemagick, trying to understand how the command lines are working, and i am having some trouble.
First, i don't understand what the keyword convert does.
Second, i don't understand how the inputs are handled. How do you transform an image, and put it as an input of another command line ?
For context, if needed, i was trying to merge two pictures with an offset, my simple idea was to crop the one that will be overlayed, and append the result with the other image i need to merge with. So the cropped command is like this
magick convert -crop image1.png 1500x534+0x0 crop.png (crop from 995 height to 534)
and what i tried when i wanted to append
magick convert -crop image1.png 1500x534+0x0 image2.png -append append.png
This crops image2 as well tho. I tried putting parenthesis, since it seems intuitive, but it doesn't seem to work like that.
On a side note i can recrop image2 to its original size and i get the expected result, but that looks silly ^^
On a side side note, i was also wondering if you could crop an image by x pixels, without having to know the initial resolution of the image
Thanks !
Edit : Well, funny thing, i litteraly found out the smush command is basically exactly what i'm trying to achieve. I Could still use some guidance on the question i raised tho ^^
I am very new to Imagemagick, trying to understand how the command lines are working, and i am having some trouble.
First, i don't understand what the keyword convert does.
Second, i don't understand how the inputs are handled. How do you transform an image, and put it as an input of another command line ?
For context, if needed, i was trying to merge two pictures with an offset, my simple idea was to crop the one that will be overlayed, and append the result with the other image i need to merge with. So the cropped command is like this
magick convert -crop image1.png 1500x534+0x0 crop.png (crop from 995 height to 534)
and what i tried when i wanted to append
magick convert -crop image1.png 1500x534+0x0 image2.png -append append.png
This crops image2 as well tho. I tried putting parenthesis, since it seems intuitive, but it doesn't seem to work like that.
On a side note i can recrop image2 to its original size and i get the expected result, but that looks silly ^^
On a side side note, i was also wondering if you could crop an image by x pixels, without having to know the initial resolution of the image
Thanks !
Edit : Well, funny thing, i litteraly found out the smush command is basically exactly what i'm trying to achieve. I Could still use some guidance on the question i raised tho ^^
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: New to Imagemagick, need something to be clarified
I suggest you remove "convert", because that makes your v7 IM behave like v6, which is usually not wanted.plakar wrote:magick convert -crop image1.png 1500x534+0x0 crop.png
The normal sequence is: read the image, process it, and write it. Your processing is "-crop", and that needs the numbers "1500x534+0+0" to follow immediately. Note the format is "WxH+X+Y" where WHXY are numbers, and the last two are prefixed with "+" or "-". So:
Code: Select all
magick image1.png -crop 1500x534+0+0 crop.png
snibgo's IM pages: im.snibgo.com
Re: New to Imagemagick, need something to be clarified
Thanks, it works when i read the image first indeed. Is reading the image after the process for when you want to apply the process to several images then ?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: New to Imagemagick, need something to be clarified
IM works with lists of images. Most operations ("-crop" etc) operate on all the images in the current list. Open parenthesis "(" starts a new list; close parenthesis ")" ends the list and merges resulting images into the outer list.
So this will crop both images:
If you just want to crop the first image, this will work because "-crop" occurs before the second image is read...
... but if you only want to crop the second image then...
EDIT: corrected typo.
So this will crop both images:
Code: Select all
magick convert image1.png image2.png -crop 1500x534+0+0 +append out.png
Code: Select all
magick convert image1.png -crop 1500x534+0+0 image2.png +append out.png
Code: Select all
magick convert image1.png ( image2.png -crop 1500x534+0+0 ) +append out.png
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: New to Imagemagick, need something to be clarified
See parenthesis processing at https://imagemagick.org/Usage/basics/#parenthesis
For novices, see
http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli
For novices, see
http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli
Re: New to Imagemagick, need something to be clarified
Oh ok, i get where my problem was from. I thought parenthesis weren't a thing because i tried to use them with and without escaping them with \ but you actually escape parenthesis with ` in powershell.snibgo wrote: ↑2019-06-08T16:10:07-07:00 IM works with lists of images. Most operations ("-crop" etc) operate on all the images in the current list. Open parenthesis "(" starts a new list; close parenthesis ")" ends the list and merges resulting images into the outer list.
So this will crop both images:If you just want to crop the first image, this will work because "-crop" occurs before the second image is read...Code: Select all
magick convert image1.png image2.png -crop 1500x534+0+0 +append out.png
... but if you only want to crop the second image then...Code: Select all
magick convert image1.png -crop 1500x534+0+0 image2.png +append out.png
EDIT: corrected typo.Code: Select all
magick convert image1.png ( image2.png -crop 1500x534+0+0 ) +append out.png
Thanks for the explanation, and the clue, now i actually understand how all that works ! Much clearer now
fmw42 wrote: ↑2019-06-08T16:40:06-07:00 See parenthesis processing at https://imagemagick.org/Usage/basics/#parenthesis
For novices, see
http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli
Thanks, i will be sure to check those links out (first one is dead tho)
Re: New to Imagemagick, need something to be clarified
Well i have another question if i may (sorry for the double post, i don't really see where rules are listed).
Isn't an offset of the form +x+y ? The second part (+y) doesn't seem to have any influence on the result of smush, even if it does seem to be grammatically correct
Isn't an offset of the form +x+y ? The second part (+y) doesn't seem to have any influence on the result of smush, even if it does seem to be grammatically correct
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: New to Imagemagick, need something to be clarified
The offset in "-smush" should be a simple number, like 4 or -6. It could be floating-point but that will be rounded to an integer.
snibgo's IM pages: im.snibgo.com
Re: New to Imagemagick, need something to be clarified
Offset is always a single number ? Isn't there a simple (inbuilt?) way to overlay an image on top of another with just an x and y axis value then (with pixel as a measure) ?
Edit : i'm guessing i should try and search for something with layers
Edit 2 : Ok, seems like what i'm trying to use is actually composite with -displace or -geometry option, but i'm not able to understand how it works.
Tried
On a side note, the documentation https://imagemagick.org/script/composite.php put the process action composite before reading the images, like that :
isn't the reading supposed to be before ?
Edit : i'm guessing i should try and search for something with layers
Edit 2 : Ok, seems like what i'm trying to use is actually composite with -displace or -geometry option, but i'm not able to understand how it works.
Tried
Code: Select all
magick 1.png 2.png composite -displace +100+100 out.png
Code: Select all
magick 1.png 2.png composite -displace 0x0+100+100 out.png
Code: Select all
magick composite -gravity center smile.gif rose: rose-over.png
isn't the reading supposed to be before ?
Re: New to Imagemagick, need something to be clarified
deleted (can't find how to delete)
Edit : Finally found a way to achieve it
I create a transparent canvas of the size of rectangle surrounding the overlapping images, put the first image (with a possible offset if i don't want it to be attached to the top left corner, which would come just after the "1.png"), compose it, and add the second image with the offset needed and compose it with the first composition.
Would be cool if there was a command that does that automatically tho, something like
Edit : Finally found a way to achieve it
Code: Select all
magick `( `( -size <xFinal>x<yFinal> xc:none `) 1.png -composite `) 2.png -geometry +<xOffset>+<yOffset> -composite out.png
Would be cool if there was a command that does that automatically tho, something like
Code: Select all
magick overlap source.png destination.png -geometry +x+y output.png
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: New to Imagemagick, need something to be clarified
Note that is the "magick composite" command (no hyphen). Don't confuse that with the "magick" command with a "-composite" (with hyphen) operation.plakar wrote:magick composite -gravity center smile.gif rose: rose-over.png
The syntax for "magick composite" is different to simple "magick". "magick composite" is rather old, and not as powerful as "magick", and is only supplied for backwards compatability. My advice: don't use it.
For placing one image over another, I would usually:
Code: Select all
magick 1.png 2.png -geometry +X+Y -composite out.png
snibgo's IM pages: im.snibgo.com
Re: New to Imagemagick, need something to be clarified
Yeah, the fact that -geometry is before -composite is what confused me for a bit, it's not really an option to the command -composite, but an option to the arguments of the command -composite.
And yeah, your way works for when the output is the same size as 1.png (or when 2.png is inside 1.png), which is not my case, so i have to create a bigger background on which i can then place 1.png and 2.png.
Well, glad i could find a working solution, thanks a lot for the guidance !
And yeah, your way works for when the output is the same size as 1.png (or when 2.png is inside 1.png), which is not my case, so i have to create a bigger background on which i can then place 1.png and 2.png.
Well, glad i could find a working solution, thanks a lot for the guidance !
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: New to Imagemagick, need something to be clarified
In your "final way", the parentheses are harmless but useless, so you can simplify:
Code: Select all
magick -size <xFinal>x<yFinal> xc:none 1.png -composite 2.png -geometry +<xOffset>+<yOffset> -composite out.png
snibgo's IM pages: im.snibgo.com
Re: New to Imagemagick, need something to be clarified
I see, you have to actually kinda read it in reverse to understand more easily what the output is supposed to... output ^^
Well, good to know , thanks
Well, good to know , thanks
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: New to Imagemagick, need something to be clarified
Yes, it was lost some weeks ago and cannot be retrieved. So I will take that out of my list. It was advice how to ask intelligent questions on this forum.(first one is dead tho)