Wednesday, April 21, 2010

ImageMagick

Introduction


ImageMagick is free software delivered as a ready-to-run binary distribution or as source code that you can freely use, copy, modify, and distribute. Its license is compatible with the GPL. It runs on all major operating systems.
The functionality of ImageMagick is typically utilized:
  • from the command line or
  • from programs written in your favorite programming language. Choose from these interfaces: MagickCore (C), MagickWand (C), ChMagick (Ch), Magick++ (C++), JMagick (Java), L-Magick (Lisp), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), PythonMagick (Python), RMagick (Ruby), or TclMagick (Tcl/TK). With a language interface, use ImageMagick to modify or create images automagically and dynamically.
This tiny introduction focuses on the command line use which is extremely useful if the same operation has to be carried out repeatedly (and automatically). Typical examples include post processing of some kind of data, dynamic and automatic creation of bitmaps for webpages, or just the odd conversion or annotation of a collection of photos.
We point the interested reader to http://www.imagemagick.org for the full documentation, download and installation of the software.

Conversion of file formats

The command line tool to convert from one graphics format to another is convert. The basic usage is straight forward:

convert Ashwinie_Jassvendra.png Ashwinie_Jassvendra.jpg
The convert command guesses the required format from the filename extension (i.e. from png to jpg).
Ashwinie_Jassvendra.png

Identifying image types

The identify command allows quick identification of image files:

Jassvendra@slax:~# identify Ashwinie_Jassvendra.png
                                     Ashwinie_Jassvendra.png PNG 632x474 632x474+0+0 8-bit   
                                     DirectClass 815KB      0.040u 0:00.039         
                        
Jassvendra@slax:~# identify Ashwinie_Jassvendra.jpg
                                    Ashwinie_Jassvendra.jpg JPEG 632x474 632x474+0+0 8-bit                 
                                    DirectClass   65.6KB 0.000u 0:00.000

Changing the size

First, we'll make the image we have somewhat smaller. For example, suppose we would like to limit it to 250 pixel in the x-direction:

convert -geometry 250 Ashwinie_Jassvendra.png small_Ashwinie_Jassvendra.png

 The number of pixels in the other direction (i.e. y) will be chosen such that the proportions of the image are preserved:

Jassvendra@slax:~# identify small_Ashwinie_Jassvendra.png
small_Ashwinie_Jassvendra.png PNG 250x188 250x188+0+0 8-bit DirectClass 104KB 0.020u 0:00.019

Here is the smaller image:

Adding a frame

Actually, the size of the image would be better visible if we had a frame around the image. Here is the command to create a frame of 2 pixels in color black:

convert -geometry 250 -border 2 -bordercolor black small_Ashwinie_Jassvendra.png small_frame.png


 Adding labels

 There is a multitude of possible ways to add labels to a picture. One is to use the montage command line utility which can create a montage by putting together several pictures. This is often used to create index thumbnail pages for directories with many pictures. Here, we put together our normal image, and a piece of text ("Jassvendra The Hero"):

Jassvendra@slax:~# montage -geometry +0+0 -background skyblue -label "Jassvendra The Hero"    small_Ashwinie_Jassvendra.png small_label.png

which results in this picture


ImageMagick has a number of quite sophisticated image processing options which includes the polaroid switch:

Jassvendra@slax:~# convert -caption "Jassvendra The Hero Polaroid" small.png -gravity center    -background black +polaroid small_polaroid.png




Labeling on top of the Image itself

The problem with writing text directly on a picture is that you can't be sure the text will be readable in the color you have chosen. The image being drawn onto could be black, white or a rainbow of colors.

Outlined Label: The simplest method is to draw the string with a outline to separate the text from the image. However as the "-stroke" font setting adds thickness to a font both inward and outward, it is a good idea to draw the text twice.

Jassvendra@slax:~# convert 06.jpg -gravity south           -stroke '#000C' -strokewidth 2 -annotate 0 'nWo Computer LINUX'           -stroke  none   -fill white    -annotate 0 'nWo Computer LINUX'           nwo.jpg


 


As you can see it works, but not very well. It does work better with a thicker font, than the default 'Times' or 'Arial' font. The more classical method to make the annotated text more visible is to 'dim" the image in the area the text will be added, then draw the text in the opposite color.

Draw Dim Box: ImageMagick has the ability to draw transparent colors. This can be very useful to create a box to draw the text into.

 Jassvendra@slax:~#   convert 06.jpg  -fill white  -undercolor '#00000080'  -gravity South           -annotate +0+5 ' nWo Computer LINUX '     nwo03.jpg


Please visit http://www.imagemagick.org/Usage/annotating for a lengthy list of examples.

Saturday, April 17, 2010

ImageMagick Tutorial

How To ...
Format Conversion

Convert from gif to png.

convert p1.gif p2.png

Convert from png to jpg. Use “-quality” for compression/quality.

convert -scale 50% -quality 80% old.png new.jpg
Scaling and Cropping

Scale a image.

convert -scale 50% old.gif new.png

Autocrop border

convert -trim cat.png cat.png

Cropping (cutting) a image.

convert -crop 853x368+0+56 old.png new.png

The 853 and 368 would be the new image's width and height. The 0 is the offset on x-axis, and 56 is the offset of y-axis. The x and y axes's origin starts at the upper left corner.

To crop by specifying percentage of sides to cut, use “-shave”.
Color, Brightness, Saturation...

Increase brightness.

convert -modulate 150,100,100 old.png new.png

The above increase brightness by the multiplier 150%. To decrease, use values less than 100. The full argument to modulate are 3 numbers in the form “x,y,z”. The x is the brightness. The y is the saturation. The z is the hue. They are all interpreted as percentages.

Increase saturation.

convert -modulate 100,130,100 old.png new.png

The above increase color saturation by the multiplier 130%. To decrease, use values less than 100.
Color, bits per pixel, file size.

Change color image to gray scale.

convert -type Grayscale old.png new.png

Note: this does not necessarily force image format use indexed color to reduce size.

Reduce bits per pixel.

Use “-depth”. In particular, for a grayscale line art in png, you can do: convert -depth 8 old.png new.png. That makes it 8 bits. For clean black and white line art, you can use “-depth 2”. This is great for reducing file size. (see also “-colors”)

Reduce color.

convert -dither -colors 256 old.png new.png.

To reduce color without dithering, use “+dither” in place of “-dither”. Note that reducing colors does not necessarily reduce file size.
Image Filtering

Sharpen a image.

convert -sharpen 2 old.png new.png

Blur a image.

convert -blur 1 old.png new.png
Image Editing

Insert copyright notice.

convert -fill red -draw 'text 20 20 "© 2006 XahLee.org"' old.png new.png

Use -gravity SouthEast -font helvetica to put the text in other corners, and change font.
Flip and Rotate

How to rotate a image?

convert -rotate 90 x.png x.png. Positive degree means counter-clockwise.

How to flip a image?

To mirror it along a vertical line, use convert -flop x.png x.png. To mirror it alone a horizontal line, use “-flip”.
Batch Processing

Batch processing.

There are many ways to process all files in a directory in one shot. You can use the unix shell utils “find” and “xargs”, or write a bash shell script, or use Perl, Python, emacs.

Suppose you want to convert all files in a dir from png to jpg.

unix shell solution (programs assume GNU version):

find . -name "*png" | xargs -l -i basename -s ".png" "{}" | xargs -l -i convert -quality 85% "{}.png" "{}.jpg"

The “-l” makes it process one line at a time. The “-i” makes the “{}” to stand for file name. The “basename -s” strips the suffix.

To use emacs, basically you create a temp file temp.sh, and fill out this file with command lines like “convert p1.png p1.jpg”, “convert p2.png p2.jpg”, ..., then execute this file as shell script. The emacs commands to do this are:

“Ctrl+x Ctrl+f temp.sh” to create a file, “Ctrl+u Alt+! ls *png” to insert a list of png files. Type “Ctrl+Alt+%” then “\(.+\)\.png” and “convert \1.png \1.jpg” to replace each image file to the right command string. Then “Alt+! sh temp.sh” to execute the file as shell script. Also, the commands string-rectangle (Ctrl+x r t) and kill-rectangle (Ctrl+x r k) are helpful, because they let you cut/insert a column of text. For more emacs tips, see: Emacs and Unix Tips.

For Perl and Python solutions, see Making System Calls in Perl and Python.
Misc

Other options to explore:

* -annotate
* -comment

* -contrast-stretch
* -black-threshold
* -white-threshold
* -level
* -modulate
* -monochrome
* -normalize
* -quantize

* -blur
* -radial-blur
* -adaptive-blur
* -unsharp
* -adaptive-resize
* -adaptive-sharpen
* -despeckle
* -dither
* -enhance
* -equalize
* -gaussian
* -antialias

A complete tutorial with examples: http://www.imagemagick.org/Usage/.

ImageMagick resize Image

ImageMagick has some pretty cool commandline tools to manage images. Specifically I wanted to resize an image (make it smaller).

Code:

convert -resize 50% -quality 80 input.jpg output.jpg

You can change resize to a pixel size also: 800x600. Pretty handy and quick. Update: You can resize/recompress and entire directory of images using find and xargs. This works good if you need to resize an entire directory/camera full of images to save space.
Code:

find . -iname "*.jpg" | xargs -l -i convert -quality 75 {} /tmp/output/{}

Saturday, April 10, 2010

Linux Slax Dial Up Modems Setup

Many people now use broadband Internet connections. However, some people use dial up modems, either because they are in a location where broadband is not available, or because it is less expensive. This section is included for people who use a dial up modem.

Modems

Some dial up modems work with Linux, others may not, particularly Winmodems. Most external modems work.

Kppp

When Slax is installed, Kppp is included.

Following is an explanation of how to set up Kppp using common options. In some situations the information which needs to be entered may be different. Enter information as appropriate for your situation.

Begin by clicking on "KPPP" in the menu to open it. You should find it under "Internet."

Click "Configure." You will get a new window.

Click "New." You will get a new window.

You can try "Wizard" and see if it works. Only some countries are included here. If your country is not included, you cannot set it up using this method. Let's use Manual Setup.

Click "Manual Setup." You will get a new window.

Click "Add." You will get a new window.

Enter the phone number your computer dials to connect to the Internet. Then click "OK." This will close this window and take you back to the previous one.

Enter the name of your Internet provider in the box following "Connection name." (You can enter anything here.)

Click "OK." This will close this window, and take you back to the previous one.

Click the tab "Modems."

Click "New."

Enter the name of your modem in the box following "Modem name." (You can enter anything here.)

The box following "Modem device" needs to set as appropriate for your modem. If you have an internal modem, leave it as "/dev/modem." If you have an external serial modem, it may be "/dev/ttyS0." If you are not sure, try different ones and see which works.

In the box following "Connection speed," change it to "115200."

Click "OK." This will close this window, and take you back to the previous one.

Click "OK" again. This will close this window, and take you back to the previous one.

In the box following "LoginID," enter the username you use to connect to the Internet.

In the box following "Password," enter the password you use to connect to the Internet.

You can now click "Connect," and connect to the Internet.

You can also click "Quit" to close it.

Monday, April 5, 2010

VLC media player for FEDORA 12

$> su -
#> rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
#> yum install vlc
#> yum install mozilla-vlc (optionnal)

Installing Compiz on Fedora 12

Installing Compiz on Fedora 12

Installing Compiz on Fedora 12 is not easy. First of all, due to compatibility issues with nouveau driver, additional steps are required to install and configure nvidia 3D driver. After resolving 3D driver issue, you need to modify Compiz configuration file so that your settings are captured. The installation procedure is the same for 32-bit/64-bit Fedora 12.

Installing Compiz

Issue the following command to install Compiz:

* #yum install emerald-themes compiz-fusion-extras emerald compiz-fusion compiz-manager compiz-fusion-extras-gnome gnome-compiz-manager libcompizconfig compiz-fusion-gnome ccsm

Configuring Compiz

CCSM Problem

You can change the settings using CompizConfig Settings Manager (ccsm) under System >> Preference. However, due to some bug, the changes in ccsm will not affect the system. To rectify this problem you need to change the script file for Compiz in /usr/bin/compiz-gtk

Once you open this file, change the following line from:

* exec compiz –ignore-desktop-hints glib gconf gnomecompat $@

to:

* exec compiz –ignore-desktop-hints glib gconf gnomecompat ccp $@

Enabling, Configuring and Using Compiz

You enabled Compiz by select System >> Preference >> Desktop Effect. Choose Compiz.

You can change the effects using System >> Preference >> CompizConfig Settings Manager

To rotate the Window Cube, press Ctrl+Alt and simultaneously use your mouse to rotate the window.

If you are new Linux user, it is recommended that you follow the step mentioned above.

Saturday, April 3, 2010

Radio Online Malaysia Dan Linux Rhythmbox

Bagi mereka yang suka mendengar radio pasti tidak melepaskan peluang mendengar radio online di Malaysia.

Tutorial.

1. Pergi ke Applications > Sound and Video > Rhythmbox Music Player.
2. Klik Radio pada sebelah kiri panel.
3. Tekan butang paling kanan sekali – Create new Internet radio – di bahagian toolbar.
4. Isikan mana-mana link di bawah pada ruangan di tetingkap yang muncul nanti.
5. Tekan Add.
6. Klik dua (2) kali pada nama link radio yang diletakkan tadi.

Berikut senarai link radio yang boleh digunakan pada Rhythmbox.

* Fly Fm – http://rs9.radiostreamer.com:11000/
* Hot Fm – http://rs9.radiostreamer.com:10000/
* One Fm – http://rs9.radiostreamer.com:12000/
* Era Fm – mms://rs5.radiostreamer.com/AMP_ERA
* Hitz Fm – mms://rs5.radiostreamer.com/AMP_HITZ
* Ikim Fm – http://210.48.148.126/ikim
* Mix Fm – mms://rs5.radiostreamer.com/AMP_MIX
* Red Fm – http://75.125.106.156:9000/;stream.nsv
* Sinar Fm – mms://rs5.radiostreamer.com/AMP_SINAR
* X-Fresh Fm – mms://rs5.radiostreamer.com/AMP_XFM
* Klasik Fm – http://mfile.akamai.com/24752/live/reflector:50934.asx
* Jazz Fm – http://tlrc.as34763.net/live.asx?station=jazz1
* My Fm – mms://rs5.radiostreamer.com/AMP_MYFM
* Kl Fm – http://mfile.akamai.com/24752/live/reflector:56151.asx
* Musik Fm – http://bkj-station4.jaring.my/muzikfm
* Radio 24 Fm – http://www.radio24.com.my/player/radio24.asx
* Suria Fm – mms://kl.cdn.tm.net.my/suriafm
* Minnal Fm – http://bkj-station1.jaring.my/minnalfm
* Express Tamil Online Radio Fm – http://www.extamil.com/radio
* Ai Fm – http://bkj-station4.jaring.my/aifm
* Mnet Fm – http://live.mnetfm.net:8080
* Nasyid Fm – http://nasyidfm.net/radio/listen.asx
* 988 Fm - http://75.125.106.155:8000
* Radio Sabah Fm – http://www.rtmsabah.gov.my/sabah_fm.asx
* Radio Sabah V Fm – http://www.rtmsabah.gov.my/sabah_v_fm.asx
* Labuan Fm – http://grace.fast-serv.com:9854
* Traxx Fm – http://bkj-station1.jaring.my/traxxfm
* Asyik Fm – http://bkj-station1.jaring.my/asyikfm
* Lite Fm – mms://rs5.radiostreamer.com/AMP_LITE
* THR Gegar Fm “permata pantai timur” – mms://rs5.radiostreamer.com/AMP_THRG
* THR Raaga Fm – mms://rs5.radiostreamer.com/AMP_THRR
* Fuhyoo Fm – http://78.129.245.212:32253
* Fungkur Fm – http://fungkurfm.mine.nu:8000
* Rilek Fm – http://67.220.76.198:8000
* Putra Fm – http://www.putrafm.upm.edu.my:8080
* Langkawi Fm – http://cybermedia.mmu.edu.my/ext/rml.asx
* Multimedia Unversiti Fm – http://cybermedia.mmu.edu.my/ext/rmmu.asx
* Selangor Fm – http://cybermedia.mmu.edu.my/ext/rms.asx
* Negeri Fm – http://cybermedia.mmu.edu.my/ext/rmns.asx
* Kedah Fm – http://60.51.214.210:8000/
* Perlis Fm – http://60.49.230.182:8000/

Cara-Cara Repair Grub

Ramai pengguna Linux yang masih menggunakan dual-boot antara Windows atau Mac memandangkan ada sesetengah aplikasi atau program yang hanya berfungsi pada OS tertentu sahaja.

Bagi yang menggunakan Windows pula kadangkala akan memformat kembali OS ini setelah terkena virus, keluar skrin biru (BSOD) atau ada ralat yang tak boleh diperbaiki akan juga memadam Menu GRUB yang dipasang Linux. Akhirnya, anda tidak dapat mengakses ke Linux walaupun partition dan failnya masih ada.

Ikuti tutorial di bawah untuk mengembalikannya. (Tutorial berdasarkan Ubuntu).

1. Boot PC anda dengan Ubuntu. Pilih Try Ubuntu without any change to you computer.

2. Klik Applications > Accessories > Terminal .

3. Taipkan sudo grub .

4. Taipkan find /boot/grub/stage1 . Ia akan mengeluarkan partition mana yang anda pasangkan GRUB sebelum ini.

5. Taipkan root (hd?,?) yang mana gantikan ? dengan nombor partition yang dinyatakan pada langkah 4. Contohnya root (hd0,1) .

6. Taipkan setup (hd0) .

7. Tutup Terminal dan mulai semula komputer.