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?".
Sergio
Posts: 3 Joined: 2010-12-27T23:24:13-07:00
Authentication code: 8675308
Contact:
Post
by Sergio » 2010-12-28T13:04:40-07:00
I'm
so close , but the syntax must be off. I'm using the identify command to see the height & width of an image. I then need to see that as a variable so that it can be processed by an If/Then statement. I've tried the following things but they are all wrong. Does anyone know how to output the height & width (separately) so that I can process it with conditional logic?
Code: Select all
#!/bin/bash
identify sand.jpg -format "%f,%w,%h"
echo %w
Code: Select all
#!/bin/bash
identify sand.jpg -format "%f,%w,%h"
echo $%w
Code: Select all
#!/bin/bash
identify sand.jpg -format "%f,%w,%h"
echo $(%w)
Code: Select all
#!/bin/bash
identify sand.jpg -format "%f,%w,%h"
echo $(w)
Code: Select all
#!/bin/bash
identify sand.jpg -format "%f,%w,%h" > $newVariable
echo$newVariable
Code: Select all
#!/bin/bash
newVariable=identify sand.jpg -format "%f,%w,%h"
echo$newVariable
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Contact:
Post
by fmw42 » 2010-12-28T14:04:29-07:00
try either
newVariable=`identify -format "%f,%w,%h" sand.jpg`
or
newVariable=`convert sand.jpg -format "%f,%w,%h"`
note these are not normal quotes, but slanted quotes - same key as the tilde - to the left of the 1 key
or
newVariable=$(convert sand.jpg -format "%f,%w,%h")
or
newVariable=$(identify -format "%f,%w,%h" sand.jpg)
but you will get 3 items in one variable, so you may want to make 3 variables to start
anthony
Posts: 8883 Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia
Contact:
Post
by anthony » 2010-12-28T23:06:38-07:00
A special way of extracting three values (space separated) into three variables in bash is this special bash 'trick'
Code: Select all
read -r file width height <<< $( convert sand.jpg -format "%f %w %h" info:)
echo filename=$file
echo width=$width
echo height=$height
This only works with BASH, not an older bourne shell or ksh or zsh, php, perl etc. JUST BASH.
Other languages have other ways of parsing strings.
Users browsing this forum: Amazon [Bot] , Bing [Bot] , Google [Bot] , Semrush [Bot] and 19 guests