How to serialize images and transformer info? [konvajs] - konvajs

I'm using Vue.js and want to save user's layer state in the browser's memory. All is fine as I'm able to just serialize the whole layer and that includes all of the objects. However, I'm having trouble with images. First issue is that when a save is loaded all image objects are empty objects (I suppose I can implement a base64 serialization on saving and deserialization on loading).
Another issue is that these images have transformers, is there a way to get the state of image rotation/position/scaling that was modified using the transformer?

Related

Best Practices for saving images in swift (ios)

So I need to save pictures (made by the user) inside the app. I don't want to send them to a server and keep the link.
I am currently using Realm to save data, but I heard that it was not ideal to save images. What are the best practices for saving images locally?
(I will sometimes need to save hundreds of images.)
What kind of your data do you save ? ( link, data, image).
You should convert image to base64 then you save them into Realm. let write them in background task.
it will reduce volume and time to store them in Realm.

Adding images to Core Data takes a long time

How can I make the way I add images to the core data more efficient?
Its a pretty bad idea to save "Data" or Image here in core data persistance. Also i think you are running this code in the background queue, if not then thats also a bad thing. But then again, saving the image or data into core data persistant store is a very bad idea and should be avoided whenever you can.
As an alternate you can do this -
Save the image in the local directory with a path and a unique
filename.
Save the filename in core data except the path.
Next time when you retrieve the image, get the filename from the Data store.
Append the filename with the whole path untill the folder. Retrieve the image.
This is a much more efficient and better way to store images.

In iOS, should we save Image as Binary Data or use a library?

I'm writing an app to consume REST Api which provide JSON response. I'm using CoreData to store object from JSON to support offline feature. Object has some image attributes (Which is image url from JSON response).
My question is should I store image attributes as Data (Using binary data) to CoreData (can check use external storage from CoreDataXCModel) or should I need to only store the image path (As String) and use some library such as Kingfisher, AlamofireImage, SDWebImage to load image from image url stored in Coredata? which one is better design?
1 more thing is for how we handle big image? Can we generate 1 thumbnail which is specific size and 1 full image size.
I suggest you to store URL in database and use some framework like SDWebImage to load. These frameworks have caching mechanism so that once an image is loaded it gets cached.
You could preferably get a thumbnail image as a link in the JSON response too.
Save the urlString, I think, in most cases the urlStrting is a better solution, because in the era of 3 g / 4 g mobile phone App has greater amounts of image data, the local store they are a very difficult thing, unless you have a 1024 TB of the iPhone.
And you should provide an interface, like long press to push an view(Or anything) to tell user they can save the image to local.
Don't forget load local image at first and provide an interface tell user they can remove the local data.

Save images in Core Data + iCloud - Swift

My app is a mood diary and to save data I've chosen to use Core Data (for strings, images, etc.); to allow the user to restore his diary I've implemented iCloud, that works well with Core Data.
Everything works well if I have not much entries, but when the images saved are too much the app is slow to load data and encounters memory warnings.
To save my images I've chosen Transformable data type and not Binary Data; I know that is not the best way to save images (saving url is surely better), but I need to sync my data on iCloud, and saving images as Transformable allows me to sync data in a simple way (thanks to the possibility offered by Apple Api to link Core Data and iCloud).
What can I do to avoid this memory warnings and sync my app pics on iCloud?
I've considered the possibility to save my pics on a custom photo album (if iCloud is activated for Photo app my app pics would be synchronized), but I need to save them with custom name to retrieve them from camera roll to my app, and for the moment I don't find any solution to save pic with custom name in a custom photo album.
Saving photos in document directory (and saving urls in my core data entity) would be the right choice for local database, but my app pics would not be synchronized.
There are a few things you can try.
First, add an image thumbnail property which stores a smaller version of the image. Use that whenever possible. Loading a bunch of full-size photos needs a lot of memory, so change to loading smaller images whenever your UI allows smaller sizes.
Beyond that you can change how you handle images using one of the following strategies. In ascending order of complexity (and effectiveness):
Make sure "Allows external storage" is enabled for the image property in your data model. This will let Core Data put the images outside the persistent store without requiring you to manage those files. This will save on memory if, for example, you sometimes fetch data but aren't using the image property.
Change the data model so that the image is saved in a different entity, with a relationship linking it to your current entity. This should make it easier to avoid "accidentally" loading images when you're not using them.
Put the images in separate files and keep only the file names in Core Data. You can still sync the images via iCloud, because you can sync files directly via iCloud outside of Core Data. But you'll need extra code to manage uploading/downloading the images. You'll also need to make sure you can handle the case where Core Data has finished syncing but the image is not available yet.
On this list, #1 is easiest but will probably have the least effect. Using #3 should be very effective but will require the most work.

Saving user photos and photos from web

So i have this situation with images. In one of app stages i get all user photos from his photo library. I get them as ALAsset's. I let him choose photo he wants. Then i save his chosen photo to applications directory as full size photo with HIGH_ prefix and a thumbnail of a photo with LOW_ prefix. I need this because photos have some properties like time etc. I save those properties to SQL database with a field of photo name that begins with HIGH_ or LOW_. When i need to get photos i get properties from db and then do [UIImage imageWithContentsOfFile:photoPath]. Can someone tell me how to do it more efficient because writing and getting photos like this takes some time. And on iPhone 4 i sometimes even get memory warnings. AND another question would be, how should i save photos fetched from web?
I stand corrected, instead of using core data, Apple writes,
It is better, however, if you are able to store BLOBs as resources on the filesystem, and to maintain links (such as URLs or paths) to those resources. You can then load a BLOB as and when necessary.
So you are doing it correctly, but maybe you should check out transformables. Just make sure you remove images you aren't using from memory if you are getting warnings
From documentation: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Articles/cdPerformance.html
Under the section 'Large Data Objects (BLOBs)"
Another way to do it with a transformable:
Which way to store data(image)? NSData, String or Transformable
In fact, perhaps transformables are for core data at least:
How should I store UIImages within my Core Data database?

Resources