I use ImageMagick and need to do conditional resize of images.
For that I store results of the identify tool into variables.
$infile='test.jpg'
width=$(identify -ping -format %w $infile)
height=$(identify -ping -format %h $infile)
But before resizing I want to do some transformations that change image size: -trim and -shave. So I need to calculate image size in between of trimming and resizing. And I'd like to do the trim operation only once to make a little optimization.
So, I'd like:
- to do trim and shave
 - store [binary] result in a variable (for example: 
$data) - pass 
$datavariable value as input toidentifytool and store its result for conditional resizing - pass 
$datatoconverttool and finish processing 
Something like this:
data=$(convert logo: -shave 1x1 gif:-)
width=$(echo $data | identify -ping -format %w gif:-)
echo $data | convert -resize "$width"
But echo doesn't work as needed.
P. S. convert and identify are tools from ImageMagick suite