Package: gallerist-azurestorage
Gallerist-AzureStorageGallerist classes for Azure Storage: implements reading image files from Azure
Blob Service, and writing of resized pictures to the same.$pipinstallgallerist-azurestorageThis library is used inTorino, a file
explorer for Azure Storage Account, and inGallerist-AzureFunctions,
an Azure Functions front-end that usesGalleristlibrary, to resize
pictures in Azure Storage Blob Service.Example: synchronous code resizing pictures on Azure StoragefromgalleristimportGallerist,ImageSizefromgalleristazurestorageimportAzureBlobFileStorestore=AzureBlobFileStore.from_connection_string("<YOUR_CONNECTION_STRING>","CONTAINER_NAME",)gallerist=Gallerist(store)# configuring sizes by mime (use '*' to match any other mime):gallerist=Gallerist(store,sizes={"image/jpeg":[ImageSize("a",1200),ImageSize("b",600),ImageSize("c",300)],"image/png":[ImageSize("a",350),ImageSize("b",250),ImageSize("c",150)],},)# the following function call causes the creation of several versions of the# image in different sizes; note that this operation is CPU boundmetadata=gallerist.process_image("ORIGINAL_FILE_NAME_ALREADY_ON_STORAGE.png")print(metadata)Asynchronous example using executors (recommended for async scenarios)importasyncioimportconcurrent.futuresfromgalleristimportGallerist,ImageSizefromgalleristazurestorageimportAzureBlobFileStorestore=AzureBlobFileStore.from_connection_string("<YOUR_CONNECTION_STRING>","CONTAINER_NAME",)gallerist=Gallerist(store)# configuring sizes by mime (use '*' to match any other mime):gallerist=Gallerist(store,sizes={"image/jpeg":[ImageSize("a",1200),ImageSize("b",600),ImageSize("c",300)],"image/png":[ImageSize("a",350),ImageSize("b",250),ImageSize("c",150)],},)asyncdefmain():loop=asyncio.get_event_loop()withconcurrent.futures.ProcessPoolExecutor()aspool:metadata=awaitloop.run_in_executor(pool,gallerist.process_image,"EXISTING_FILE_ON_STORAGE.jpg")print(metadata)asyncio.run(main())Alternatively to using an executor explicitly, it is possible to useloop.call_soon_threadsafe:fromgalleristimportGallerist,ImageSizefromgalleristazurestorageimportAzureBlobFileStorestore=AzureBlobFileStore.from_connection_string("<YOUR_CONNECTION_STRING>","CONTAINER_NAME",)gallerist=Gallerist(store)# configuring sizes by mime (use '*' to match any other mime):gallerist=Gallerist(store,sizes={"image/jpeg":[ImageSize("a",1200),ImageSize("b",600),ImageSize("c",300)],"image/png":[ImageSize("a",350),ImageSize("b",250),ImageSize("c",150)],},)defprocess_image(image_path:str):# configuring sizes by mime (use '*' to match any other mime):gallerist=Gallerist(store,sizes={"image/jpeg":[ImageSize("a",1200),ImageSize("b",600),ImageSize("c",300),],"image/png":[ImageSize("a",350),ImageSize("b",250),ImageSize("c",150),],},)metadata=gallerist.process_image(image_path)print(metadata)asyncdefmain():loop=asyncio.get_event_loop()loop.call_soon_threadsafe(process_image,"EXISTING_FILE_ON_STORAGE.jpg")asyncio.run(main())Asynchronous example using asynchronous methods from azure-storage-blob.aioNote:azure-storage-blobrequiresaiohttp, and is not compatible withconcurrent.futures.ProcessPoolExecutor.importasynciofromgalleristimportGallerist,ImageSizefromgalleristazurestorage.aioimportAzureBlobAsyncFileStorestore=AzureBlobFileStore.from_connection_string("<YOUR_CONNECTION_STRING>","CONTAINER_NAME",)gallerist=Gallerist(store)# configuring sizes by mime (use '*' to match any other mime):gallerist=Gallerist(store,sizes={"image/jpeg":[ImageSize("a",1200),ImageSize("b",600),ImageSize("c",300)],"image/png":[ImageSize("a",350),ImageSize("b",250),ImageSize("c",150)],},)asyncdefmain():metadata=awaitgallerist.process_image_async("EXISTING_FILE_ON_STORAGE.jpg")print(metadata)asyncio.run(main())