Page 1 of 2

Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-01T11:05:43-07:00
by cookie2000
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 !!!!

Re: Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-01T11:23:22-07:00
by Bonzo
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.
Why are you using mogrify? I would use convert.

What Imagemagick version are you using?

Links to input images are always helpful.

Re: Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-01T11:38:35-07:00
by snibgo
"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.

Re: Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-01T12:11:23-07:00
by fmw42
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

Re: Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-01T12:39:20-07:00
by cookie2000
mogrify version 7.0.7-11
i cant find a way to attach the pictures

Re: Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-01T12:48:31-07:00
by cookie2000
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

Re: Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-01T13:39:28-07:00
by fmw42
Does this do what you want?

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
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.

Re: Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-01T13:49:31-07:00
by cookie2000
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

Re: Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-01T15:02:58-07:00
by fmw42
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.

Re: Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-19T11:03:11-07:00
by cookie2000
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 ?

Re: Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-19T11:15:57-07:00
by fmw42
Post your input and output images and your exact command line.

Re: Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-19T12:29:04-07:00
by cookie2000
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

Re: Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-19T12:38:50-07:00
by fmw42
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

Re: Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-19T12:55:12-07:00
by cookie2000
the tmp.png is still perfect but the test.jpg, the brightness of the red color for example is different

Re: Change picture to transparent and inserting it into other picture at specific location

Posted: 2018-10-19T13:26:18-07:00
by fmw42
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?

Code: Select all

magick -version
will show what we need.

Also what is your jpg and png versions. You can get those from

Code: Select all

magick -list format
The issue could be in one of those delegate libraries that might be old and need upgrading.