remove line break from caption in JPG IPTC and XMP

Started by Archive, May 12, 2010, 08:54:14 AM

Previous topic - Next topic

Archive

[Originally posted by jofr on 2008-01-20 18:17:18-08]

Hello,
How can I remove line breaks in the IPTC and XMP caption text in JPG files with ExifTool?

Thanks,
JO

Archive

#1
<span style="color: gray;"><i>[Originally posted by exiftool on 2008-01-20 18:59:00-08]</i></span>

ExifTool itself doesn't support arbitrary string processing,
so you can't do this with exiftool alone.

But you can use exiftool to extract and rewrite the caption, and
any other utility you want in between to process the caption.
If you are in Unix (or Mac OS X), you could translate newlines
to semicolons in the IPTC caption-abstract like this:

<div class="codeheader">Code:</div><div class="code"> exiftool -caption-abstract -b a.jpg | tr '\n' ';' | exiftool -caption-abstract '<=-' a.jpg</div>
- Phil

Edit: NOTE: This is a very old post and ExifTool now has various ways to do this.  Either with an advanced formatting expression, or the API -filter option.

Archive

[Originally posted by jofr on 2008-01-26 19:18:27-08]

File not found: <=-

is the result I get if I try your example.

What's wrong?

Thanks,
JO

Archive

[Originally posted by exiftool on 2008-01-27 00:20:38-08]

Sorry.  Somehow I put a space after -caption-abstract that
shouldn't be there:

Code:
exiftool -caption-abstract -b a.jpg | tr '\n' ';' | exiftool -caption-abstract'<=-' a.jpg

- Phil

Archive

[Originally posted by jofr on 2008-01-27 01:19:28-08]

Thanks Phil

I'm trying to do it under OS X, but so far it didn't remove the line breaks in the caption.
Here the file I'm trying to change:

http://www.motivio.de/aperture/a.jpg

Thanks,
JO

Archive

[Originally posted by exiftool on 2008-01-27 17:18:41-08]

OK then, try this:

Code:
exiftool -caption-abstract -b a.jpg | tr '\r' ';' | exiftool -caption-abstract'<=-' a.jpg

The line breaks in your file are carriage returns (\r), not newlines (\n).
The above command works in OS X when I try it with your sample
image, and changes the line breaks to semicolons.

- Phil

Archive

[Originally posted by jofr on 2008-02-11 16:59:24-08]

Hello,
I still have trouble to remove all line brakes in the caption.

If you look at the text below, there are still "." showing up after the import to PhotoShelter in front of "Hamburg" and "Gisela" and at the end of the caption text.

"FUSSBALL INTERNATIONAL UEEA CUP GRUPPENPHASE SAISON 07/08.Hamburger SV - FC Basel .Gisela OERI (Basel)."

I have tried both

exiftool -caption-abstract -b a.jpg | tr '\r' ' ' | exiftool -caption-abstract'<=-' a.jpg

and

exiftool -caption-abstract -b a.jpg | tr '\n' ' ' | exiftool -caption-abstract'<=-' a.jpg

Please find my test file under:

http://www.motivio.com/aperture/motivio0801-95607.jpg

Thanks and Regards,

JO

Archive

[Originally posted by exiftool on 2008-02-11 17:45:06-08]

First, there are no newlines in the IPTC:Caption-Abstract of your sample image.  There
are, however, newlines in the XMP:Description, and I think this is what you are looking
at.

Second, I should have realized there is a much easier way to remove the
newlines by taking advantage of user-defined tags.  Here is a config file
that will do it for you (for Caption-abstract):

Code:
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        NewCaption => {
            Require => 'Caption-Abstract',
            ValueConv => '$val =~ s/[\n\r]+/ /g ? $val : undef',
        },
    },
);

(see the
config
file documentation
for details on how to install user-defined tags.

Then the command line is then

Code:
exiftool "-caption-abstract<newcaption" a.jpg

This command will do nothing if the caption-abstract doesn't
exist or doesn't contain a newline.  Otherwise it will convert
each set of newlines to a single space.

Of course, you can do the same thing with XMP:Description
if you want.

- Phil

Archive

[Originally posted by jofr on 2008-02-11 21:52:40-08]

Hello Phil,

I tried to change your example to do the same thing with the XMP:Description, too.

But I how do I write the config file for this case?

Thanks and Regards,

JO

Archive

[Originally posted by exiftool on 2008-02-11 23:00:08-08]

It's pretty simple once you figure out how things work:

Code:
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        NewCaption => {
            Require => 'Caption-Abstract',
            ValueConv => '$val =~ s/[\n\r]+/ /g ? $val : undef',
        },
        NewDescription => {
            Require => 'XMP:Description',
            ValueConv => '$val =~ s/[\n\r]+/ /g ? $val : undef',
        },
    },
);

- Phil

Archive

[Originally posted by jofr on 2008-03-01 22:33:53-08]

Hello,

Since I'm able to remove line brakes in my captions, I'm trying to remove a line at the end of the caption which always starts with "FOTO:"

It looks like this:

"Caption Text blabla blabla FOTO: Photographer"

and I would like to make this:

"Caption Text blabla blabla"

Photographer can be different each photo, only "FOTO:" is always included before.

How can I do this by extending my ExifTool_config?

JO

Archive

[Originally posted by exiftool on 2008-03-01 23:06:32-08]

Try this:

Code:
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        NewCaption => {
            Require => 'Caption-Abstract',
            ValueConv => '$val =~ s/[\n\r]+/ /g ; $val =~ s/FOTO:.*//s; $val',
        },
    },
);

Archive

[Originally posted by jofr on 2008-03-01 23:41:37-08]

Thank you!

Works perfect!

JO