Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: How can I batch convert images to b/w while preserving the folder structure

  1. #11
    Join Date
    Apr 2010
    Beans
    298

    Re: How can I batch convert images to b/w while preserving the folder structure

    Quote Originally Posted by Vaphell View Post
    i updated my earlier post but i'll repeat myself
    the code is a script, you need to save the code as a text file, just paste it into text editor and save
    and then run the script
    bash name_you_have_chosen
    obviously change srcdir and destdir to suit your needs
    now you most defensibly think I am an idiot but this is the first time I am using a script

    if my folder that I want to convert is here

    '/home/levan/Desktop/F1'

    and

    I want to out put it to here /home

    what do I write

    Code:
    srcdir= I write '/home/levan/Desktop/F1' this ??
    Code:
    destdir= and here I will write this ~ ??

  2. #12
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How can I batch convert images to b/w while preserving the folder structure

    eg
    srcdir=$HOME/Desktop/F1
    destdir=$HOME/F1_grayscale
    $HOME and ~ are pretty much the same fyi, i suggest adding something to dest ~ to contain results, because the script would get your main dir spammed otherwise (~ would be an equivalent of F1, which means untold amount of subdirs created right there)
    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. #13
    Join Date
    Apr 2010
    Beans
    298

    Re: How can I batch convert images to b/w while preserving the folder structure

    Quote Originally Posted by Vaphell View Post
    eg
    srcdir=$HOME/Desktop/F1
    destdir=$HOME/F1_grayscale
    $HOME and ~ are pretty much the same fyi, i suggest adding something to dest ~ to contain results, because the script would get your main dir spammed otherwise (~ would be an equivalent of F1, which means untold amount of subdirs created right there)
    I wanted to do a test before I wold do the real deal so I run this commend and this is what I got

    Code:
    bash '/home/levan/Pictures/Wallpapers/test' /home/levan/Pictures/Wallpapers/test: line 13: unexpected EOF while looking for matching `"'
    /home/levan/Pictures/Wallpapers/test: line 14: syntax error: unexpected end of file
    this is what I wrote

    Code:
    srcdir=home/levan/Pictures/Wallpapers
    destdir=home/levan/Pictures/Wallpapers/grayscale"

  4. #14
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How can I batch convert images to b/w while preserving the folder structure

    something is not right with the file, eg missing ) after -print0?
    output of cat /home/levan/Pictures/Wallpapers/test ?

    and don't put destination dir inside source to avoid feedback loop, you would risk converted files being found as input for another conversion depending on in what order find scans subdirs (1. find finds file X, grayscale version is created in dest subdir, 2. finds gets to discover dest subdir and scans it, 3. file X_grayscale is passed for another conversion but to dest/dest)
    That might or might not happen if you run script once, but in case of repeating the script you would get another layer of dest each time (dest, dest/dest, dest/dest/dest, ...)

    ok:
    /home/levan/Pictures/Wallpapers
    /home/levan/Pictures/Wallpapers_grayscale

    ambiguous/feedback loop:
    /home/levan/Pictures/Wallpapers
    /home/levan/Pictures/Wallpapers/grayscale
    Last edited by Vaphell; May 11th, 2013 at 12:22 AM.
    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

  5. #15
    Join Date
    Apr 2010
    Beans
    298

    Re: How can I batch convert images to b/w while preserving the folder structure

    Quote Originally Posted by Vaphell View Post
    something is not right with the file, eg missing ) after -print0?
    output of cat /home/levan/Pictures/Wallpapers/test ?

    and don't put destination dir inside source, you would risk converted files being found as input for conversion

    ok:
    /home/levan/Pictures/Wallpapers
    /home/levan/Pictures/Wallpapers_grayscale
    ambiguous:
    /home/levan/Pictures/Wallpapers
    /home/levan/Pictures/Wallpapers/grayscale

    Wow it worked awesome

    I had " things messed up

    Code:
    #!/bin/bash
    
    # source and destination dirs
    srcdir='/home/levan/Pictures/Wallpapers'
    destdir='/home/levan/Pictures/Wallpapers/grayscale'
    
    
    while read -rd $'\0' f
    do
      echo "$f"
      fdir=${f%/*}
      mkdir -p "${fdir/#$srcdir/$destdir}"
      convert "$f" -set colorspace Gray -separate -average "${f/#$srcdir/$destdir}"
    done < <( find "$srcdir" -regextype posix-extended -iregex '.*(png|bmp|jpe?g|tga|gif|tiff)$' -print0 )
    did this and it worked awesome

    thank you now I know -ish how to work with bash files

    thanks to you thank you again

  6. #16
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How can I batch convert images to b/w while preserving the folder structure

    really put the dest outside src, if you would run the script again you would get Wallpapers/grayscale/grayscale (original grayscale is treated as an input and gets its own subdir in itself), another run another layer
    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

  7. #17
    Join Date
    Apr 2010
    Beans
    298

    Re: How can I batch convert images to b/w while preserving the folder structure

    Quote Originally Posted by Vaphell View Post
    really put the dest outside src, if you would run the script again you would get Wallpapers/grayscale/grayscale (original grayscale is treated as an input and gets its own subdir in itself), another run another layer
    ooo ok thanks again

Page 2 of 2 FirstFirst 12

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
  •