Thanks for the answer. When you specify a file name in Russian letters without an extension, saving the file name with a picture (jpg, etc.) also spoils. I tried to understand the problem in the code and, in my opinion, the problem in the function save_image. There is no call to utf8on ($ filename); just as it did in savepdf .
Problem with file name when saving in some formats