Programmer

Converting .eps to .png Easily

I end up generating a lot of postscript plots in R and other programs. Unfortunately, a lot of not so technical people have trouble opening postscript files so I end up having to convert these images to other formats pretty often. A really handy program for converting eps files to png (or jpg although that’s not really an optimal format for plots) is ImageMagick (available for all OSs I believe). ImageMagick lets you quickly convert (and create thumbnails, make B&W,…) from the command line without having to open up Photoshop.

For example, to convert an image named myPlot.eps to png you just need to enter convert myPlot.eps myPlot.png (convert is a program in the ImageMagick package) at the command prompt and you’ll get a png file in myPlot.png. If you want to adjust the resolution (the default resolution is 72 dpi) of the output image, you can add the -density option (e.g. for 200 dpi convert -density 200 myPlot.eps myPlot.png). Make sure you put the -density part before the input image name.

Converting many files at once is where ImageMagick really shines. The mogrify command is probably the quickest option. For example, to convert the files image01.eps, image02.eps and image03.eps to png, just use the command mogrify -format png image*.eps. In one shot, it will create image01.png, image02.png and image03.png.

Unfortunately, recent version of Imagemagick seem to be treating eps to png conversions oddly (see below) so mogrify isn’t cutting it on my files. If you have similar trouble (and you’re on Unix or Mac or Cygwin), you can just use a bit of Bash combined with the convert command to get around the problem like this:

[bash] for f in `ls *.eps`; do convert -density 100 $f -flatten ${f%.*}.png; done [/bash]

Black Background Problem

As I mentioned above, I started having trouble converting from eps to png after upgrading to ImageMagick 6.4. The transparent/white backgrounds in my eps files were being converted to black backgrounds and making the figures unreadable. I guess it must be some change in how transparency is handled but I’m not totally sure what changed. It took me a bit of googling before I found the solution, so I’ll repost it here. Adding -flatten to the command (e.g. convert myImage.eps -flatten myImage.png) should change the background back to white. My mogrify command doesn’t include the -flatten option so convert (like the example above) seems like the way to go.

Bash/UNIX
Programmer

Comments (17)

Permalink

Making a ‘Restore Disk’ for the Acer Aspire One

Acer Aspire One

We just picked up a little Acer Aspire One netbook. We’re pretty happy with it so far (except we’ll be exchanging it for a new one since the ‘p’ key on this one only works half the time). I’ll probably do a more in depth review once we’ve used it a bit but it certainly is tiny and handy. The only major drawback is the tiny mousepad. Anyway, it doesn’t come with a system restore or Windows disk. I realize there’s a hidden partition on the hard drive but I don’t really like trusting a single hard drive. Google didn’t turn up any really handy answers for how to make a system restore disk from a hidden partition or an entire install (especially onto a USB hard drive) using free software so I thought I’d document what I ended up coming with. I have no idea if this is the smartest/safest way to do this and I’d recommend getting Norton Ghost or something similar if you don’t feel confident with any of the processes in here.

There’s two steps to the process, making a USB drive into a little bootable linux system and backing up the partitions onto a USB hard drive.

Things You’ll Need

  • Some annoying computer with no backup/restore CD
  • USB Key Disk
  • USB Harddrive

I think you could actually just do this with a single harddrive or a really big USB key if you made it into 2 partitions (the SystemRescueCD OS doesn’t save changes by default).

Making a bootable linux USB disk

I used SystemRescueCD for my linux system (although I suppose any small distribution with the appropriate tools would work). Obviously a CD does not do a lot of good when you have a laptop without a CD player but luckily (the somewhat misnamed) SystemRescueCD can be installed to a USB drive. As documented on that page, you’ll need to download the .iso from the SystemRescueCD site and move most of the files from the .iso to your USB drive. If you don’t already have a handy way to mount an .iso and don’t feel like burning a CD, I had decent luck with Microsoft Virtual CD-ROM Control Panel or if you’re using Linux just a simple mount -o loop disk.iso /some/empty/folder (although for some strange reason I had trouble getting a Linux-made version working). Once you’ve copied the files from the CD and ran syslinux as directed, you should have a handy USB key that will boot a computer into linux (if you set the BIOS to boot from USB).

Backing Up Partitions

Once you’ve got your little USB linux, you’ll want to look at Lifehacker’s handy walkthrough to SystemRescueCD. Replace all mentions of CD with USB disk and instead of backing up to the same hard drive, we’ll back up to an additional USB hard drive.

Now from here on out, you’ll want to be very careful. Things should be (mostly) safe but messing around with partitions is getting towards the more touchy end of computing. I’d back up anything important to a separate harddrive. After that, here we go:

  1. Turn off your computer, stick in your USB key drive (not the USB hard drive yet) and press <F12> on startup to set the BIOS to boot from the USB
  2. The SystemRescueCD OS should come up. Hit return at boot: and pick the appropriate keyboard type if it asks.
  3. Once the root@sysresccd /root % prompt comes up, run partimage. Look through the list of partitions. You should see an approximately 5 GiB partition (the hidden restore partition), the big main partition about the size of your harddrive and a small partition about the size of your USB disk. Write down which is which. On my Acer Aspire One, the hidden partition shows up as fat32 on sda1, the main windows partition as ntfs on sda2 and my USB disk plugged in the left USB port as sdb1. Exit partimage by pressing <F6>.
  4. Plugin in your USB harddrive. Wait a couple seconds. Start partimage again and you should see a new partition appear that’s the size of your USB harddrive. Write it down. On the AAO, the close right USB port comes up as sdc1. Also note if the harddrive is ntfs. Exit again with <F6>.
  5. Move to the mnt directory (cd /mnt). Make a new directory named myusb (mkdir myusb). Now mount the USB harddrive (connect it to the folder we just made). If your harddrive is ntfs then do ntfs-3g /dev/[insert USB harddrive partition] /mnt/myusb, otherwise type mount /dev/[your USB harddrive's partition goes here] /mnt/myusb. In my case, this was mount /dev/sdc1 /mnt/myusb.
  6. Make a directory somewhere convenient on the backup harddrive (in /mnt/myusb). I did mkdir /mnt/myusb/backup. Write down the full path for this directory.
  7. Start partimage (last time this time). Select either the main Windows partition or the hidden partition you want to backup, press <Right>, enter /mnt/myusb/backup/partbak in the “Image file to create/use” box. Hit <F5> to go to the next screen and <F5> again to accept the default options (gzip the image files and split into 2 Gb files). Enter a descriptive description and hit Return (twice) to go to the next screen. Take a quick glance at the information and hit <Right> and Return again to start the backing up.
  8. Get a coffee or two and wait until it finishes. Exit. Shutdown the computer. Remove the USB drives. Restart in Windows, plug in the USB harddrive and make sure the drives contains a backup folder with partbak.000รฏยผล’partbak.001… inside. If so, congratulations.

Geez that ended up going longer than I thought but that should be it. Now if worse comes to worse, you can do the reverse to restore (hopefully). I’ve only tried restoring once but it’s one for one so far.

Bash/UNIX
Programmer

Comments (22)

Permalink

WP_ModerationRSS

I like to monitor my comments by RSS. That keeps all the fun blog related stuff in the feed reader and leaves my email for important stuff. Unfortunately, this has resulted in some comments languishing unnoticed in the moderation queue since there doesn’t seem to be an easy way (that I found with a quick search) to get the comments awaiting moderation into a feed. So here is a very simple plugin to put comments awaiting moderation into an RSS feed.

Features

  • RSS feed of comments awaiting moderation
Continue Reading »

Blogger
Programmer
Web

Comments (2)

Permalink

Hosting Problems and How to Restore Lost Pings

I just checked in here and found the last couple days of comments missing. Luckily, they were stored in gmail and I think I restored them all. But if you left a comment recently and it isn’t here now, it’s not that I don’t like you (just that my host apparently doesn’t like me).

A couple of the comments were pings and I wouldn’t have know how to get them back if I hadn’t messed around with pinging for my WP_PingPreserver plugin, so I figured it might be useful to put up a quick bit on how to recover lost pings. You’ll need to know a little bit about php to use it I guess but if you don’t know php and need to restore some pings let me know and I’ll make up a quick plugin. So here’s some simple (i.e. probably not perfectly to specifications) php code to restore lost pings on WordPress:

Continue Reading »

Blogger
Programmer
Web

Comments (0)

Permalink

Gravatar Adds MonsterIDs and Identicons

Gravatar

It looks like Gravatar has added Identicons and MonsterIDs to their system. I’d been wondering when they would add something like this since it seems like such a simple and useful addition. I was thinking my plugins wouldn’t get much use now but it seems like they’ve gotten quite a few hits in the last few days. Not sure if that’s related to Gravatar or just random but I guess some people are still finding them useful.

So I guess I’ll keep maintaining the plugins since unfortunately Gravatar doesn’t really give you all the configuration possibilities of WP_Identicon or the hand drawn monsters of WP_MonsterID.

Goblin art by Lemm

Speaking of hand drawn, Lemm, the kind illustrator that drew up the new monsters, has (re?)started No More Tangerines, a blog showing off some of her art. It’s pretty cool to see the progression her drawings go through.

Blogger
Programmer
Web

Comments (3)

Permalink