display.newImage does not work with non english letters filename. Please HELP!

Hi all,

Why display.newImage(“óáü.png”) give the error: Failed to find image(óáü.png) ?
changing the name of the image file in display.newImage(“myfile.png”) it work fine:)

There’s a problem with the non english letters in the filename I suppose!

How can use non english filenames for display.newImage??

Obviously I can’t rename the files!

Any suggestions are appreciated…thanks [import]uid: 30847 topic_id: 22084 reply_id: 322084[/import]

Hey there,

Will see if I can get some info on this for you.

In the meantime, why can’t you rename the files? (Just making sure I understand correctly.)

Peach :slight_smile: [import]uid: 52491 topic_id: 22084 reply_id: 87795[/import]

Hallo Peach,
thanks for the answer.

I can’t rename the files because filenames are part of the app.

eg: I have a file called pàjaro.png (dird in english), the app take the name of this file as name of the object to show. In this case display.newImage raise an error! The problem is that are dozens of files like this and I did not want to rename them all:(

Now I’ve done a workaround using a translation table referencing the original filename and the english filename. It does work but is a tricky bit!

Seem that Corona display.newImage does not manage filenames containing chars with char code > 190. This sound strange because the project is in UTF-8.

Thanks a lot
Ale
[import]uid: 30847 topic_id: 22084 reply_id: 87848[/import]

I don’t think it’s a Corona Limitation but rather a Lua limitation. Not many programming languages actually allow non-english characters, might be wrong but…

You could always use a string to define your object. Let’s use “pàjaro.png”.

pajaro = display.newImage("pajaro.png")  
pajaro.fullName = "pàjaro.png"  

You could then use a text object to display your file name.

displayFilename = display.newText(pajaro.fullName,0,0)

I’m not quite sure I understood your use for the filename in your app but I hope this helps.

~ Lew [import]uid: 1058 topic_id: 22084 reply_id: 87854[/import]

Or you can keep all your names the same in your code, but when you open an image use string.gsub to replace all char 190 with _, or replace “à” with “a” etc.

http://developer.anscamobile.com/reference/index/stringgsub

eg:

pajaro = display.newImage(strings.gsub(“pàjaro.png”, “à”, “_”)

This way you don’t need to manage two sets of names, just rename your image files themselves replacing any special characters. This also means if you allow the user to save files it’ll still work. For example if they take a picture and then you ask them the filename to save as. Basically if you don’t know the potential filename before hand this works better.

If you want to later display the correct name, without having to save a seperate translation table, then you might be better off using some form of encoding. For example chars > 128, for example 190 become _190.

You can use…

pajaro = display.newImage(strings.gsub(“pàjaro.png”, “à”, “_190”)

and on load, say after you grab the list of files from the filesystem:

real_name = strings.gsub(filename, “_190”, “à”)

You could take this further by actually getting the ascii code of the special character and creating the _190 bit dynamically, and the same backwards.

Its a bit of a hassle, but once you do it, it’ll always work for any filename.

Another alternative is to see if io handles these chars. If it does, make a copy of the image to /tmp as image1.png or something and load that copy. There’s some file copy code somewhere on the site. [import]uid: 8872 topic_id: 22084 reply_id: 87863[/import]

Thanks guys for the helps …

@happylewie Yes, I also think that can be a Lua limitation

@kam187
you right, finally I’ve learned here that there’s NO alternative to rename the files in order to
have the display.newImage work properly and solve the problem:(

Use of a coded filename is also an help to working around

After I have read this post
http://developer.anscamobile.com/forum/2010/08/08/string-greek-characters

I have done this dirty work around:
I’ve renamed all the non english files with a VERY simple coding, a1,a2,a3,c1…
after I wrote a module called char_translate.lua with the translate function translate_chars(letter)
Then each time I have a char > 190 I translate the special characters with the coded filename
Finally call the display.newImage with the new filename without special chars

local letter
local lCode = string.byte(letter,1)
if lCode > 190 then
letter = charTrans.translate_chars(letter)
end
letterGraphic = display.newImage(“graphics/letters/lc/”…letter…".png")

This work for me…at now:)

I hope this helps someone else who needs to open filenames with special characters with display.newImage

Thanks again for the suggestions

Ale [import]uid: 30847 topic_id: 22084 reply_id: 87921[/import]