[HOW TO] Compress Pictures In Linux

Standard

Assalamu’alaikum

Sesuai dengan judulnya yang berarti Mengkompres / menyusutkan ukuran gambar di Linux.

Cukup copy script berikut, dan paste kan ke aplikasi text editor :

#!/bin/bash
# A script to resize images.
readonly OUT_FMT="_new.jpg"
if [ "$#" -eq 0 ] ; then
echo "A script to resize images "
echo "How to use : $(basename $0) add_of_image1 add_of_image2 ..."
exit 1
fi
for pic
do
# New filename
out_name="${pic%.*}$OUT_FMT"
if [ -e "$out_name" ] ; then
echo "Output file $out_name exists, Not resizing!!!"
elif [ "${pic#*$OUT_FMT}" == "" ] ; then
echo "$pic already resized!!!"
elif [ ! -r "$pic" ] ; then
echo "Error : could not access $pic !!!"
else
echo -n "$pic -> $out_name"
convert -quality 80 -resize 800x600 "$pic" "$out_name"
if [ ! -e "$out_name" ] ; then
echo " Error .. No output file!!!"
else
echo " ($(du -h "$out_name" | cut -f1))"
fi
fi
done

lalu save dengan nama

resize.sh

rubah hak akses filenya melalui terminal

sudo chmod +x resize.sh

Cara menjalankannya cukup lewat terminal dan ketik ./resize.sh nama_file_gambar

./resize.sh aaa.jpg

Jika gambar yang akan dikompres terletak dalam satu folder, cukup ketikkan perintah seperti contoh berikut

./resize.sh Desktop/linux09/*.JPG

Yang jadi kendala adalah gambar hasil kompres dan asli terletak dalam satu folder.

But is not problem🙂

Happy Ngoprek

Wassalam

sumber

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s