Fix NextGen Gallery IPTC Encoding Error in Chinese

By | December 10, 2010

NextGen Gallery is a great gallery plugin for wordpress. I am using it for my blog.

I found a problem that if the IPTC information is in Chinese, it cannot import properly import as meta data.

After searching and searching, finally I fixed the issue by modifying the /wp-content/plugins/nextgen-gallery/lib/meta.php file in get_IPTC function:

Original code:

if($this->iptc_data[$key])
    $meta[$value] = trim(utf8_encode(implode(',', $this->iptc_data[$key])));
}

Modify to:

foreach ($iptcTags as $key => $value) {
    if($this->iptc_data[$key] && $key == '2#120'){
        $meta[$value] = mb_convert_encoding(implode(', ', $this->iptc_data[$key]), 'UTF-8', 'gb2312');
    }
    else if($this->iptc_data[$key]){
        $meta[$value] = trim(utf8_encode(implode(', ', $this->iptc_data[$key])));
    }
}

That’s it. Smile