ImageMagick – Ubah Ukuran Foto

CBagaimana cara mengubah ukuran foto dalam jumlah banyak? Sangat tidak praktis kalau kita mengubah ukuran foto tersebut satu persatu. Di Ubuntu ada tools yang namanya ImageMagick yang bisa dipakai untuk mengubah ukuran sebuah foto. Selain itu ImageMagick juga bisa dipakai untuk mengubah tipe file foto yang kita miliki, tidak hanya itu masih banyak fungsi ImageMagick yang belum saya pelajari. Untuk menginstal ImageMagick di Ubuntu 8.04 caranya cukup mudah, lihat log waktu saya menginstal ImageMagick berikut ini :

root@tedy-laptop:/home/tedy/Pictures# apt-get install imagemagick
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
imagemagick
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B/1421kB of archives.
After this operation, 4571kB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
imagemagick
Install these packages without verification [y/N]? y
Selecting previously deselected package imagemagick.
(Reading database ... 200580 files and directories currently installed.)
Unpacking imagemagick (from .../imagemagick_6.3.7.9.dfsg1-2ubuntu1_i386.deb) ...
Setting up imagemagick (7:6.3.7.9.dfsg1-2ubuntu1) ...

root@tedy-laptop:/home/tedy/Pictures#

Cara untuk mengubah ukuran foto dengan bantuan ImageMagick juga cukup mudah, cukup gunakan perintah convert, seperti berikut ini :

tedy@tedy-laptop:~/Pictures$ convert -resize 600 training.jpg training-resize.jpg

Dengan perintah di atas, saya mengubah foto dengan nama training.jpg (dengan ukuran lebar 3250 pixel) menjadi sebuah foto lain dengan nama training-resize.jpg yang lebarnya 600 pixel. Lihat Image Properties sebelum diubah :

Dan ini setelah foto diubah ukurannya dengan bantuan ImageMagick :

Update :

Sore ini saya iseng membuat script untuk mempermudah proses resize banyak gambar sekaligus. Dengan script ini saya bisa mengubah semua gambar dalam sebuah direktori dengan cepat.

tedy@tedy-laptop:~$ more script.sh
#!/bin/bash
# ini contoh script untuk resize banyak foto sekaligus dalam sebuah folder
clear;
echo "=============================================================";
echo "This is script for resize a folder contain many images";
echo "=============================================================";
echo "";
echo "Enter images directory ( for example : /home/tedy/ ) :";
read DIRECTORY;
clear;
while [ ! -d $DIRECTORY ]
do
echo "";
echo "You enter wrong directory, please enter correct directory :";
read DIRECTORY;
done;
clear;
echo "Enter the width of the resized image (in px size) :";
read WIDTH;
clear;
echo "";
echo "================================================================";
echo "All images will resize proportionally with the width = $WIDTH px";
echo "All resized images will stored in directory RESIZE";
echo "";
echo "Start resize process";
cd $DIRECTORY;
rm -rf RESIZE;
if [ -d RESIZE ]; then
rm -rf RESIZE;
else
mkdir RESIZE;
fi
ls *.jpg | sed -e 's/\.[a-zA-Z]*$//' > /tmp/list.txt;
cat /tmp/list.txt |
while read line;
do echo "Resized version from image ${line}.jpg is ${line}-resize.jpg";
convert -resize $WIDTH "${line}.jpg" "RESIZE/${line}-resize.jpg";
done;
echo "Resize process completed";
echo "=============================================================";
tedy@tedy-laptop:~$

Cara pakainya cukup mudah, lihat contoh tampilan saat saya menjalankan script di atas :

4 thoughts on “ImageMagick – Ubah Ukuran Foto

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.