Can Data URL value be passed and stored in Local storage for later use? - data-uri

I am developing an application that requires editing an image by converting it into a canvas an the save the changes as an Image. So my doubt is that, can this Data URL be passed along the application and save to local storage of the browser to be produced back as an image when the application is loaded ??

Yes, why not.
Only problem is that canvas creates very large filesizes and local storage has a size limit. For production keep limit the use of local storage to 2,5mb. That should cover most browsers.
A better solution would be to post the data url to a server and retrieve it later.
Check it out yourself, compare filesize of your canvas created png to the filesize of optimized png's data url

Related

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.

Should i save images to local storage in iOS App?

I am working on a project where i want to make the data, text, images available in offline mode as well.
I fetch data from a web-service which includes image urls and other data. I store the text data in core data entities, however i don't save images locally but fetch them in realtime.
To view images in offline mode i will have to save them to local storage. However i am wondering if it would be the right approach. Saving images to local may possibly eat up a lot of storage on user's device.
What is the best approach to address this problem?
Should i save images to local or should i fetch them on run time only?
Use NSCache. With NSCache you can set a limit to how many images and so on are cached. See Apple's documentation for more details: https://developer.apple.com/reference/foundation/nscache?language=objc
Edit:
Never mind NSCache, just save the images as files. NSCache can still save you network usage and allow your app to be more responsive, but it is not what you want.
Should i save images to local or should i fetch them on run time only?
This question for you , you should decide what you need or what is will be more suitable for your app . at any way if you want to cache images i suggest to use this library SDWebImage

Upload image without converting NSData

I try to upload my image into server converting to NSData but it's take to much time to convert images.
Can we upload image to server without converting to NSData ?
At starting I had tried sending image directly to server.
But without converting image to data and string if I tried to send it ,it could not send also it is not possible.Because in server if we send data anything to server,it must be a string format.If we send image directly,it takes much space also it should not be a data.Image must be a URL or path in server.
It depends upon the source of these images. If the images are from the photos libraries, for example, then, yes, you can retrieve the original asset, avoiding the inefficient process of converting a UIImage to a NSData (which can make the asset larger, introduce quality loss, lose metadata, etc.).
The key take home message in this scenario is not "how to avoid converting to NSData", but rather "how to avoid round-tripping the image through a UIImage and then reconverting it back to a NSData, but rather just retrieve the original asset."
But this only applies to images for which you have the original raw asset (e.g. images in the photos library, images in the documents folder, etc.). In those cases, just grab the raw NSData and you're done.
But if this is an image that you generated programmatically (e.g. a snapshot of a UIKit view), then that will have to be converted to a NSData. But if you can avoid round-tripping it through the UIImage in the first place, then you eliminate this overhead.
You can use blob data type store the data. Though its not highly recommended. You can refer these links. BLOB data type and how to use BLOB storage service as don't put large BLOBs in a database. Put them in the filesystem next to your database file and then write the filenames or an URL to the database. This will be a much faster, will use the database much more efficiently, will minimize I/O.

Storing more number of images in file on iOS

I want to develop the solution where storing of image data downloaded from server and display it.
Scenario is, There will be thumbnail images placed on each row, clicking on that will download the actual image from server and display the image in a bigger view.
I want to store this image data once its downloaded from server, so that in the later stage if the same thumbnail has clicked to open, I don't need to again download the actual image from server, instead I can pull that from the place where I stored locally.
There will be more than 80 thumbnail images placed in rows and corresponding bigger images on the server.
Can I store the image data in a file and store it in documents directory or some thing like that? My worry, if the user selected all the 80 thumbnail images, then i'll have to store all the 80 bigger images locally on the app.
What is the best way to achieve this storing solution? Please advise.
Thank you.
You can store the images in the documents folder, as you already said. Just make sure to exclude them from backups, Apple will reject you for storing too much replaceable data in there.
There are also some third party image cache libraries, most notably (afaik) FastImageCache from Path:
https://github.com/path/FastImageCache
From their website what FastImageCache does is this:
Stores images of similar sizes and styles together
Persists image data to disk
Returns images to the user significantly faster than traditional methods
Automatically manages cache expiry based on recency of usage
Utilizes a model-based approach for storing and retrieving images
Allows images to be processed on a per-model basis before being stored into the cache

Save images in phonegap and jquery mobile

Hi I have to develop an application that consists of the world cup fifa stamp album.
I have all the stamps in a png format, so in the first module i need to show the stamps that i own and the ones that not.
My original idea was to store in a database an entity called stamp that includes the image, the name of the player, the id of the stamp and the quantity that i own of each one. I don´t know which storage option to use i know that localstorage can´t store the images so I think my only option is web sql.
Is this the correct approach or the other one is to save the images like in a local folder and then using local storage save the path to the image, the id, name and number of the stamps?
Your life will be easier if you would store the images in the file system and their locations in the database.
Images must be served as static files so you will be able to access them directly
You don't need additional code to extract and stream the images
Images are easy to cache and store on the file system
The database also stores the data on the file system
For a web app you would could use multiple servers to improve performance
So yes, save the images in a local folder and use localstorage or web database to save the image paths.
For storing large amount of data you have to use SQLite for iOS and indexeddb for all other platforms.
There are two ways to access SQLite in phonegap. Either use native websql or sqliteplugin.
You can try out my library which abstract these storage mechanism. See here for example app https://github.com/yathit/cordova-sqliteplugin-todo
For storing image in the database, see here in "Storing File and Blob data" section.

Resources