Results 1 to 4 of 4

Thread: imagemagik batch script

  1. #1
    Join Date
    Nov 2011
    Beans
    3

    imagemagik batch script

    Hi everyone!

    I am trying to make a flexible bash batch script using convert for manage pics.

    Code:
    # FOR RESIZING: change/remove -resize option for decide about resizing
    # FOR CONVERSION: change the extention into the last string if you want (also) convert into another format
    # remove "converted" if you want overwrite the existing files
    # you can define which files you want modify by editing the first string. if you specify *.* all files will be modified
    # see $man convert for more string options
    
    #!/bin/bash
    for i in *.*; do convert $i -resize 25% $(basename $i)converted.jpg; done
    if the file name(s) contain spaces this script does not work! how can I fix it?

    can you suggest me any better batch script about imagemagik/convert?

    thanks guys!

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,331
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: imagemagik batch script

    rule of thumb: put all your variables in ""

    when you do something like this
    Code:
    i='abc 001.jpg'
    convert $i -resize 25% $(basename $i)converted.jpg
    after substitution you get this
    Code:
    convert abc 001.jpg  -resize 25% ....
    ie, multiple parameters where 1 is expected. Double quotes prevent that


    Code:
    $ i='abc 001.jpg'
    $ printf "[%s]\n" $i
    [abc]
    [001.jpg]
    $ printf "[%s]\n" "$i"
    [abc 001.jpg]
    printf puts its parameter(s) in place of %s placeholder(s) so it can be used to easily show the difference between $var and "$var".
    Last edited by Vaphell; April 29th, 2013 at 09:35 PM.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  3. #3
    Join Date
    Nov 2011
    Beans
    3

    Re: imagemagik batch script

    thanks but right now I have resolved with this simple command

    mogrify -resize 25% -quality 60 -format jpg *.jpg

    know I would like to know the difference between the command convert and mogrify, can anyone help me?

  4. #4
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,331
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: imagemagik batch script

    afaik mogrify modifies the source file, while convert creates a modified copy.

    http://www.imagemagick.org/script/mogrify.php
    This tool is similiar to convert except that the original image file is overwritten (unless you change the file suffix with the -format option) with any changes you request.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •