Author Topic: Discovering the magic of Imagemagick  (Read 2147 times)

DrDOS

  • Guest
Discovering the magic of Imagemagick
« on: June 26, 2009, 12:18:58 PM »
Imagemagick is hiding in your pclos machine. It's an entire suite of applications that can process photos, view photos, build thumbnail pages and obtain photo information. It only works in the command line, so the likelyhood is that you don't even know it's there. You can use from the command terminal or you can use it from scripts. It even has it's own scripting language, but it gets along very well with bash.

Would you like to make the background color of a .gif transparent?

$ convert -transparent '#fff' input.gif output-trans.gif

where a copy of a file named output-trans.gif with a  transparent white background "#fff' is made from a file input.gif which has a plain white background.

Want to resize all the images in a folder?

# mogrify -geometry '800x600>'  -quality 60 *.*

will re-size all the images in the working folder to  have a size not exceeding 800px wide or 600px high while retaining the aspect ratio and file name.

You can find out all about it here.

http://www.imagemagick.org/

If you're not into writing scripts there are many available on the web. IM is often included as part of other applicaitons and has even been ported to Windows.

Offline bones113

  • Hero Member
  • *****
  • Posts: 1878
  • Cherish your loved ones everyday.
Re: Discovering the magic of Imagemagick
« Reply #1 on: June 26, 2009, 02:35:18 PM »
It is installed but will not work. I get the "command not found" error from the cli. I would like to check it out. Any suggestions?.
PCLinuxOS 2011.9 Kde on a MSI cx700 laptop with dual core t4200@ 2ghz, 4 gigs ddr2 , 320 gb sata hd, 17.3 hd wide screen, ati Radeon 4330 video @512 mb, dvdrw multi drive. PCLinuxOS 2011.9 Kde on Dell optiplex 755, Core2 duo@2.66 ghz, 4gig ddr2, wd 320 gig sata hd, dvdrw, Ati Radeon 2400 @256 mb.

CtrlAltDel

  • Guest
Re: Discovering the magic of Imagemagick
« Reply #2 on: June 26, 2009, 02:45:13 PM »
Hi bones..

Post your output here so we can see what you did..


Cheers,


CtrlAltDel

Offline gandy

  • Hero Member
  • *****
  • Posts: 1176
Re: Discovering the magic of Imagemagick
« Reply #3 on: June 26, 2009, 03:16:32 PM »
You can also get a GUI version of Imagemagick buy typing "display" without the quotes in a terminal window. I found that out a while back by searching the forum here.
For me, it is far better to grasp the Universe as it really is than to persist in delusion, however satisfying and reassuring. –
Carl Sagan

Offline bones113

  • Hero Member
  • *****
  • Posts: 1878
  • Cherish your loved ones everyday.
Re: Discovering the magic of Imagemagick
« Reply #4 on: June 26, 2009, 03:22:27 PM »
Hi bones..

Post your output here so we can see what you did..


Cheers,


CtrlAltDel

Here it is. I tried several different ways.

[tony@localhost ~]$ image magick
bash: image: command not found
[tony@localhost ~]$ imagemagick
bash: imagemagick: command not found
[tony@localhost ~]$ ImageMagick
bash: ImageMagick: command not found
[tony@localhost ~]$
PCLinuxOS 2011.9 Kde on a MSI cx700 laptop with dual core t4200@ 2ghz, 4 gigs ddr2 , 320 gb sata hd, 17.3 hd wide screen, ati Radeon 4330 video @512 mb, dvdrw multi drive. PCLinuxOS 2011.9 Kde on Dell optiplex 755, Core2 duo@2.66 ghz, 4gig ddr2, wd 320 gig sata hd, dvdrw, Ati Radeon 2400 @256 mb.

Offline bones113

  • Hero Member
  • *****
  • Posts: 1878
  • Cherish your loved ones everyday.
Re: Discovering the magic of Imagemagick
« Reply #5 on: June 26, 2009, 03:25:02 PM »
You can also get a GUI version of Imagemagick buy typing "display" without the quotes in a terminal window. I found that out a while back by searching the forum here.

Yeah. That worked. Thanks.
PCLinuxOS 2011.9 Kde on a MSI cx700 laptop with dual core t4200@ 2ghz, 4 gigs ddr2 , 320 gb sata hd, 17.3 hd wide screen, ati Radeon 4330 video @512 mb, dvdrw multi drive. PCLinuxOS 2011.9 Kde on Dell optiplex 755, Core2 duo@2.66 ghz, 4gig ddr2, wd 320 gig sata hd, dvdrw, Ati Radeon 2400 @256 mb.

DrDOS

  • Guest
Re: Discovering the magic of Imagemagick
« Reply #6 on: June 26, 2009, 03:45:08 PM »
Actually 'display' is only the viewer part of Imagemagick and there is a lot more to it. You don't call imagmagick from the CLI, there is no binary with that name, you call 'mogrify', 'convert', 'identify' and several others.

In fact here's a script that I wrote just this morning using two of the binaries. It just makes a nice photo splash page in the working folder. If you want to try it just put the script in your home folder, name it splash, call it this way. Open a terminal in a folder with some images, not too many or it will use too much memory, maybe 20 or 50mb of images, and enter this;

$ bash $HOME/splash

And please tell me what you think of it. I would appreciate some feedback.

Code: [Select]
#!/bin/sh
IFS=$'\t\n'
echo -E \
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html>
<head><meta content=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\">
<title>My Photo Splash Page</title>
<style type='text/css'>
body {background-color:#000;color:#fff}
img  {border:2px solid white}
</style>
</head>
<body>
<center>
<h2>My Photo Splash Page</h2>
<br>
" > splash.html
identify -format '<span><img src="%i" width="%w" height="%h"></span>\n' *.jpg *.jpeg *.JPG *.JPEG >> splash.html
echo -E "</center></body></html>" >> splash.html
firefox splash.html
exit 0
« Last Edit: June 26, 2009, 04:51:18 PM by DrDOS »

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Discovering the magic of Imagemagick
« Reply #7 on: June 26, 2009, 04:11:12 PM »
I make a lot of use of Kim right click menus which uses       imagemagick       to carry out the work.

Very useful.
Lots of other video apps make use of it too, like dvd::rip etc.

Definitely one of the unsung heroes.  ;)

DrDOS

  • Guest
Re: Discovering the magic of Imagemagick
« Reply #8 on: June 26, 2009, 09:46:27 PM »
I make a lot of use of Kim right click menus which uses       imagemagick       to carry out the work.

Very useful.
Lots of other video apps make use of it too, like dvd::rip etc.

Definitely one of the unsung heroes.  ;)


The next time you make a gallery page with KIM run this little bit of script on it. It's only made to run on the KIM page but you might harm another page if you ran it on it. It keys to an index.html page. You might notice the difference that a whiff of javascript can do for thumbnail pages. Took about an hour to write it. I call it kimpopup.

PS: Updated the script so that you can run it twice on the same file (as in by accident) without corrupting it.

Code: [Select]
#!/bin/sh
IFS=$'\t\n'
echo -E \
"<script>
function showImg(URL){
var imgPage=\"<html><head><title>Click to Close  \" + URL + \"</title><style>body{background-color:#eee;text-align:center}table{width:100%;height:100%;text-align:center}td{text-alight:center;vertical-align:middle}img{border:5px solid white}</style></head><body onLoad='self.focus();' onClick='self.close();' ><table><tbody><tr><td><img src='images/\" + URL + \"'></td></tr></tbody></table></body></html>\";
var mywin=open('','','scrollbars=0,toolbar=0');mywin.document.write(imgPage);mywin.document.close();}
</script>" > temp.txt
sed -i '39,$s/<a href="images\//<a href="#" onClick="showImg(!/;39,$s/"><img class="photo"/!)\;"><img class="photos"/' index.html
sed -i "39,\$s/\!/\'/g" index.html
sed -i '/(Kde Image Menu)/r temp.txt' index.html
sed -i '5s/(Kde Image Menu)/(Kde_Image_Menu)/;28s/img.photo/img.photos/' index.html
rm temp.txt
firefox index.html
exit 0

« Last Edit: June 27, 2009, 11:02:47 AM by DrDOS »

Offline jlf001

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 519
Re: Discovering the magic of Imagemagick
« Reply #9 on: June 27, 2009, 10:58:43 AM »
DrDOS,

Thanks for the tip and the script.

Jeff