Project

General

Profile

Extract preview and rename?

Added by Patrick Hennessey over 3 years ago

I can't seem to find a way to extract a preview image and rename it at the same time. It always extracts "filename-preview1.jpg" when extracting. I don't want "-preview1" appended to the filename.

Currently implementing it as:

exiv2 -ep1 -f -l [target folder] [source file]

I tried replacing the target folder with a full image path, but that caused it to fail. Any advice?


Replies (3)

RE: Extract preview and rename? - Added by Robin Mills over 3 years ago

Patrick:

That's how it's intended to work. If you want it behave different, you'll have to write a bash script. And Exiv2 is open-source. You get the code and you are welcome to modify it to behave differently. We don't know all the ways in which you would prefer it to work.

How would you like it to behave?

I'm not sure I've understood your question about "full image path". Please try adding the options --verbose and --force to request exiv2 to give you additional output.

Robin

RE: Extract preview and rename? - Added by Patrick Hennessey over 3 years ago

This is what I'm trying:

exiv2 -ep1 -f -l /tmp/thumbnails/image_name.jpg /testimages/test_image.cr2

The hope was that it would extract the thumbnail from test_image.cr2 and name it "image_name.jpg" and put it in the tmp/thumnails folder. Instead, I get this error:

exiv2: -l option can only be used with extract or insert actions
Usage: exiv2 [ options ] [ action ] file ...

Manipulate the Exif metadata of images.

RE: Extract preview and rename? - Added by Robin Mills over 3 years ago

$ exiv2 -ep1 --verbose --force -f -l /tmp/image_name.jpg ~/Stonehenge.jpg 
File 1/1: /Users/rmills/Stonehenge.jpg
Writing preview 1 (image/jpeg, 160x120 pixels, 10837 bytes) to file /tmp/image_name.jpg/Stonehenge-preview1.jpg
Exiv2 exception in extract action for file /Users/rmills/Stonehenge.jpg:
/tmp/image_name.jpg/Stonehenge-preview1.jpg: Failed to open file (wb): No such file or directory (errno = 2)
$
This is correct behaviour. The command says: extract preview 1 from ~/Stonehenge.jpg into the location (directory) /tmp/image_name.jpg which does not exist. You can modify the command to write into an existing location (directory).
$ exiv2 -ep1 --verbose --force -f -l /tmp ~/Stonehenge.jpg 
File 1/1: /Users/rmills/Stonehenge.jpg
Writing preview 1 (image/jpeg, 160x120 pixels, 10837 bytes) to file /tmp/Stonehenge-preview1.jpg
$
The filename of the preview will be Stonehenge-preview1.jpg. By default previews are written into the same directory as the original image. You can use the -l (or --location) switch to specify the directory into which the preview will be written:
$ exiv2 --help | grep -i location
   -l dir  Location (directory) for files to be inserted from or extracted to.
$ 
    (1-3/3)