Bulk resize images and keeping original files

Suppose you have a directory (with subdirectories) full of images, and you want to resize them all while keeping the original images. To do so, first create a copy of the directory tree without the image files. Then, using a for loop, find each image file and apply the convert command to it. The following is an example to resize jpg files to 40% of the original quality.

mkdir /path/to/mirror_dir
find /path/to/image_dir -type d -exec mkdir -p /path/to/mirror_dir/{} \;
cd /path/to/image_dir
for i in $(find -iname "*.jpg"); do echo $i; convert -resize 40% $i /path/to/mirror_dir/$i; done

background image in LaTeX Beamer presentation

This post shows how one can change the background image in a Beamer presentation:

 <pre class="example">%% all slides

\usebackgroundtemplate{ \includegraphics[width=\paperwidth, height=\paperheight]{my_bg_image} }

%% single slide { \usebackgroundtemplate{\includegraphics[width=\paperwidth]{my_bg_image}} \begin{frame} \frametitle{Frame with nice background} \begin{itemize} \item 1 \item 2 \item 3 \end{itemize} \end{frame} }

The above method spans the image to cover the entire page size. To include a smaller image and center it, do this:

 <pre class="example">\usebackgroundtemplate{%

\vbox to \paperheight{\vfil\hbox to \paperwidth{\hfil\includegraphics[width=1.5in]{name.jpeg}\hfil}\vfil} }

(I asked this question on the Tex.SX since \hspace{4.5cm} works but \vspace{4.5cm} did not.)

Convert raster image to vector image

I wanted to convert some raster images (bmp, png, etc.) to vector images (svg, pdf, eps) so that they can be rescaled easily. I found Vector Magic, which used to be free from Stanford University but now cost a grip; however, they do allow some free conversions. This post let me know that Potrace is implemented in Inkscape. I just used Potrace directly since it is command line based.

 <pre class="src src-sh">potrace image.bmp <span style="color: #ff4500;">## </span><span style="color: #ff4500;">output image.eps by default</span>

potrace -s image.bmp ## output image.svg; transparent

Now I can easily convert basic artwork to vector images!

Creative Commons: Share, Remix, Reuse – Legally

I recently wrote about the GNU Public License (GPL). All of my software that I write on my own will most likely be licensed by GPL so others can use and modify it freely. I really think this benefits society.

What about content, such as text, image, audio, or video? Analogous to the GPL, there are the Creative Commons (CC) licenses. CC is plural in that there are many licenses available, depending on how the author wants to share his or her work. The core right is to be able to redistribute a work for non-commercial purposes without modification. I believe the most popular variant is the Attribution-NonCommercial-ShareAlike 3.0 Unported, of which my Super Nerdy Cool blog is licensed with. I should remember to always post communicate the license of all my work (such as presentations, lecture notes, etc.). Examples of how to attribute can be found here

Now, onto some resources.

  1. Images: the noun project compfight (searching Flickr) and Cadyou.
  2. Audio: FreeSound, Free Music Archive, and opsound.
  3. Video: Blip TV.

Photo/picture/image repository, viewable using a web browser

I never had the habit of taking pictures and using them to cherish memories. I recently realized its importance when my mom passed away and I was scouring to find pictures. Luckily my siblings had some (I had to scan the the older, non-digital ones). These days, a camera is cheap, portable, and digital storage is cheap and only getting cheaper. I went out and bought a camera and will be taking pictures for the rest of my life now. I probably won’t print the photos all that much, just viewing, sharing, and storing them.

In terms of storage, I like to keep it simple and store them on my laptop using a directory hierarchy for albums. I currently view them with shotwell since it is the default for Ubuntu 10.10. It works quite nice actually. To share with my family (private), I upload the photos to Picasa Web. To share them with my social network, I upload them to facebook. If I want certain pictures to be public (viewable by the world), I upload them to flickr; these are usually taken by my phone.

Obviously the photos are scattered all over the internet with different photos chosen for each, with different quality, etc. It’s probably not easy to recover all the pictures as well. I shouldn’t have to as the main repository is my computer. However, I’d like this repository to also be viewable on the web to certain people (e.g., close family members). I’d like for them to be able to easily obtain the original pictures as well. I went out to look for a web server application for photo viewing and sharing, something analogous to WordPress for blogging, phpBB for forums, and Ampache for audios and videos. However, for photos, there isn’t an obvious application that stands out. My preferences for the software are:

  1. free, open source (GPL!),
  2. lightweight (as little dependency as possible and easy to setup),
  3. automatic resizing for thumbnails (I keep the photos in their original quality, and I don’t want to download massive files when viewing them on the web)
  4. privacy settings (I don’t want it to be viewable by anyone, only to a select few),
  5. local filesystem management of photos and albums via a directory hierarchy (just transfer/sync them into the designated folder and the website just works), and
  6. easy and batch downloading of photos and albums (if a sibling wants an album, just click a link to download an entire album).

I found some comparisons of applications here, here, and here. I asked on serverfault (originally on stack overflow but was moved over) but did not get much responses. I had to try a few out for myself.

Some things to note. A common theme to all the applications (besides a web server running, like Apache) are php (to generate website), MySQL (to store information like users, comments, etc.), and ImageMagick or GD (resizing images).

The privacy setting isn’t much of a concern since I can enable authentication in Apache adding an AuthType directive for the directory in the main config of the site (in /etc/apache2/sites-enabled/my-site) or in .htaccess of the restricted folder; the former is preferred to the latter if it is accessible for speed issues. I should also combine it with SSL just to be more secure (and to learn it).

Here are my evaluations (I just extracted their scripts into a folder of an existing website and followed the INSTALL instructions.).

  1. Gallery: seems to be the most popular, still actively developed, and has all the features I need (add downloading features via plugins) except for the local filesystem management of files (version 3.0). I talked to the main developer on irc and he told me it will probably be implemented if I requested it, and so I did. Let’s just say if the missing feature was there, this would be my chosen program (would’ve saved me a lot of time in testing other software too since this was the first software I tested).
  2. Piwigo: like Gallery, is also cutting edge and feature-rich. However, there are some things to note. You can manage pictures and albums from a directory, but you have to manually go into the website and sync (sync directories first, then dir + files); make sure to simulate the sync first, and change the privacy settings for the new images from the sync (e.g., admin only). For downloading, use the “Download Multi” plugin. Piwigo looks very nice, but the syncing issue is a pain and it took my a while to figure out how to set certain settings. I don’t think I will use it.
  3. Camera Life: also like Gallery and Piwigo. I didn’t try this out on my web server, but I know it does not have a privacy setting and does not have a batch downloading feature. I believe you can manage the images from the local system. I contacted the main developer Will, and he is very responsive. He plans to implement a privacy setting by the next release (March 2011) and will make the site friendly to batch downloading plugins on different web browsers.
  4. Bizou is dead simple and looks promising. Base on the demo, the only thing I don’t like is that when you click on a photo, it downloads the image in original quality. I would like the software to have an intermediate, web-browser quality version of an image to view (to save on bandwidth). It does not have a batch download mechanism, but I guess a web browser plugin would do.
  5. jGallery: did not try out since it is java based. I think files are managed by the local filesystem.
  6. linPHA: local filesystem management, but don’t think it has a privacy setting for viewing and batch downloading.
  7. Naig: looks simple, no batch downloading, no privacy setting, and local filesystem management. However, when I transferred a new folder into albums, I get an error when going to that album on the site. I might have settled for this initially if I didn’t get the error as it is very simple (good as a viewer of all pictures, include slideshow feature, and pictures are resized appropriately).
  8. phpGraphy: lightweight, no batch downloading feature, no privacy setting, but the filesystem management of pictures and albums is SOLID. This together with Authentication from Apache will probably be enough for a VIEWING repository. Basically, just move your images or albums into the pictures folder, chmod +rx the stuff, and the website will display everything properly.
  9. Zoph. Based on the website, I thought it had all the features I needed. The main thing to point out is Zoph offers some commands that you can use in the shell to import and organize (by albums, etc.). However, it is more complicated than I would want.

After evaluating the softwares above, I came to realize that I want an application that just watches a folder and displays them on the web. I want it to create thumbnails and web versions (appropriate resolutions) of the images automatically. The privacy setting can be set up in Apache so this isn’t a huge issue (although there is no logout button). Batch/mass downloading is not present in most of the software.

Here are my conclusions. I like Gallery best as it has all the features. However, just because I can’t manage the photos from a directory I will not be using it (yet). I really liked Naig due to its simplicity and how it displays the images; however, since it is currently broken for me, I won’t be using it. Hopefully the maintainer will get back to my inquiry.

I guess in the mean time, I can use phpGraphy with authentication from Apache. It is rock solid at what it does. However, no access to mass downloading or downloading files with the original quality. I can live without that for now.

WordPress: post via email using Postie

WordPress’s default “post by email” setting is pretty weak, mainly because it doesn’t handle attachments (think posterous, among other things. Postie is quite powerful as it can handle different attachments and can handle my LaTeX and source code content. Note to self: use the development version!

Setting up is quite easy – you only need to install php5-imap to use imap with ssl. If the postie filters is activated, deactivate it or remove the two examples in there. This should remove the “(post via postie)” message in the subject line and “Bookmark this category” line in the gets appended to the beginning of the post.

Images

In the “Image” section in Postie’s settings, set the Image Template to custom and set the template to blank. This way, if I want a gallery (wordpress feature since v2.5), I can add in this line in the post/email

[ gallery link="files" ]
## without the spaces in beginning and end, or use NextGen gallery
[ imagebrowser id=x ]
## need to know id of post

See this site for an overview. I can also use the NextGen gallery. When I have time, I want to hack postie so that the line gets appended by default if there are image attachments.

Embedding other sites’ video and audio

Install WordPress Video Plugin. See this site for the syntax.

Audio and Video attachments

Add “mpeg” in the audio list as mp3 files have that description. Install audio player and use the audio template

## audio
LeftSquareBracket audio:{FILELINK} RightSquareBracket
## video: simple_link
[[%7BFILELINK%7D][{FILENAME}]]

Audio player will play mp3 files. Video doesn’t really play, but I don’t plan to host any videos.

I will use posterous (my other blog) for more multimedia intensive blogging (since this is more of a technical blog).

Note: other attachments get attached as files!

Check email

Set up crontab -e:

*/10 * * * * /usr/bin/wget -O /dev/null http://my.server.com/wp-content/plugins/postie/get_mail.php >/dev/null 2>&1

for checking every 10 minutes.

Posting options

See this site for other options, such as categories, tags, delay, etc.

I will write a template email and use emacs to email and post. Weblogger is a little weak in that doesn’t handle attachments and does not support tagging and categories (as of now).

Issues

  1. LaTeX: Need to use double backslashes to get things correctly.
  2. What else? Good enough for now.