1. Welcome to NikonCafe.com—a friendly Nikon camera & photography discussion forum!

    If you are thinking of buying a camera or need help with your photos, you will find our forum members full of advice! Click here to join for free!

Command-line-driven 'save for web' routine

Discussion in 'Other Raw Processors' started by MikeA, Jul 6, 2008.

  1. MikeA

    MikeA

    316
    Aug 26, 2007
    Left coast, USA
    This might not belong in the raw-conversion forum, but I'm not sure where else it would go (moderator please advise or change "venue" if need be). It's related in my own mind to a raw-conversion workflow -- namely, what I do after raw conversion to TIFF format, when the goal is to convert to JPEG for web display.

    I have found most programs' "save-for-web" routines underwhelming (with the exception of the one at www.dzsoft.com -- but damn the luck, it doesn't yet do color-space conversion). After some days of hacking around with command-line tools I hadn't used before, I finally put together something I'd been wanting for quite a while -- a command-line-driven "save for web" routine that does all of the things I need: select maximum pixel dimension; ensure that the files are converted to sRGB for web display; always append a string such as "-web" to the base name of the input file when writing the output file; ensure the best interpolation I could get (Lanczos); have the output files always saved to a "web" subdirectory of the current directory; specify files one at a time and/or with wildcards and/or with "include" files; option to run WinRAR.exe afterward and make a .zip file containing the JPEGs I've just created, with the .ZIP file's name altered slightly when need be to ensure that any existing archive won't be overwritten.

    The completed script is too specialized paths-wise to be suitable for someone else's machine. But, the basic conversion command and the one related to copying EXIF data to the output files are the business end of the thing, and they could be easily scripted by anyone with basic scripting smarts.

    There are two main steps: (1) Use ImageMagick's Convert.exe to create the smaller JPEG file for web display; (2) [optional but useful] use ExifTool.exe to ensure that the EXIF data are copied into the output file. As far as I can tell, both ImageMagick and ExifTool are available at no cost for personal use.

    (1) Convert the TIFF (or perhaps large JPEG file) to a resized/resampled JPEG using Convert.exe, which comes with ImageMagick (www.imagemagick.org). The Convert.exe switches and arguments I use appear in this order (and the order does matter to ensure that the resampling is done as you expect):

    -resample 72x72
    -filter Lanczos
    -quality 85 [your choice; affects file size]
    -profile "path to sRGB profile on your system"
    -resize valueXvalue
    inputfilename[0]
    outputfilename

    Above, "valueXvalue" would be, say, 800x800 -- again, user's choice -- ensuring that the longer pixel dimension of the input file becomes no more than 800 (or whatever value you use on the command line) in the output file. I haven't tried something like "600x800" -- I suspect that would foul up the aspect ratio, but I don't know for sure.

    On my system that sRGB path is "C:\WINDOWS\SYSTEM32\SPOOL\DRIVERS\COLOR\sRGB Color Space Profile.icm". It's probably different on other systems.

    The "[0]" must be appended to the file's name on the command line to ensure that Convert.exe converts the main image only. If the TIFF source file contains a thumbnail or preview image and "[0]" isn't used, both the main and thumbnail/preview images will be converted and you get unexpected output filenames.

    The above switches+arguments have to be on a single line, of course.

    Convert.exe seems to copy IPTC data successfully, but strips EXIF data. I wasn't able to find out from their support forum if there's a way to transfer the EXIF block successfully with Convert.exe, so:

    (2) I then use the amazing ExifTool program (www.sno.phy.queensu.ca/~phil/exiftool/) to complete the job, with these switches+arguments (again, on a single line in the actual command):

    -exif:all
    -iptc:all
    --XResolution
    --YResolution
    -tagsfromfile
    inputfilename
    outputfilename

    Switches "--XResolution" and "--YResolution" -- note the double hyphen in both cases -- ensure that the source files' own (large) pixel dimensions aren't written into the EXIF data of the (presumably smaller) JPEG output files.

    Hope someone finds this useful. If not, feel free to use this message for wrapping fish or whatever. :) 
    .
     
  2. Pesto126

    Pesto126

    566
    Apr 13, 2006
    Northeast USA
    Thx for the share Mike.. always cool to see what other users can come up with using tools that are available.

    As an fyi... I really love a tool I found a few months ago and use for a ton of different things: Image Genius Pro... the program allows you to build flowsheet like "pipelines" which can do a large number of functions including most of what you mention above. I have one pipeline that I use for my personal blog.. it resizes, renames, saves and ftp's the files with a simple drag and drop of images (think droplet). I have another that I use for adding frames, watermarks, and drop shadows.. it is quite handy and worth a look.

    Thx again for your info...
     
  3. MikeA

    MikeA

    316
    Aug 26, 2007
    Left coast, USA
    Image Genius Pro does sound useful. And certainly it's better-looking than a "vanilla" command-line-based tool...

    ...but I do love those plain-vanilla tools -- unattractive, but they do provide quick service with almost no waiting. :) 

    I can see how the ability to upload files via FTP would be handy. I haven't had to do such a thing yet. Fortunately, if I need to do that kind of thing I can use the command line -- the 4NT command processor supports FTP "addresses" as destinations for the "copy" command (one of gazillions of reasons to love that company's command-processor products).

    It does look as if the program you're recommending is pretty complete. I didn't spend a long time looking over the web site so I might have missed something obvious: does it 1) ensure that the converted-for-web JPEGs have the sRGB profile and 2) transfer IPTC data if you want it attached to the files? (I see that it can strip the EXIF data if you want, which must mean it transfers the EXIF data by default.)

    Good idea (in their dedicated save-for-web program, and I assume it's also in Image Genius Pro) about specifying a max. file size. I should add that to the script -- while size of converted file > 'nnn' bytes ) { reduce quality by '2'; redo 'save' command } ... something like that.

    I found the authors' site not popping up immediately via Google search for Image Genius Pro but eventually found it by looking for a company name on various shareware sites. For anyone who'd like to find the site, it's:

    http://www.pixeldragons.com/Home/Index.ashx
     
  4. Pesto126

    Pesto126

    566
    Apr 13, 2006
    Northeast USA
    Hi Mike - yes, I believe it does do both of those functions but haven't looked into it in detail - I will review the product real soon in detail since I really like it - while not a DAM product, it certainly is a very useful DAM tool that I use often.

    Of course, I too love those command line tools and freeware products. I like to support the shareware guys / gals as well because often their products are just as good as the "big guys".
     
  5. MikeA

    MikeA

    316
    Aug 26, 2007
    Left coast, USA
    I'll look into the save-for-web thing at the least. I always learn something useful when I take on one of these scripting projects, but I'm a sucker for even new GUI tools. :) 

    If you have ExifTool on your system, it'd be easy to verify if the program is converting to sRGB: you could take an AdobeRGB original (TIFF, or whatever), and convert it for the web. Then run ExifTool with the command:

    exiftool -ProfileDescription filename

    where filename is the JPEG file ... and it should print something like this:

    Profile Description : sRGB IEC61966-2.1
     
  6. MikeA

    MikeA

    316
    Aug 26, 2007
    Left coast, USA
    I had to find out. :)  I installed the demo version of their Just Resize My Photos program and gave it a try. It did not convert to sRGB. So that needs fixing. It transferred some, but not all, of the EXIF data, and it stripped the IPTC data.

    If the 'screen sizes' option is used -- useful for web conversions -- the program resamples in a way that has IrfanView identifying the output file as 96 ppi, but ExifTool identifies the X- and Y-resolution as 240 ppi. Photoshop also thinks it's 240 ppi. But the output file's size (in bytes, I mean) seems too small for it to be a 240 ppi image. I'm not sure what to make of that. ... a moment later. I think Photoshop and ExifTool are telling the right story here. When the image is viewed at "print size" in Photoshop, it's much smaller than I wanted for web display. So I guess it was saved at 240 ppi, the size on disk notwithstanding. The images converted via the scripted approach are at their expected sizes for web display.

    So it seems to need a bit of work: sRGB conversion for the web as an option, the ability to resample to a specific "resolution" value no matter which kind of resizing (screen vs. print) is selected, the option to preserve all the EXIF and/or IPTC data, and an option to overwrite or not-overwrite existing files.

    FWIW...the command-line tools (hooked together via script) and the GUI app were relatively close in processing time for four 8-bit TIFFs (average size, 25MB). The script finished in about 29 seconds, the GUI app in about 40. If I had 100 files to process I might find this difference more noticeable -- then again, that's why "go away for a while and make a pot of coffee" was invented. :) 

    (I haven't tried their "pipeline" tool yet. If you're getting exactly what you need out of it for web-log purposes, it must be working a bit better than the specialized save-for-web app.)

    EDIT: and another thing. :)  I had placed my test originals (copies, not one-of-a-kind originals) within a "tests" subdirectory I created in the resizing app's folder. I decided to leave them there when I ran the un-installer. The un-install app wiped out the entire directory, including any user-installed files. Which suggests that they've taken the too-easy way out of handling their install/uninstall logging. Another thing needing a bit of work. Although using an application's own installation directory tree as a location for one's original files is obviously not a great idea, doing it can still be useful during testing.
     
  7. Pesto126

    Pesto126

    566
    Apr 13, 2006
    Northeast USA
    a great test... good to know and I'll include it in the review I do so thank you.

    It works well for what I do.. but that's not much with change color spaces, etc. I like the fact that you can include logic paths in the flowchart to change options as you go too.

    thx for your testing!
     
  8. MikeA

    MikeA

    316
    Aug 26, 2007
    Left coast, USA
    At some point the web will somehow become color-managed or color-manageable, so this business with color spaces for display will become less critical. I haven't yet tried the other, more complex application and I'll give it a spin. It will be interesting to read the review and then read people's comments about it, and find out if anyone's experience with the Just Resize program was different from mine...
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.