Page 1 of 1

Using FX to create a custom transparency mask

Posted: 2017-05-24T04:19:58-07:00
by Karen
Hello,

Thx to the documentation, I was able to create a mask of transparency gradient.
I have been tweaking the function but I have a really hard time to understand what I am doing.
The end state I want to reach is being able to produce a mask that will be used to produce a frame (so, to keep the borders of a given image) and the frame will not be symetrical.
My strategy is to produce bottom, top, right and left part independently and to fuse them in some way (I also didn't achieve the fuse part yet).

Here is what I achieved for the moment :

Code: Select all

convert -size 700x1200 xc: -channel G  -fx '1-(1-(2*i/w-1)^4)*(1-(2*j/h-1)^4)'  -separate  gradient_fx_quad2.gif
==> produce a symetrical frame

Code: Select all

convert -size 700x1200 xc: -channel G -fx '(2*j/h-1)' -separate  gradient_fx_quad2.gif    
==> produce the bottom part of the frame

What I am looking into doing is having an fx function where I can put my own measures (the size of the width of the transparency fading).

Any pointer or comment would be useful.

Re: Using FX to create a custom transparency mask

Posted: 2017-05-24T10:10:20-07:00
by fmw42
I am not sure what you are trying to achieve when you say not symmetric. Can you show us an example of what you want from somewhere else or a picture and explain what you want where? Also please always provide your IM version and platform/OS.

But have you see the -frame function at http://www.imagemagick.org/Usage/crop/#frame or the framing examples at http://www.imagemagick.org/Usage/thumbnails/#frame_edge or the -vignette function http://www.imagemagick.org/Usage/transform/#vignette or the gradient: and radial-gradient: functions http://www.imagemagick.org/script/gradient.php

Re: Using FX to create a custom transparency mask

Posted: 2017-05-26T00:35:42-07:00
by Karen
Hi,

Thx a lot for the answer.
I have been reading the pointers you gave and the more close to what I am trying to do is http://www.imagemagick.org/Usage/thumbnails/#frame_edge. Unfortunately, it seems overcomplicated for what I want to achieve.

I should have been more explanative regarding the not symetrical part.
I have been drawing a little scheme hoping I have been given enough information. (I have put the files on a hosting website as I don't know how to load them in the post, I am aware of this being detrimental for ppl reading in the future when the hosting website will be down, don't hesitate to indicate me how to put it on the post)
https://ibb.co/ffhoFv
I am trying to create a frame from an image which is already the size of the final document. I am trying to "cut" this image with an internal rectangular so that I keep only the "around part", the frame. For the moment, I am able to get this frame but my issue is that I cannot make it asymetrical : larger on the top and the right rather than on the bottom and the left sides (see B on the drawing). Ideally, I would like to be able to put as input the measures that I want. Something like " -fx '3 on the top, 1 on the bottom, 2 on the right, 1 on the left'" (the numbers designate the number of squares on the drawing attached to this post, but it could be in pixels).
I have been able to produce the symetrical frame (A on the drawing), here is the result :
https://ibb.co/jqnuoF

IM version is 6.7.7-10 2017-03-14 Q16 and I am using Ubuntu.

Re: Using FX to create a custom transparency mask

Posted: 2017-05-26T10:10:38-07:00
by fmw42
This forum does not allow uploading images. So you have done the correct thing.

Here is one way to do this. Create a black image a little larger than you want (in this case 20 pixels on each side). The blur it so that you get a white ramping from the outside to black on the inside. Then crop it the size you want using -gravity on the appropriate corner to have it larger on the top and right. Then put that into the alpha channel of your image. Here is the IM 6 approach. (Note, I believe that this could be done in one command in IM 7). I have added +write mask.png so that it creates a saved mask image for you to examine. But once you understand, you can remove that code. Adjust as desired. (If you want a linear ramp, then use -blur 25x65000 and adjust the 25 as desired.

Input:
Image

Code: Select all

ww=`convert -ping cyclops_tiled.png -format "%w" info:`
hh=`convert -ping cyclops_tiled.png -format "%h" info:`
wd=$((ww+20))
ht=$((hh+20))
convert cyclops_tiled.png \
\( -size ${wd}x${ht} xc:black -virtual-pixel white -blur 0x25 -auto-level \
-gravity northeast -crop ${ww}x${hh}+0+0 +repage +write mask.png \) \
-alpha off -compose copy_opacity -composite \
cyclops_tiled_masked.png
Mask:
Image

Output:
Image