I have a website where people can upload images and crop them before they upload them to the server. My problem is that each image size increases by hundred percent in the upload process. For example if I take an JPG image size 102kb 640x640, when it is loaded from the website, I use the chrome network tool after I crea the cache and see that its size is 800kb (after I saved it with size 600x600). In order to save it to the DB I use HTML5 canvas and cropping using http://fengyuanchen.github.io/cropper/ In the server side I use Azure CloudBlockBlob.
Client:
VData = $("#uploadedImage").cropper('getCroppedCanvas', {
width: 600,
height: 600
}).toDataURL();
Server:
public PhotoInfo UploadPhoto(string image, string picCaption)
{
string base64 = image.Substring(image.IndexOf(',') + 1);
byte[] imageByte = Convert.FromBase64String(base64);
Stream stream = new MemoryStream(imageByte);
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
ConfigurationManager.AppSettings.Get("StorageConnectionString"));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("photos");
if (container.CreateIfNotExists())
{
// configure container for public access
var permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions(permissions);
}
// Retrieve reference to a blob
string uniqueBlobName = string.Format("{0}{1}", Guid.NewGuid().ToString(), Path.GetExtension("blob")).ToLowerInvariant();
CloudBlockBlob blob = container.GetBlockBlobReference(uniqueBlobName);
//blob.Properties.ContentType = image.ContentType;
blob.Properties.ContentType = "image/jpg";
stream.Position = 0;
blob.UploadFromStream(stream);
var photo = new PhotoInfo()
{
ImagePath = blob.Uri.ToString(),
InvitationId = 0,
Name = picCaption != null ? picCaption : ""
};
PhotoInfo uploadedPhoto = _boxItemProvider.SetPhoto(photo);
return uploadedPhoto;
}
Any advice here?
Thanks.