I am building a mobile app similar to Instagram in terms of working with Images. I am using amazon s3 to store the images and Mysql for the file path. I'm trying to ensure users upload great quality pictures but also ensure the file size is reasonable, Should I compress the images? Does anyone have an idea and what is the acceptable size for an image?
The definition of "acceptable" is totally up to you!
You should certainly store a high-quality image (probably at the original resolution), but you would also want to have smaller images for thumbnails and web/app viewing. This will make it faster to serve images and will reduce bandwidth costs.
A common technique is to have Amazon S3 trigger an AWS Lambda function when a new image is uploaded. The Lambda function can then resize the image into multiple sizes. Later, when your app wishes to retrieve an image, it can point to a resized image rather than the original.
When resizing images, you can also consider image quality. This allows JPG files to reduce in size without needing to reduce in resolution.
Related
Is it possible to reduce size of a PDF?
I have couple of things saved in DB as PDF, image, docs, etc. saved as base64, but mostly PDFs and images.
I am able to reduce/scale down images, but would it be possible for PDFs too?
This is for a mobile application. I can compromise on quality (which I am doing with images).
Edit
Can't say what's in the pdf, depends on the client, I guess there is no easy/direct way to reduce the size of pdf.
What's your thoughts on compressing the PDF and decompressing at mobile side? Will it have any effect on reducing the size?
It mainly depends on your PDF:
You can remove embedded fonts
You can reduce images quality
You can optimize resources if duplicated (if source is iText it isn't a remote option)
I was creating a Windows phone 8.1 (RT) app where I'm having a few images both in the LocalStorage and also in the Pictures Library where I'm loading the images using GetThumbnailAsync().
For a PNG image of size 6MB+ the GetThumbnailAsync() in PicturesLibrary takes a few msec while the same image when copied to LocalStorage in the App takes around 10 secs to get the thumbnail.
Also I used
getThumbnailAsync(ThumbnailMode.ListView,100,ThumbnailOptions.ResizeThumbnail)
Yet it takes a long time but returns the Thumbnail in the desired pixel size. Can anyone point out why it takes so much time in case of LocalStorage and if there are any alternatives to make it fast.
The system pre-caches thumbnails for images in the pictures library, whereas it can't do that for images in an app's isolated storage.
There are two workarounds here:
Move the picture to a public location where the system can pre-generate a thumbnail
Embed a thumbnail in the EXIF data for the image in your local storage. Then the system can do a fast extract and return a thumbnail more quickly. Currently it has to decode the entire 6+ MB file to generate a thumbnail, where a fast extract only needs to pop open the much smaller thumbnail
I am working on creating an Image Manipulation library using C# with MVC3. There is an option where users would be uploading multiple files. These files need to be compressed during transfer to server in order to cut down the upload time and bandwidth usage. We don't want to compromise with the quality and size of the images but do want to compress the images. Can somebody provide links to the articles which can be helpful to compress the images but maintaining their sizes and quality.
Look into an existing uploader with compression. Here's a few
silverlightfileupld (Silverlight)
flexupload (Flash)
I have problem with image compression. I need to compres a lot of files (700-900kb) to files 70-80kb without
loss of quality. (or small loss ) I found menu item "Save for Web & Devices ..." in Photoshop. It works great.
But I don't want to use photoshop programmatically. May be someone knows how to solve this problem with
other third party components or frameworks?
Thanks for any ideas!
.NET has a number of image decoding/encoding libraries, often tied to a particular GUI framework (e.g. in Windows Forms you have System.Drawing.Image and for WPF, see the Imaging Overview chapter on msdn).
There are also third party libraries specialized in image conversion/compression that you can find online (both free and non free)
Generally though, the amount of saving you get from compressing an image highly depends on the original format. If you already have JPEG photos with normal compression (quality of 85%) then there is not much you can do in terms of making them smaller except resizing them. If you have raw bitmaps (e.g. BMP, uncompressed/low compression TIFF etc.) then you can expect quite large savings with most compressing formats
When choosing image format, consider this:
Photos and similar: JPEG will often do fine. Good savings with reasonable quality loss
Screenshots and similar: PNG will generally give best results (PNG is lossless). JPEG will often create highly visible artifacts on screenshots
Compressing an already compressed image (i.e. PNG, JPEG etc.) with a general purpose compression algorithm like ZIP or RAR will in practice not give you any savings. You may actually end up with a bigger file.
You can have a look at the FreeImage project. It has a C# wrapper that you can use.
Imagemagick allows you to batch-processing on files and offers a everything you could possible ask for when it comes to handling of images
E.g. to resize every image in folder (destroy originals) to QVGA do
mogrify -resize 320x240 *.jpg
To preserve aspect ratio do
mogrify -resize 320x240! *.jpg
If you need to traverse a directory structure, this is how you can do it in *nix based systems (also destroying originals)
find . -type f -name *.jpg -exec convert -resize 800x800 {} \;
There is also an quality switch available, see here
For simplicity lets say that I have a web page that needs to display thumbnails of images. The images locations are stored in a database(the images are stored on Amazon S3). Is it possible to have my web server scale down the large image before it is delivered to the client? This way I don't have to store thumbnails of every image and the client can download a smaller file.
Every tutorial on this topic over-simplifies the situation and nearly all of them leak memory. It's a long read, but you should know about the 29 image resizing pitfalls so you can avoid them.
I wrote a library to do server-side dynamic image resizing safely. It's not something that can be done properly in 1 tutorial or even 10. You can solve 80% of the bugs, but not 100%. And when you're doing something this resource-intensive, you can't tolerate bugs or memory leaks.
The core library is free and open-source, but the Amazon S3 plugin is part of the Performance edition, which has a $249 license fee. The Performance Edition comes with source, examples, and documentation for S3, MS SQL, Azure, MongoDB GridFS, and CloudFront integration, as well as terabyte-scale disk caching and memcaching.
From the statistics I have access to, it appears that imageresizing.net is the most widely-used library of its kind. It runs at least 5 social networks and is used with image collections as large as 20TB. Most large sites use the S3 plugin, as local storage (or even a SAN) isn't very scalable.
Sure, no problem. There's plenty of resources on the web that show how to dish up an image from a database. So I won't duplicate that here.
Once you've loaded the image, you can easily shrink it using .NET. There is an example at the following URL. It doesn't do exactly what you are doing, but it does generate thumbnails of an image.
http://blackbeltcoder.com/Articles/graphics/creating-website-thumbnails-in-asp-net
Using WebImage class that comes in System.Web.Helpers.WebImage you can achieve this.
You can use this great kid to output resized images on the fly.
Sample code:
public void GetPhotoThumbnail(int realtyId, int width, int height)
{
// Loading photos’ info from database for specific Realty...
var photos = DocumentSession.Query<File>().Where(f => f.RealtyId == realtyId);
if (photos.Any())
{
var photo = photos.First();
new WebImage(photo.Path)
.Resize(width, height, false, true) // Resizing the image to 100x100 px on the fly...
.Crop(1, 1) // Cropping it to remove 1px border at top and left sides (bug in WebImage)
.Write();
}
// Loading a default photo for realties that don't have a Photo
new WebImage(HostingEnvironment.MapPath(#"~/Content/images/no-photo100x100.png")).Write();
}
More about it here: Resize image on the fly with ASP.NET MVC
Here's a great tutorial that shows how to work with WebImage directly from the ASP.NET site:
Working with Images in an ASP.NET Web Pages (Razor) Site
Yes.
You make a ASP.Net page that does Response.Clear(), sets Content-Type-header in Response and sends the binary data of the image (also through Response). The image can be resized on-the-fly, but I'd recommend caching it for some time on disk or so. Then you reference the image from HTML as <img src="http://server/yourimagepage.aspx">. For storing image in memory before sending you can use MemStream.
I have sample code but not in front of me right now, sorry. :)