Hi, I’m new to Anvil (and Python for that matter). I was looking at the image documentation and have not figured out how to rotate an image. I’ve taken most of the code below from the examples (https://anvil.works/docs/media/image-manipulation) and it does display the image on my screen and prints the width and height.
But nothing I have tried so far will rotate the image. Below I am just assigning it to a variable as in the example. That yields: [An internal error has occurred] . How do I rotate the image and refresh the image onscreen with the rotated image?
Hello @shaun, just letting you know that there may be a bug with image rotation. I can get the “internal error” to go away if I create a BlobMedia object with an image (with the content type ‘image/png’), but it doesn’t help as I can’t get the code to interpret any lines after the rotation command.
This is actually a bug in our documentation - it’s not possible to rotate a cross-origin image. Browsers don’t allow you to access the raw bytes of a third-party image from code, for security reasons. This is true in any application.
We’ve improved the error message and we will change the image rotation part of the documentation (since it currently indirectly implies that this is possible.)
The above technique comes from the documentation. However, if you’re always only going to use the rotated version of the icon, then it’d be better to perform that manipulation once outside Anvil and then upload the rotated version to your app’s assets for future access.
(Note: If, on the other hand, you’re going to need to rotate image files that are hosted at URLs that won’t be known until run-time, then you’ll probably want to save them to and load them from a Media field in a database row.)