Change picture to transparent and inserting it into other picture at specific location
-
- Posts: 9
- Joined: 2018-10-01T10:56:30-07:00
- Authentication code: 1152
Change picture to transparent and inserting it into other picture at specific location
Hi all I kind of do not find the right combination
starting point
One jpg with white backround
Task
1 resize that picture to 2973x4460
mogrify -write test1.png -format png -resize 2973x4460 016011.png
2 make the backround of the picture transparent and write it into a different picture resulting in size 3840x5760, center it to left and right, but position it 470 pixel from the top keeping the canvas around the picture
mogrify -write test2.png -format png -gravity center -background transparent -extent 3840x5760 -alpha SET -draw 'image Dst_In 0,0 0,0 "test1.png"' gradiant-grey.jpg
the second command gives me the picture on the background of the gradiant-grey picture, but it is not surrounded by the canvas of the gradiant-grey picture ( It is touching top and bottom )
help !!!!
starting point
One jpg with white backround
Task
1 resize that picture to 2973x4460
mogrify -write test1.png -format png -resize 2973x4460 016011.png
2 make the backround of the picture transparent and write it into a different picture resulting in size 3840x5760, center it to left and right, but position it 470 pixel from the top keeping the canvas around the picture
mogrify -write test2.png -format png -gravity center -background transparent -extent 3840x5760 -alpha SET -draw 'image Dst_In 0,0 0,0 "test1.png"' gradiant-grey.jpg
the second command gives me the picture on the background of the gradiant-grey picture, but it is not surrounded by the canvas of the gradiant-grey picture ( It is touching top and bottom )
help !!!!
Re: Change picture to transparent and inserting it into other picture at specific location
Why are you using mogrify? I would use convert.Use the mogrify program to resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more. This tool is similar to convert except that the original image file is overwritten (unless you change the file suffix with the -format option) with any changes you request.
What Imagemagick version are you using?
Links to input images are always helpful.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Change picture to transparent and inserting it into other picture at specific location
"mogrify" is used when you have a number of input images, and the same sequence of operations to apply to each input, making the same number of output images.
It isn't used for combining multiple inputs into a single output. For that, use "convert" for IM v6, or "magick" for IM v7.
It isn't used for combining multiple inputs into a single output. For that, use "convert" for IM v6, or "magick" for IM v7.
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: Change picture to transparent and inserting it into other picture at specific location
We could help more if we had your input images. Can you post them to some free hosting service and put the URLs here. Then we can provide a single convert command line to do all that you want. You say you are starting with one white JPG, but your first command show you resizing a PNG image. Please clarify.
_________________________
Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.
See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620
If using Imagemagick 7, then see http://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
_________________________
Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.
See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620
If using Imagemagick 7, then see http://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
-
- Posts: 9
- Joined: 2018-10-01T10:56:30-07:00
- Authentication code: 1152
Re: Change picture to transparent and inserting it into other picture at specific location
mogrify version 7.0.7-11
i cant find a way to attach the pictures
i cant find a way to attach the pictures
-
- Posts: 9
- Joined: 2018-10-01T10:56:30-07:00
- Authentication code: 1152
Re: Change picture to transparent and inserting it into other picture at specific location
Ok I am starting with
picture 016011.jpg , i have resized it and changed the background to transparent thats why I used png
( convert 016011.jpg -format png -resize 2973x4460 -fuzz 30% -transparent white 016011.png)
http://www.../016011.jpg
http://www..../gradiant-grey.jpg
In the end I want to have a jpg
picture 016011.jpg , i have resized it and changed the background to transparent thats why I used png
( convert 016011.jpg -format png -resize 2973x4460 -fuzz 30% -transparent white 016011.png)
http://www.../016011.jpg
http://www..../gradiant-grey.jpg
In the end I want to have a jpg
Last edited by cookie2000 on 2018-10-21T12:01:41-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Change picture to transparent and inserting it into other picture at specific location
Does this do what you want?
Unix syntax and IM 7 code.
You never answered my question about your platform?
see
https://imagemagick.org/Usage/compose/#compose
https://imagemagick.org/Usage/basics/#parenthesis
https://imagemagick.org/Usage/layers/#convert
IM 7 can do inline computations. So my +"%[fx:(u.w-v.w)/2]+470" computes the horizontal center relative to the top left corner (northwest) and then positions it 470 px down from the top.
Unix syntax and IM 7 code.
Code: Select all
magick gradiant-grey.jpg \( 016011.jpg -resize 2973x4460 -fuzz 30% -transparent white \) -gravity northwest -geometry +"%[fx:(u.w-v.w)/2]+470" -compose over -composite result.jpg
see
https://imagemagick.org/Usage/compose/#compose
https://imagemagick.org/Usage/basics/#parenthesis
https://imagemagick.org/Usage/layers/#convert
IM 7 can do inline computations. So my +"%[fx:(u.w-v.w)/2]+470" computes the horizontal center relative to the top left corner (northwest) and then positions it 470 px down from the top.
-
- Posts: 9
- Joined: 2018-10-01T10:56:30-07:00
- Authentication code: 1152
Re: Change picture to transparent and inserting it into other picture at specific location
I am currently working o a mac, but i will be doing this on ubuntu linux
it is looking nice, have to test it tomorrow on a couple of pictures, thanks a million so far
it is looking nice, have to test it tomorrow on a couple of pictures, thanks a million so far
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Change picture to transparent and inserting it into other picture at specific location
My command was tested on my Mac OSX Sierra. It should run fine from Linux also provided both are using IM 7. IM 6 does not allow inline computations. So that would need to be an extra command that put the computation into a variable that would then be used in the -geometry setting. If needed I can post my result for you.
-
- Posts: 9
- Joined: 2018-10-01T10:56:30-07:00
- Authentication code: 1152
Re: Change picture to transparent and inserting it into other picture at specific location
I have done this successfully, however on colourpicture the pictures get dull
the picture is fine while resizing it, but after the compose over composite, the colours are not as before, any idea ?
the picture is fine while resizing it, but after the compose over composite, the colours are not as before, any idea ?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Change picture to transparent and inserting it into other picture at specific location
Post your input and output images and your exact command line.
-
- Posts: 9
- Joined: 2018-10-01T10:56:30-07:00
- Authentication code: 1152
Re: Change picture to transparent and inserting it into other picture at specific location
ok as before
pictures are here
www.../gradiant-grey.jpg
(i am using this gradiant grey, only because I am not able to change the background to colour #E9EDEE and have the size to 3840x5760 )
www.../4060715278916-0.png
magick ./gradiant-grey.jpg \( "4060715278916-0.png" -transparent white -trim +repage -gravity center -resize 3840x4460 +repage -transparent white \) -format jpg -strip -gravity northwest -geometry +"%[fx:(u.w-v.w)/2]+470" -compose over -composite test.jpg
i trin and repage it ( as I want the item from the picture to be exact 4460 pixels in height )
the red looks dull after this procedure
pictures are here
www.../gradiant-grey.jpg
(i am using this gradiant grey, only because I am not able to change the background to colour #E9EDEE and have the size to 3840x5760 )
www.../4060715278916-0.png
magick ./gradiant-grey.jpg \( "4060715278916-0.png" -transparent white -trim +repage -gravity center -resize 3840x4460 +repage -transparent white \) -format jpg -strip -gravity northwest -geometry +"%[fx:(u.w-v.w)/2]+470" -compose over -composite test.jpg
i trin and repage it ( as I want the item from the picture to be exact 4460 pixels in height )
the red looks dull after this procedure
Last edited by cookie2000 on 2018-10-21T12:02:10-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Change picture to transparent and inserting it into other picture at specific location
try this where I resize only according to the height and let the width be in proportion. (note I have written a tmp.png file to show you the height of the resize dress image)
magick ./gradiant-grey.jpg \
\( "4060715278916-0.png" -transparent white -trim +repage -gravity center \
-resize x4460 +repage -transparent white +write tmp.png \) \
-format jpg -strip -gravity northwest -geometry "+%[fx:(u.w-v.w)/2]+470" -compose over -composite \
test.jpg
magick ./gradiant-grey.jpg \
\( "4060715278916-0.png" -transparent white -trim +repage -gravity center \
-resize x4460 +repage -transparent white +write tmp.png \) \
-format jpg -strip -gravity northwest -geometry "+%[fx:(u.w-v.w)/2]+470" -compose over -composite \
test.jpg
-
- Posts: 9
- Joined: 2018-10-01T10:56:30-07:00
- Authentication code: 1152
Re: Change picture to transparent and inserting it into other picture at specific location
the tmp.png is still perfect but the test.jpg, the brightness of the red color for example is different
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Change picture to transparent and inserting it into other picture at specific location
Looks fine for me. Post your resulting image so we can see how different it is. What is your exact Imagemagick version and platform/OS?
will show what we need.
Also what is your jpg and png versions. You can get those from
The issue could be in one of those delegate libraries that might be old and need upgrading.
Code: Select all
magick -version
Also what is your jpg and png versions. You can get those from
Code: Select all
magick -list format