User:Etz Haim/Tech Corner

From Wikipedia, the free encyclopedia

Attention!


There's no guarantee, explicit or implied, for anything contained in these pages. Use at your own risk!


Conversions[edit]

Image file formats[edit]

GIF to PNG[edit]

PNGs are always a better alternative to the stone-age, abusive patent-crippled GIFs. Avoid contributing GIFs to Wikipedia.

Conversion, the gif2png way:

gif2png file.gif

the ImageMagick/GraphicsMagick way:

convert file.gif file.png

and the NetPBM way:

giftopnm < file.gif | pnmtopng > file.png

Progressive JPEGs to non-progressive[edit]

Progressive JPEG is the JPEG equivalent of the "interlaced GIF"; while being downloaded, the image gradually "fades in" from a low-quality, heavily pixelized form to its full quality. Progressive JPEG makes the download of big image files somewhat smoother and compensates you for the wait, for a small increase on the total download size.

When images are converted into thumbnails, the "progressive" feature of the JPEG on the full-size image is obviously unnecessary (though no great cost either). You can convert progressive JPEGs to non-progressive from the command line, using the mogrify utility from ImageMagick:

mogrify *.jpg

Make sure you keep a backup of the original(s) before executing this command.

If you are going to make such conversions you should use a specific tool like jpegtran which can do it losslessly. do not throw away quality by using a general perpose tool that will decode and re-encode the jpeg. In most cases its probablly not worth the hassle though.

Audio file formats[edit]

Where possible it is best to avoid conversions from one lossy format to another. try to get hold of an original that has never undergone lossy compression and use that as a source for your ogg file (or get the author to do the ogg encoding themselves from the original source material).

WMA to WAV audio[edit]

WMA (Windows Media Audio) is an evil proprietary audio file format owned by Microsoft. You can't contribute WMA files to Wikipedia, and it's also best to avoid using them at all. If you want to convert any WMA's you own to anything else, you have to convert them to WAV first. For this purpose, you may use this bash shell script (requires MPlayer):

for i in *.wma;
        do mplayer -vo null -vc dummy \
        -ao pcm -waveheader \
        -slave -nolirc -nojoystick -nomouseinput "$i" &&
        mv audiodump.wav "`basename "$i" .wma`.wav";
done

If you want to resample the sound clips to 44100Hz (CD quality), add the following command line option to the above:

-af resample=44100

WAV to Ogg Vorbis[edit]

Still, WAV files are too big to be uploaded to Wikipedia. Ogg Vorbis is a lossy compressed audio file format, equivalent to MP3, except its files have and .ogg suffix, and it's not patent-encumbered like MP3.

You can convert your WAV files to Ogg Vorbis, either using a graphical tool such as Audacity or Sweep, or with the oggenc tool that comes with most Linux distributions:

oggenc file.wav -o file.ogg

The oggenc tool has a lot of command line options. You may have a look at its man (manual) page:

man oggenc

For an audio player that can handle .ogg files, try XMMS (on Linux), WinAmp (on Windows) or MPlayer (on most platforms).

MP3 to Ogg Vorbis[edit]

For a command line tool to perform automatic MP3 to Ogg Vorbis conversion, take a look at mp32ogg.

PNG optimization[edit]

This is my recipe for reducing the size of PNGs to the smallest possible:

pngrewrite infile.png outfile.png # if the PNG has < 256 colors
optipng -o7 outfile.png
advpng -z4 outfile.png

For more information see Wikipedia:How to keep image file sizes as small as possible.

My scripts[edit]

Web gallery harvester[edit]

This is a python script to be executed from the command line. It requires the lynx browser and the wget download manager:

Usage: python <scriptname> <directory> <url>
#!/usr/bin/python

import os, sys
from urlparse import urlparse
from fnmatch import fnmatch
 
browser_id = 'Mozilla/5.0 (X11; U; Linux i586; rv:1.7.3) Gecko/20040914 Firefox/0.10.1'
extensions = ('jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG', 'gif', 'GIF', 'bmp', 'BMP')
 
dir, referer = sys.argv[1:3]
  
path = os.path.join(os.getcwd(), dir)
  
os.mkdir(path)
os.chdir(path)
meta = open('.meta', 'w')
meta.write('This directory contains the images linked in:\n\n')
meta.write(referer + '\n')
meta.close()
  
print path
 
rawlist = os.popen('lynx --dump "%s"' % referer)
cmd = 'wget "%s" --accept=%s --referer="%s" --user-agent="%s"'
  
for item in rawlist:
        if 'http://' in item:
                url = item.split()[-1]
                filename = os.path.split(urlparse(url)[2])[-1]
                for ext in extensions:
                        if fnmatch(filename, '*.'+ext):
                                os.system(cmd % (url, ext, referer, browser_id))
                                break
Get Firefox
Get Firefox