Need help for round corners and adding layer......

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
derilzemer
Posts: 21
Joined: 2011-12-12T12:18:16-07:00
Authentication code: 8675308

Need help for round corners and adding layer......

Post by derilzemer »

Hi @ all,
first my english isn't good but i hope i can explain it in the rigth words.
More than a year ago i got help from this forum for an problem with convert & crop. The Solution that i got for my problem works great.
We use inside a script the following string:

Code: Select all

echo " convert $aktiv_dir/$aktiv_file -crop 2x4\@  +repage -bordercolor black -border 1 -fuzz 95% -trim +repage -quality 100 -resize 32% $aktiv_dir/${datei_name}_%d.png" >>doit.sh
The result looks like this http://www.derilzemer.de/solution1.htm
But you can see that there is no transparency!
At the first time i do the needed steps for transparency with Gimp and it's very costly :? because
  • Load the pictures into gimp
    adding alpha channel --> CTRL+K
    using square selection with radius 20px for round corners
    invert the selection -->CTRL+I (for transparency)
    delete the invert --> DEL
    export and save as png --> CTRL+Shift+E
After all these steps the result looks like this (look at the corner from the pictures)
http://www.derilzemer.de/example1.htm

Okay after doing these steps for 10 times and a lot of frustration about the the lot of work for 10 pictures and knewing that i have to do all these steps for 4000 pics i need help to script that. A very frindly user from the Gimpforum helps me to do this with Script-Fu inside Gimp.
The big Disadvantage from Gimp is the very very slow worktime :( . A hint from the Gimp forum was that i have to do that with a other programm like ImageMagick. Why not?
viewtopic.php?f=1&t=21309
Okay this link looks like, that it is possible with IM but i doesn't understand it :-( maybe my english isn't good enough. So is there anyone who can help me to understand it or can help me to add it into my existing string??

Code: Select all

echo " convert $aktiv_dir/$aktiv_file -crop 2x4\@  +repage -bordercolor black -border 1 -fuzz 95% -trim +repage -quality 100 -resize 32% $aktiv_dir/${datei_name}_%d.png" >>doit.sh
Thanks a lot for any help
with best regards from Germany
Andreas
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need help for round corners and adding layer......

Post by fmw42 »

Try this

convert 53322_1971_1_.png -bordercolor black -border 1 -fuzz 85% -fill none -draw "matte 0,0 floodfill"-trim +repage -crop 4x2\@ +repage -trim +repage 1tmp_%d.png

You will need to adjust the fuzz value to some compromise between rough edges and leaving some spots from your corners. You can add your other resize commands afterwards.

The extra trim at the end trims any excess transparency around each output image.

Note you also have your crop values backwards, it should be -crop 4x2\@ not -crop 2x4\@

Note -quality 100 is not appropriate for PNG images. See http://www.imagemagick.org/script/comma ... hp#quality
derilzemer
Posts: 21
Joined: 2011-12-12T12:18:16-07:00
Authentication code: 8675308

Re: Need help for round corners and adding layer......

Post by derilzemer »

Hi,
thanks for the quick answer.
Note you also have your crop values backwards, it should be -crop 4x2\@ not -crop 2x4\@.
Note -quality 100 is not appropriate for PNG images. See http://www.imagemagick.org/script/comma ... hp#quality
Thanks for the hints. I forgot to change both after testing with differnt things. Quality default is 75 if i doesn't use quality inside the code, so it is okay for me.
If i use your code i only have transparency but not the final result i want to have :(
Now i tested with the follow that gives me the result but i have to do 2 steps.

Code: Select all

convert 53322_1971_1.png -fuzz 85% -trim +repage -crop 4x2\@ +repage -trim +repage -resize 32% 1tmp_%d.png
After that i use this
convert 1tmp_0.png -alpha set -virtual-pixel transparent -channel A -blur 0x8 -threshold 50% +channel rounded_corner.png
Is there any possibilty that i can use both in one step??

Regards
Andreas
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need help for round corners and adding layer......

Post by fmw42 »

What version of IM are you using? What error or what did not work correctly?

This works just fine for me with IM 6.8.3.8 Q16 Mac OSX Snow Leopard. Each output is 32% smaller and still transparent on the outside.


convert 53322_1971_1_.png -bordercolor black -border 1 -fuzz 80% -fill none -draw "matte 0,0 floodfill" -trim +repage -crop 4x2\@ +repage -trim +repage -resize 32% 1tmp_%d.png

If that is not what you need, please explain further.
derilzemer
Posts: 21
Joined: 2011-12-12T12:18:16-07:00
Authentication code: 8675308

Re: Need help for round corners and adding layer......

Post by derilzemer »

Hi,
fmw42 wrote:What version of IM are you using? What error or what did not work correctly?
Version is 8:6.6.0.4-3+squeeze3 on Debian Squeeze 6.0.7. There are no errors on creating processes.

I use your posted code again and what can i say. I don't know what happend 1 hour before :?

Code: Select all

convert 53322_1971_1.png -bordercolor black -border 1 -fuzz 80% -fill none -draw "matte 0,0 floodfill" -trim +repage -crop 4x2\@ +repage -trim +repage -resize 32% 1tmp_%d.png
the pictures looks pretty good http://www.derilzemer.de/example1.htm
Only if i use a black Background I can see a little pixel failure?! on the right side and the corners at the bottom by most of the cards.
http://www.derilzemer.de/example_black.htm
Is it a problem with a parameter? But it is not dramatically. If there is no possibility to correct this thanks a lot for your expertise and support to my question.

regards from Germany and have a nice weekend
Andreas
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need help for round corners and adding layer......

Post by fmw42 »

The only thing I know to try to fix this is to try using a slightly larger -fuzz value. But you risk getting rough edges around your images, since the fuzzy floodfill may "eat" into the white edges if the fuzz value is too large

Perhaps you can create your original images better so that the corners do not show. Then you can use a smaller fuzz value.

I think it is your process of rounding the corners that is causing this problem. Do you have any control over that?

The only other thing that I can suggest would be to make a mask for the rounded region that is all white inside and black outside. Then use the mask to make the outside perfectly transparent and remove the extraneous corners. But to do that you would have to have consistent size cropped images for all your original images, so that one mask could be used for them all.

If you know the size of the rounding, you can re-round the corners to make the outsides perfectly transparent and remove the extraneous corners. see rounded corners in IM at http://www.imagemagick.org/Usage/thumbnails/#rounded
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Need help for round corners and adding layer......

Post by anthony »

Note that draw draws in a linear colorspace. Which is great for rounding corners with transparency, but can cause slight aliasing when rounding say white foreground on black.

See the notes on this in..
http://www.imagemagick.org/Usage/draw/#colorspace

WARNING: this example was done BEFORE colorspace additions, as such the 'gamma' corrections probably can be more easily handled using colorspace changes.

Also remember greyscale images often get saved in a linear colorspace rather than sRGB colorspace as they generally represent mathematical maps, masks and intermediate images.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply