Possible bug: Edited images don't update the card without a software restart

I’m a long-time user of Anki. So thankful for the developers and community!

When I’m editing a card on my Windows PC version of Anki, I right-click on an image and click “Open image” to edit it. After editing the image (e.g. cropping and saving), and closing the “Edit” window for the card, all the new text changes update, but the image doesn’t update on the card until I do a restart of the software.

The image has definitely been updated. When I go back to try and edit what appears to be an “unchanged image” on the Anki edit window, turns out to be the edited image once I open it with the standard Windows basic photo editor. So the edits are saving successfully to the file (I save the image using the same file), but Anki is not updating the card image until a software restart.

Is this intentional (for a reason not apparent to me)? Is this a bug? Is this only a problem with my version of Anki, and I need to reinstall it?

The issue still occurs when I disable both my add-ons.

Software versions and other information - copied from Anki’s About page:

Anki 24.11 (87ccd24e) (ao)
Python 3.9.18 Qt 6.6.2 PyQt 6.6.1
Platform: Windows-10-10.0.26100

===Add-ons (active)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
Advanced Review Bottom Bar [‘1136455830’, 2024-08-22T14:04, ‘None’, mod]
Review Heatmap [‘1771074083’, 2022-06-30T04:43, ‘None’, ‘’]

===IDs of active AnkiWeb add-ons===
1136455830 1771074083

===Add-ons (inactive)===
(add-on provided name [Add-on folder, installed at, version, is config changed])

Images are cached for better performance. You can try this code to disable that (untested):

import mimetypes

from flask import Response

from aqt.editor import pics
from aqt.mediasrv import app as flask_app

image_types = [mimetypes.guess_type(f"test.{ext}")[0] for ext in pics]


@flask_app.after_request
def disable_caching_for_images(response: Response) -> Response:
    if response.mimetype in image_types:
        response.cache_control.max_age = 0
    return response

To use this as an add-on:

  • Go to Tools > Add-ons > Show Files to open your add-ons folder
  • Create a new folder there with any name.
  • Create a file in that folder named __init__py and paste the code there.
  • Restart Anki.
4 Likes

Thanks so much, abdo! I really appreciate it. :clap:

OK, so the images are cached for better performance. Fair enough. It’s not a bug after all then but part of the design. :+1:

I haven’t tried your code. I’m a bit nervous to try it because it is untested, and I’m happy with the “if it ain’t broke, don’t fix it” philosophy at the moment. I edit almost every card’s image at the moment, but I don’t mind restarting Anki every now and then through the day.

Thanks again for the generosity of your time and effort to help and explain! :grinning_face:

https://ankiweb.net/shared/info/1827331674
Maybe this could help for a faster restart

It’s totally safe to run. it won’t edit your images.