This was a short bash script I wrote to help document some startup problems on a server.
The script was grabbing screen dumps from iDRAC during boot on a RHEL6 server, but it can be used on other distributions as well since the console command xwd is common.
#!/bin/bash
# Description:
# Grab screenshot of a specified X-window and wait X-seconds
# Use xwininfo to find the Window id to the window you are going to
# grab screenshots from.
xwininfo="0x4c0001a"
# filename for output
outfile="outfile-"
# seconds sleep between grabs
sleeping=2
padding="000" # put as many padding zeros as you want on filename
for ((i=0; i<1000; i+=1))
do
# Perform the actual screenshot grab
xwd -id $xwininfo -out $outfile-${padding:${#i}}$i.xwd
# Convert the xwd file to a better image format like PNG
convert $outfile-${padding:${#i}}$i.xwd $outfile-${padding:${#i}}$i.png
# Delete the converted XWD-file
rm -f $outfile-${padding:${#i}}$i.xwd
# wait
sleep $sleeping
done
Stop the script after you have grabbed enough screenshots.
I ended up with several files named outfile-000.png outfile-001.png ...
Deleted those files that were not needed and sent the images a documentation of the booting process.
Tags: bash, convert, PNG, windowid, wxd
Posted by Hans-Henry Jakobsen
This is a short example of how to extract images from a PDF file using ImageMagick
# convert thePDFfile.pdf page-%03d.png # ls page* page-000.png page-001.png page-002.png
Imagemagick can also be used to create Adobe Acrobat PDF documents
convert DSC* resultFile.pdf
The resultfile contains one image per page.
Tags: convert, imagemagick, pdf
Posted by Hans-Henry Jakobsen
This is a modified version of my Resize of images in a folder with imagemagick post back in February. Only difference this time is that i strips out EXIF tags and the script has been cleaned up a bit. Click on the image to see the result in full size.
#!/bin/bash
# Description:
# Script to resize JPG images to desired width defined in IMAGESIZE variable.
# EXIF tags is also removed from the result images.
# Software needed:
# jhead - http://www.sentex.net/~mwandel/jhead/
# imagemagick - http://www.imagemagick.org
IMAGESIZE="320 480"
for IMAGEFILE in $(ls|grep JPG)
do
for I in $IMAGESIZE
do
# create directories if needed
if [ ! -d $I ]
then
mkdir $I
fi
# Strip EXIF tag information from source file
jhead -purejpg $IMAGEFILE
# Resize file
base=`basename $IMAGEFILE .JPG`_Resized_$I.JPG
convert $IMAGEFILE -resize $I $base
# Watermark the file
width=`identify -format %w $base`
convert -background '#0008' -fill white -gravity center -size ${width}x15 \
-font Verdana -pointsize 10 \
caption:"Copyright © 2007 Pario.no" \
+size $base +swap -gravity south -composite $I/$base;
# delete resized file
rm $base
done
# Delete source file (DO NOT USE YOUR ORIGINAL FILE!)
rm $IMAGEFILE
done
You can download my resize, watermark bash script here.
Tags: bash, convert, imagemagick, jhead
Posted by Hans-Henry Jakobsen
This bash script adjusts images to fit in a digital frame with a resolution of 480×234 pixels however by using the size 832×468 pictures are displayed sharper on some frames. Normally, narrower pictures will have black borders at both sides when displayed. but this script makes the border color the average of the picture.
The following linux tools are used in the script: convert and montage, bash, od and awk. od is part of the textutils package in Debian.
#!/bin/bash
# current directory contains source JPG files
# $DESTINATION is where the prepared JPG files are stored
# $TEMP is a temporary directory
TEMP=TEMP
DESTINATION=DESTINATION
GEO=832x468 # geometry of target JPG files and resize value
for FILE in *.JPG
do
convert -resize 1x1 "$FILE" "$TEMP/1x1.bmp"
od -A n -j 54 -t u1 "$TEMP/1x1.bmp" | awk -v f="$FILE" -v des="$DESTINATION/" -v geo="$GEO" '
{
print "montage -geometry", geo, "-resize", geo, "-background rgb\\(" $3 \
"," $2 "," $1 "\\) \"" f "\" \"" des f "\"";
exit;
}'
done | sh -x
Source: comp.graphics.misc
Tags: awk, bash, convert, Debian, montage, od
Posted by Hans-Henry Jakobsen
Today I stumbled upon Fred’s Imagemagick Scripts, a nice collection of bash scripts to do image manipulations like
Tags: convert, imagemagick
Posted by Hans-Henry Jakobsen