Ajatt-Tools / PasteImagesAsWebP

🍙 An Anki add-on that makes your images small.
https://ankiweb.net/shared/info/1151815987
GNU Affero General Public License v3.0
23 stars 6 forks source link

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 328: character maps to <undefined> #20

Closed Fytch closed 1 year ago

Fytch commented 2 years ago

Can anything be done about this? Sorry about the prehistoric OS. The OS is 64 bit and the libwebp installation is the official Google build.

Debug info:
Anki 2.1.35 (84dcaa86) Python 3.8.0 Qt 5.14.2 PyQt 5.14.2
Platform: Windows 7
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2022-10-01 14:10:44

Caught exception:
Traceback (most recent call last):
  File "aqt\webview.py", line 37, in cmd
  File "aqt\webview.py", line 123, in _onCmd
  # removed my other addons from the log here
  File "aqt\editor.py", line 418, in onBridgeCmd
  File "aqt\editor.py", line 932, in onPaste
  File "C:\Users\Fytch\AppData\Roaming\Anki2\addons21\1151815987\common.py", line 65, in wrapper
    return new(args[0], _old=old)
  File "C:\Users\Fytch\AppData\Roaming\Anki2\addons21\1151815987\events.py", line 82, in paste_event
    w.convert(mime)
  File "C:\Users\Fytch\AppData\Roaming\Anki2\addons21\1151815987\utils\webp.py", line 163, in convert
    if self.to_webp(tmp_file, webp_filepath) is False:
  File "C:\Users\Fytch\AppData\Roaming\Anki2\addons21\1151815987\utils\webp.py", line 144, in to_webp
    stdout = p.communicate()[0]
  File "subprocess.py", line 1011, in communicate
  File "C:\python38\lib\encodings\cp1252.py", line 23, in decode
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 328: character maps to <undefined>
tatsumoto-ren commented 2 years ago

Updating Anki could help. Try version 2.1.54

Fytch commented 2 years ago

That's unfortunately not a possibility for because another addon I use is only compatible with 2.1.35. FWIW, https://ankiweb.net/shared/info/1151815987 states that the versions 2.1.30-2.1.47 are supported.

tatsumoto-ren commented 2 years ago

another addon I use is only compatible with 2.1.35

Which one? There' s a possibility that it will work if you open its folder and edit meta.json.

Fytch commented 2 years ago

https://ankiweb.net/shared/info/278530045

tatsumoto-ren commented 2 years ago

migaku

This is a virus.

You can use this instead. https://ankiweb.net/shared/info/1344485230

Fytch commented 2 years ago

I would actually be glad if I could get rid of Migaku but there's a couple of features (first and foremost the five pitch colors, they really help me remember the pitch accent well) that I haven't seen offered by any other extension. I'll look into it once I get this addon to work.

So now I updated Anki to 2.1.49 (highest version supported my morphman) and I also updated the addon but I'm getting the same error unfortunately:

Anki 2.1.49 (dc80804a) Python 3.8.6 Qt 5.14.2 PyQt 5.14.2
Platform: Windows 7
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2022-10-07 19:26:42

Caught exception:
Traceback (most recent call last):
  File "aqt\webview.py", line 41, in cmd
  File "aqt\webview.py", line 142, in _onCmd
  File "aqt\webview.py", line 595, in _onBridgeCmd
  File "aqt\editor.py", line 438, in onBridgeCmd
  File "aqt\editor.py", line 882, in onPaste
  File "C:\Users\Fytch\AppData\Roaming\Anki2\addons21\1151815987\common.py", line 69, in wrapper
    return new(args[0], _old=old)
  File "C:\Users\Fytch\AppData\Roaming\Anki2\addons21\1151815987\events.py", line 91, in paste_event
    w.convert(mime)
  File "C:\Users\Fytch\AppData\Roaming\Anki2\addons21\1151815987\utils\webp.py", line 167, in convert
    if self.to_webp(tmp_file, self.set_output_filepath()) is False:
  File "C:\Users\Fytch\AppData\Roaming\Anki2\addons21\1151815987\utils\webp.py", line 144, in to_webp
    stdout = p.communicate()[0]
  File "subprocess.py", line 1011, in communicate
  File "C:\python\lib\encodings\cp1252.py", line 23, in decode
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 328: character maps to <undefined>
tatsumoto-ren commented 2 years ago

This error has to do with windows then.

Fytch commented 2 years ago

Thanks. Yeah, you were right, it had to do with Windows' WIC and cwebp. I tried to solve it for over an hour but to no avail. In the end, I just rewrote the addon to instead use ImageMagick. It works like a charm now. ImageMagick has the advantage that it also supports AVIF among many other nice formats, making it more future-proof and flexible. I can create a pull request with my changes if somebody is interested. We can also make it so that the backend is selectable with a config entry, if that's in your interest.

tatsumoto-ren commented 2 years ago

Sure, feel free to make a pull request.

galantra commented 5 months ago

@Fytch do you mind sharing your fork? AVIF support would be great!