Use ImageMagick to cut transparent rounded corners in Linux bash (2)

Source: Internet
Author: User

Rounded corner: cutroundcorner
Parameter: $1: edgesize $2: width (I. e. Height) $3: radius $4: srcfilename $5: destfilename
Note: $1 indicates the length of the removed advertising area, $2 indicates the edge length of the final square rounded corner image, and $3 indicates the radius of the rounded corner.
Example: cutroundcorner 20 100 20 1.jpg 1.png

Source codeAs follows:

#! /Bin/bash
# --- $1: edgesize $2: width (I. e. Height) $3: radius $4: srcfilename $5: destfilename ---
Echo "start cutting image $1 ...."
Info = 'identify-format "% wx % H" $4'
Idx = 'expr Index "$ Info" 'X''
Idx_w = $(idx-1 ))
Idx_h = $ (idx + 1 ))
Width = 'expr substr "$ Info" 1 $ idx_w'
Height = 'expr substr "$ Info" $ idx_h 20'
Echo "width: $ width"
Echo "height: $ height"
If ($ width> $ height ))
Then
Echo "width longer"
Cropx = $ ($ width-height)/2 + $1 ))
Cropy = $1
Nsize = $ ($ height-$1*2 ))
Else
Echo "height longer"
Cropx = $1
Cropy = $ ($ height-$ width)/2 + $1 ))
Nsize = $ ($ width-$1*2 ))
Fi
Convert-crop "$ nsize x $ nsize + $ cropx + $ cropy"-resize $ 2x $2! -Roundcorner $3 $4 $5

The effect of the cropped transparent rounded corner is as follows:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.