Image_Iptc icon indicating copy to clipboard operation
Image_Iptc copied to clipboard

German Umlaute are destroyd in Keywords

Open mischafirges opened this issue 12 years ago • 37 comments

First, thanks for that amazing piece of work, it's great. I only have the Problem, that German Umlaute like ö, ä and ü gets destroyed in Keywords. If think it's because the writing process is not in utf8

Can you please tell me how to fix that??? Thanks a lot!

mischafirges avatar Mar 28 '13 17:03 mischafirges

Hello friend,

I'll try to simulate this problem and will return soon with a solution.

Hug!

agutoli avatar Mar 28 '13 17:03 agutoli

I've read a bit, and I think it's because of the ASCII-Transformation. Because this doesn't know the Umlaute... After the old IPTC-Standard this is right, but in the new one, called XMP-Standard, Umlaute are ok...

Maybe this helps. Thanks a lot for the fast answer!

mischafirges avatar Mar 28 '13 18:03 mischafirges

I did some tests and could not reproduce this error, call me on gtalk to talk better; bruno.agutoli(at)gmail.com

agutoli(at)agutoli:Image_Iptc$ php readIptc.php Array ( [0] => keyword1 [1] => This is a test with special characters ö, ä, ü )

agutoli avatar Mar 28 '13 19:03 agutoli

Do I see right, that you tested the reading process? I have the error when writing iptc data to a file!

I debugged some functions from iptc.php an realised following: Function iptcMakeTag() returns $src -> in that variable all special chars are okay Function binary() returns $iptc -> in this variable the special chars are wrong.

Maybe that helps...

mischafirges avatar Mar 28 '13 23:03 mischafirges

Any thing new here? Do you have an idea?

mischafirges avatar Mar 30 '13 14:03 mischafirges

Take a test, download the project now, run the "writeIptc.php" and then run the "readIptc.php" and see if it worked.

agutoli avatar Apr 01 '13 15:04 agutoli

I fear, there is no change...

error

mischafirges avatar Apr 01 '13 16:04 mischafirges

This problem seems to be in the apache configuration, see how it is configured "AddDefaultCharset UTF-8" in "apache2/conf.d/charset"

do not forget to restart apache

agutoli avatar Apr 01 '13 16:04 agutoli

work?

agutoli avatar Apr 01 '13 17:04 agutoli

naaahh, unfortunately not. I'm running the script on xammp and till now i haven't found out where to change the default charset.

mischafirges avatar Apr 01 '13 20:04 mischafirges

Hm. OK. I changed a few things and now the readlptc is really working. Unfortunately this ist not solving the problem, because in the file, the special chars were still not correct. And, when i upload such a file to, for example Fotolia.com, then they also show the wrong letters.

Any idea?

error

mischafirges avatar Apr 01 '13 20:04 mischafirges

Not sure, I know very well Windows 7 or 8 (not sure), but I believe it is the same coding problem, your operating system can handle the type "x" and the image is coded for type "y" it would have to be tested in windows.

One option is to try using utf8_encode or utf8_decode before writing the text in the image.

agutoli avatar Apr 01 '13 21:04 agutoli

Good idea, I allready tried that, but without success. Do have an idea, where I have to edit this?

mischafirges avatar Apr 01 '13 21:04 mischafirges

You must use the "array_map" to pass an array to the "set"

public function set($tag, $data) 
{

    $data = array_map("utf8_encode", $data);
    //$data = array_map("utf8_decode", $data);//or decode
    $this->_meta["2#$tag"] = array($data);
    $this->_hasMeta        = true;
    return $this;
}

see if this works in Windows

agutoli avatar Apr 01 '13 21:04 agutoli

I will try that this evening! Thanks a lot for your very detailed help! This is great!

mischafirges avatar Apr 02 '13 08:04 mischafirges

Maaaaan! That's it! Thanks a lot for your help, again!

mischafirges avatar Apr 02 '13 11:04 mischafirges

Glad to have helped, then show me how I got the code to see if I can improve Iptc.php. Hug!

agutoli avatar Apr 02 '13 14:04 agutoli

The last hint was perfect. I'm using the utf8_encode for the array, that all :-)

mischafirges avatar Apr 02 '13 19:04 mischafirges

thanks!

agutoli avatar Apr 02 '13 19:04 agutoli

Hi agutoli, First, thanks a lot for this useful class. I'm a french user and also need to write special characters in iptc. Using utf8_decode works fine when i use readiptc.php. But, if i open my modified image in Photoshop (CS5) or in Mac Preview's app, there's still some encoding problems. Have you an idea about this ? Thanks a lot for your answer. JG

jgautier2 avatar Jun 28 '14 12:06 jgautier2

Hi jgautier2, thanks for reporting this issue. I'll check the problem and call you back as soon as possible. Thanks again!

agutoli avatar Jun 29 '14 21:06 agutoli

Thanks for your answer. A precision : I got some jpg files with accents in iptc tags that appears properly in PS CS5 (I could send you one iff you want). But when I modify their tags with your class, all special characters become wrong... In case of it could be useful, i've heard about "CodedCharacterSet" iptc tag... Maybe a way ?

jgautier2 avatar Jun 30 '14 07:06 jgautier2

Hi agutoli,

Did you check the problem ? Please let me know when you expect to do it. Thanks a lot. JG

jgautier2 avatar Jul 12 '14 06:07 jgautier2

jgautier2, first I'm sorry for the delay, but I've been a bit busy with work ... :/

You could update your lib and test please?

agutoli avatar Jul 12 '14 16:07 agutoli

Thanks for your answer and the update.

But, I’ve got this error :

Parse error: syntax error, unexpected '[' in /home/hansluca/sd/site3/www/dbp/lib/Image_Iptc-master/Iptc.php on line 380

JG

Le 12 juil. 2014 à 18:18, Bruno Agutoli [email protected] a écrit :

jgautier2, first I'm sorry for the delay, but I've been a bit busy with work ... :/

You could update your lib and test please?

— Reply to this email directly or view it on GitHub.

jgautier2 avatar Jul 12 '14 16:07 jgautier2

It's the php version, try again please. :)

agutoli avatar Jul 12 '14 17:07 agutoli

New error (when getting IPTC infos) : Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Passed variable is not an array or object, using empty array instead' in /home/hansluca/sd/site3/www/dbp/lib/Image_Iptc-master/Iptc.php:397 Stack trace: #0 /home/hansluca/sd/site3/www/dbp/lib/Image_Iptc-master/Iptc.php(397): ArrayIterator->__construct('20121030') #1 /home/hansluca/sd/site3/www/dbp/lib/Image_Iptc-master/Iptc.php(224): Iptc->_charset_encode('20121030') #2 /home/hansluca/sd/site3/www/dbp/lib/func.php(67): Iptc->fetch('055') #3 /home/hansluca/sd/site3/www/dbp/edit_image.php(532): GetIptcArrayOfOneMediaFromTagsTab('../../hidef/HAN...', Array) #4 {main} thrown in /home/hansluca/sd/site3/www/dbp/lib/Image_Iptc-master/Iptc.php on line 397

jgautier2 avatar Jul 12 '14 17:07 jgautier2

I did a treatment on encode and decode function, but could you show me how you're calling the class? so I can simulate the error here ...

agutoli avatar Jul 12 '14 21:07 agutoli

I use a homemade function that loops through an array (called "$tagstab") containing some IPTC tags names, call "fetch" (or "fetch all") on the image ($pathtomedhidef) for each tag found, and then return an array. I call this function with image path and tags array as parameters. See below :

function GetIptcArrayOfOneMediaFromTagsTab($pathtomedhidef, $tagstab)
{
    require_once('lib/Image_Iptc-master/Iptc.php');
    $iptc = new Iptc($pathtomedhidef);
    
    $iptctab=array();
    foreach ($tagstab as $k => $v)
    {
        
        switch($v)
        {
            
            case 'KEYWORDS':
            $kwtab=$iptc->fetchAll(Iptc::KEYWORDS);
            if(is_array($kwtab) && sizeof($kwtab) >0)
            {
            $iptctab[$v]=implode(', ', $kwtab);
            }
            else
            {
            $iptctab[$v]='';
            }
            break;
            
            case 'CREATED_DATE':
            $iptctab[$v]=$iptc->fetch(Iptc::CREATED_DATE);  
            break;
            
            case 'CREATED_TIME':
            $iptctab[$v]=$iptc->fetch(Iptc::CREATED_TIME);  
            break;
            
            case 'CITY':
            $iptctab[$v]=$iptc->fetch(Iptc::CITY);  
            break;
            
            case 'COUNTRY':
            $iptctab[$v]=$iptc->fetch(Iptc::COUNTRY);   
            break;
            
            case 'HEADLINE':
            $iptctab[$v]=$iptc->fetch(Iptc::HEADLINE);  
            break;
            
            case 'CREDIT':
            $iptctab[$v]=$iptc->fetch(Iptc::CREDIT);    
            break;
            
            case 'COPYRIGHT_STRING':
            $iptctab[$v]=$iptc->fetch(Iptc::COPYRIGHT_STRING);  
            break;
            
            case 'CAPTION':
            $iptctab[$v]=$iptc->fetch(Iptc::CAPTION);   
            break;
            
        
        }
        
        if(empty($iptctab[$v]))
        {
            unset($iptctab[$v]);
        }
    
    
    }
    return $iptctab;
}
// tags array
$tagstab=array('HEADLINE','CAPTION');
// path to img (for ex.)
$pathtomedhidef='../../hidef/HANSLUCA_JGAUTIER_QQQQQ_000010.jpg';
// call function
$iptctab=GetIptcArrayOfOneMediaFromTagsTab($pathtomedhidef, $tagstab);

There was no error before your last update. JG

jgautier2 avatar Jul 13 '14 07:07 jgautier2

Hi agutoli,

I've tried again and I didn't get any error : great.

But, I've still some problem with accents when editing modified files in Photoshop (and also Preview or Finder on MacOS). When I use your "writeIptc.php" and then "readIptc.php", it's ok. But when I open "logo_php.jpg" in Photoshop (CS5), accents are not properly shown (neither in Preview or Finder). This is what appears in PS : capture decran 2014-07-25 a 10 49 55

This is what appears in Preview : capture decran 2014-07-25 a 10 51 39

Here's "logo_php.jpg" modified file : logo_php2

Please, let me know if you need more informations to be able to resolve this issue. Thanks a lot,

JG

jgautier2 avatar Jul 25 '14 08:07 jgautier2