--- src/helper/png-write.cpp 2012-12-13 14:00:46.000000000 -0300 +++ src/helper/png-write.cpp.new 2013-07-07 22:54:15.000000000 -0400 @@ -101,19 +101,38 @@ void PngTextList::add(gchar const* key, if (tmp) { textItems = tmp; count++; - png_text* item = &(textItems[count - 1]); - item->compression = PNG_TEXT_COMPRESSION_NONE; - item->key = g_strdup(key); - item->text = g_strdup(text); - item->text_length = 0; + + gsize latin1Length = 0; + gchar *latin1Text = g_convert(text, -1, "ISO_8859-1", "UTF-8", NULL, &latin1Length, NULL); + + if (latin1Text) { + item->compression = PNG_TEXT_COMPRESSION_NONE; + item->key = g_strdup(key); + item->text = g_strdup(latin1Text); + item->text_length = 0; #ifdef PNG_iTXt_SUPPORTED - item->itxt_length = 0; - item->lang = 0; - item->lang_key = 0; + item->itxt_length = 0; + item->lang = 0; + item->lang_key = 0; #endif // PNG_iTXt_SUPPORTED + g_free(latin1Text); + } else { +#ifdef PNG_iTXt_SUPPORTED + item->compression = PNG_ITXT_COMPRESSION_NONE; + item->key = g_strdup(key); + item->text = g_strdup(text); + item->text_length = 0; + item->itxt_length = 0; + item->lang = 0; + item->lang_key = 0; +#else + g_warning("Unable to store PNG text item %s as an iTXt chunk.", key); + count--; +#endif // PNG_iTXt_SUPPORTED + } } else { - g_warning("Unable to allocate arrary for %d PNG text data.", count); + g_warning("Unable to allocate array for %d PNG text data.", count); textItems = 0; count = 0; }