imagemagick snippets

Screenshot in wmii

Tagged wmii, screenshot, linux, imagemagick  Languages bash

Method 1

A simple script to create a screenshot in wmii. It probably works in other window managers too. I call it 'scrot'. Put it in the path and run it as you'd run any program in wmii. The "import" program comes with imagemagick.

#!/bin/bash
import -window root /tmp/screenshot.png

Method 2

If you want timestamped screenshots then

apt-get install scrot
mkdir -p ~/screenshots

And create a script with the following content for making the screenshot.

#!/bin/bash
scrot '%Y-%m-%d-%H-%M-%S_$wx$h_scrot.png' -e 'mv $f ~/screenshots'

Installing ImageMagick, mini-magick and rmagick on Mac OS X Leopard

Tagged imagemagick, attachment_fu, rails, ruby, mac, osx, leopard, mini-magick, rmagick  Languages ruby

I had no success installing ImageMagick and mini-magick with the instructions I found on this page but after some googling I found this blog post, which had the magic commands that worked for me:

sudo port install tiff -macosx  #disables the linkage with Apple's open gl
sudo port install ImageMagick

sudo gem install rmagick
sudo gem install mini_magick

To test mini-magick, open an irb console and paste in the following code:

require 'rubygems'
require 'mini_magick'

path = "public/images/0000/0003/logo.jpg"
image = MiniMagick::Image.new(path)

#print width and height
puts image[:width]
puts image[:height]

Bulk resizing images with Imagemagick.

Tagged imagemagick, bulk resize  Languages bash

Quick and dirty, but handy one-liner that resizes all *.jpg files in the current directory.

for image in *.jpg; do convert $image -resize 800x600 800x600-$image; done

Installing ImageMagick from sources and using xstow to handle the installation.

Tagged xstow, imagemagick  Languages bash

I really hate installing software outside of the package manager, because that is not the way of a stable system. Xstow helps the agony those times that sourceball installations are necessary (e.g for new features). Here's how to install imagemagick with xstow. If you haven't installed xstow yet, then follow the relevant instructions in this snippet

sudo apt-get install libmagick9-dev # needed for sane image support
cd /tmp
wget ftp://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/ImageMagick-6.4.2-7.tar.bz2
tar xjvf ImageMagick-6.4.2-7.tar.bz2
sudo mv ImageMagick-6.4.2 /usr/src
cd /usr/src
sudo ln -s ImageMagick-6.4.2 imagemagick
cd imagemagick
./configure --prefix=/usr/local/stow/imagemagick
make
sudo make install
cd /usr/local/stow
sudo xstow imagemagick

ImageMagick and OpenEXR

Tagged openexr, imagemagick  Languages bash

I could not get OpenEXR delegate to work in ImageMagick. There was no reason for it in config.log. It just silently refused to get configured. I debugged the configure script and found out that PKG_CONFIG was unset. So this fixed it. The --enable-hdri should be optional.

./configure PKG_CONFIG=/usr/bin/pkg-config --prefix=/usr/local/stow/imagemagick --enable-hdri

How to remove a background with ImageMagick

Tagged imagemagick, background  Languages bash

How to remove a random and uniform background from an image:

convert me.jpg -fill none -fuzz 1% -draw 'matte 0,0 floodfill' -flop  -draw 'matte 0,0 floodfill' -flop me.png

This will fill pixels similar in color to the pixel at x=0 and y=0. We use a fuzz setting of 1% to make colors similar to the background transparent.

This method works best on uniform backgrounds and objects with clear boundaries that make it stand out from the background.

Reference: http://www.imagemagick.org/Usage/morphology/\#intro