Script to block out text on an image
This command works just fine:
convert T.jpg \( +clone -draw 'rectangle 32,20,178,55' \) -composite conv-T.jpg It draws a black rectangle in the top left hand corner, 32px down and 20px across. I want to use this in a script: convert T.jpg \(+clone -draw 'rectangle $X,$Y,$XX,$YY' \) -composite conv-T.jpg I've set the values and this is what happens onk@XEON4 ~/TEST/PIC/PIC $ X=32 onk@XEON4 ~/TEST/PIC/PIC $ XX=178 onk@XEON4 ~/TEST/PIC/PIC $ Y=20 onk@XEON4 ~/TEST/PIC/PIC $ YY=55 convert T.jpg \(+clone -draw 'rectangle $X,$Y,$XX,$YY' \) -composite conv-T.jpg convert: unable to open image `(+clone': No such file or directory @ error/blob.c/OpenBlob/2712. convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501. convert: non-conforming drawing primitive definition `rectangle' @ error/draw.c/DrawImage/3190. convert: unable to parse expression `)' @ error/convert.c/ConvertImageCommand/601. onk@XEON4 ~/TEST/PIC/PIC $ Any help much appreciated |
Try using echo?
Code:
convert T.jpg \(+clone -draw 'rectangle $X,$Y,$XX,$YY' \) -composite conv-T.jpg Code:
echo convert T.jpg \(+clone -draw 'rectangle $X,$Y,$XX,$YY' \) -composite conv-T.jpg Try using double quotes? This allows variables to parse Code:
'rectangle $X,$Y,$XX,$YY' Code:
"rectangle $X,$Y,$XX,$YY" |
Quote:
Thanks for trying tho'. |
After a bit of digging around using DuckDuckGo (https://duckduckgo.com/) I figured this line out to blur a specified rectangle on an image.
convert Test.jpg -region ${W}x${H}+${x}+${y} -blur 0x8 conv-Test.jpg Then I wrote this script - Blur-Image.sh #!/bin/bash renice 19 -p $$ bold=$(tput bold) norm=$(tput sgr0) # default="*.mts" # read -p "Movie To Png [$default]: " FileName # FileName=${FileName:-$default} read -p "Files to process (name only): " FileName default="jpg" read -p "Files extension (${bold}$default${norm}|png|...): " Extension Extension=${Extension:-$default} default="0" read -p "Width(${bold}$default${norm}): " W W=${W:-$default} default="0" read -p "Height(${bold}$default${norm}): " H H=${H:-$default} default="0" read -p "Top Corner from left hand side(${bold}$default${norm}): " x x=${x:-$default} default="0" read -p "Top corner from top(${bold}$default${norm}): " y y=${y:-$default} convert $FileName*.$Extension -region ${W}x${H}+${x}+${y} -blur 0x8 conv-$FileName.$Extension exit 0 Feel free to copy and use yourself. Thanks everyone. |
Thanks for Blur-Image.sh.
Regarding your initial question, give the following a try: Code:
convert T.jpg \(+clone -draw "rectangle '$X','$Y','$XX','$YY'" \) -composite conv-T.jpg |
Quote:
Here's the screendump onk@XEON4 ~/TEST/PIC/PIC $ ls *T*.* T.jpg T.sh onk@XEON4 ~/TEST/PIC/PIC $ echo $X $XX $Y $YY 30 178 15 55 onk@XEON4 ~/TEST/PIC/PIC $ convert T.jpg \(+clone -draw "rectangle '$X','$Y','$XX','$YY'" \) -composite conv-T.jpg convert: unable to open image `(+clone': No such file or directory @ error/blob.c/OpenBlob/2712. convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501. convert: non-conforming drawing primitive definition `rectangle' @ error/draw.c/DrawImage/3190. convert: unable to parse expression `)' @ error/convert.c/ConvertImageCommand/601. Putting the actual values in and running your suggestion also does not work onk@XEON4 ~/TEST/PIC/PIC $ convert T.jpg \(+clone -draw "rectangle 30,15,178,55" \) -composite conv-T.jpg convert: unable to open image `(+clone': No such file or directory @ error/blob.c/OpenBlob/2712. convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501. convert: unable to parse expression `)' @ error/convert.c/ConvertImageCommand/601. This is what does work: onk@XEON4 ~/TEST/PIC/PIC $ convert T.jpg \( +clone -draw 'rectangle 30,15,178,55' \) -composite conv-T.jpgjonk@XEON4 ~/TEST/PIC/PIC $ All I want to know is how to parameterise the rectangle co-ords in a bash script, it shouldn't be this hard surely? |
Quote:
Code:
coordinates="rectangle 30,15,178,55" |
Quote:
I'll post the script later Many thanks |
Quote:
onk@XEON4 ~/TEST/PIC/PIC $X=30;XX=178;Y=15;YY=55 onk@XEON4 ~/TEST/PIC/PIC $ convert T.jpg \( +clone -draw "rectangle $X,$Y,$XX,$YY" \) -composite conv-T.jpg onk@XEON4 ~/TEST/PIC/PIC $ |
So here's a script that does work and draws a black rectangle of a specified height and width with the top left hand corner at a specified distance from the top left hand corner of the image
black-rectangle.sh ================== #!/bin/bash renice 19 -p $$ bold=$(tput bold) norm=$(tput sgr0) read -p "Files to process (name only): " FileName default="jpg" read -p "Files extension (${bold}$default${norm}|png|...): " Extension Extension=${Extension:-$default} default="0" read -p "Width(${bold}$default${norm}): " W W=${W:-$default} default="0" read -p "Height(${bold}$default${norm}): " H H=${H:-$default} default="0" read -p "Top Corner from left hand side(${bold}$default${norm}): " x x=${x:-$default} default="0" read -p "Top corner from top(${bold}$default${norm}): " y y=${y:-$default} convert $FileName.$Extension \( +clone -draw "rectangle $W,$H,$x,$y" \) -composite conv-$FileName.$Extension exit 0 Feel free to use it I would like to alter the colour of the rectangle tho', over to you smart fellers for that one.... |
Quote:
Quote:
|
Quote:
convert $FileName.$Extension \( +clone -fill grey59 -draw "rectangle $X,$Y,$XX,$YY" \) -composite conv-$FileName.$Extension Works perefectly |
Welcome to LQ GPGAgent!
Glad that you found help, and thanks to those who replied! In future, please place your code and command snippets inside [CODE]...[/CODE] tags for better readability. You may type those yourself or click the "#" button in the edit controls. Thanks! |
Quote:
From now on my code will look like Code:
CODE=10 PHP Code:
:D |
All times are GMT -5. The time now is 08:55 AM. |