Posts Tagged 'convert'

Creating HTML Documents from Files with Wiki Syntax

I want to create some simple HTML documents with some basic layouting like heading, images and links. Writing pure HTML can be a slow and painful procedure. Usually I’m working with a lot of wikis, so I want to have a file were I can write my document using a common wiki syntax and generate HTML code from this wiki file afterwards.

There some good Perl wiki-to-html converters out there, but since I don’t want to install Perl on my Windows machine at my laboratory, I rather want to have something written in Python.

I found a nice parser and html converter for the Creole Wiki Syntax, it works well with Linux and Windows.

Unfortunately Creole is not the most powerful wiki syntax, I didn’t found out how to create a table of content yet and there are some other drawbacks. If someone knows a good wiki2html tool which doesn’t have tons of dependencies and runs fine under Windows, feel free to leave me a message.

Advertisements

Resizing Image Files with Python

Yesterday I came back from my holidays in Korea with a whole bunch of pictures which I now want to upload to my website to share them with my friends. Usually I take high resolution pictures with a size of 3056×1334 pixel. That’s of course to big for publishing them in the internet, so I wrote a small python script to convert them to 800×600 automatically by using the Unix convert command:

#!/usr/bin/env python
  1. -*- coding: utf-8 -*-
import sys import commands def convert(file, resize="800x600", prefix="small"): try: cmd = "convert -resize " + resize + " " + file + " " + prefix + "_" + file commands.getstatusoutput(cmd) except e: print e def usage(prog): print "Usage:", prog, "-r RESIZE -p PREFIX FILES..." if __name__ == "__main__": argv = sys.argv[1:] if len(argv) <= 1: usage(sys.argv[0]) sys.exit(-1) resize = "800x600" prefix = "small" for i in range(len(argv)): arg = argv[i] if arg == "-r" and i+1 < len(argv): resize = argv[i+1] elif arg == "-p" and i+1 < len(argv): prefix = argv[i+1] elif argv[i-1] != "-r" or argv[i-1] != "-p": convert(arg, resize, prefix)

Run the script with convert.py *.jpg and it will convert all jpg file into 800×600 pixel images while preserving the original file and creating new ones named “small_ORIGINALFILENAME”. Use the parameters “-r” and “-p” to define the resize rate or to change the prefix, see man convert for more details.