Search code examples
pythongoogle-app-engineimagemagickwand

Why does Appengine image rotation give cache resources error?


I use Appengine standard with:

basic_scaling:
  max_instances: 7
  idle_timeout: 4m

instance_class: B4_1G

i try to rotate an image:

def get_image(bucket_name, file_name):   
    blob = storage_client.bucket(bucket_name).get_blob(file_name)
    _, temp_local_filename = tempfile.mkstemp()
    blob.download_to_filename(temp_local_filename)
    with Image(filename=temp_local_filename) as i:
      encoded_image = base64.b64encode(open(i.rotate(125), 'rb').read())
      del i

  gc.collect()    
  return (html.Img(src='data:image/png;base64,{}'.format(encoded_image.decode('utf-8')), style={'height':'400%', 'width':'100%'}))

but i get:

 File "/layers/google.python.pip/pip/lib/python3.8/site-packages/wand/resource.py", line 222, in raise_exception
    raise e
wand.exceptions.CacheError: cache resources exhausted `/tmp/tmp0gu_437j' @ error/cache.c/OpenPixelCache/3984

on the rotate line.


Solution

  • i.rotate(125) gives the error, but i.rotate(90) works, as does 270. I only want 90-degree rotations so that will do.