A library for compressing, adding watermark and uploading the file into aws s3.
$ dotnet add package AWSFileUploaderWithImageCompressionA library for compressing, adding watermark and uploading the file into aws s3.
This library uses Magic.NET for compressing and adding watermark to the image.
Install-Package AWSFileUploaderWithImageCompressiondotnet add package AWSFileUploaderWithImageCompression //Initialize the s3imageuploader with respective access_key, secret_key and the bucketname
IS3ImageUploader s3ImageUploader = new S3ImageUploader("ACCESS_KEY", "SECRET_KEY", RegionEndpoint.APSouth1, "BUCKET_NAME");
IImageService imageService = new ImageService(s3ImageUploader);
PutObjectResponse objectResponse = await imageService.CompressAndUploadImageAsync(System.IO.File.OpenRead("C:/myfolder/mypic.jpg"), "newname.jpg" /* Optional to provide a new filename by default it uses Guid for the uploaded filename.*/);
ImgCompressorConfiguration imgCompressorConfiguration = new ImgCompressorConfiguration
{
MaintainAspectRatio = true,
MaxHeight = 600, //Default is 1200
MaxWidth = 800, //Default is 1600
WaterMarkPosition = ImageMagick.Gravity.Northeast, //Default is Southeast (bottom right)
WaterMarkTransperency = 5 //The watermark transperency ranges from 0 to 10, 0 as 0% and 10 as 100% transperency.
};
IImageCompressor compressor = new ImageCompressor(imgCompressorConfiguration /* Optional */);
//For adding watermark to the image
bool watermarkSucess = await compressor.AddWaterMark("C:/myfolder/mypic.jpg", "C:/myfolder/icons/watermark.png",
"C:/myfolder/output/myimage.jpg");
//For compressing the image (Note: The compression will happen when the source image exceeds the MaxHeight or MaxWidth configuration.
ImageCompressorResponse compressionSuccess = await compressor.CompressImage("C:/myfolder/mypic.jpg", "C:/myfolder/output/myimage.jpg");
/* The response will have the following data :
* 1. ImageCompressionSucccess
* 2. OriginalSizeInBytes
* 3. OriginalImageWidth
* 4. OriginalImageHeight
* 5. AfterCompressionSizeInBytes
* 6. ResizedImageHeight
* 7. ResizedImageWidth
* 8. OutputFilePath
* 9. OutPutFileStream (If output was provided as a stream)
*/
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated. Feel free to request for any changes or any additional features.
Distributed under the MIT License. See LICENSE for more information.
Name: Muthukumar Thevar
Email: mak.thevar@outlook.com
Project Link: https://github.com/mak-thevar/AWSFileUploaderWithImageCompression