Resize Proportionally -> rotate -> thumbnail -> save

A form needs to process several uploaded pictures and apply the following settings:

- resize picture proportionally (width: 650),
- if needed rotate picture and update orientation exif data,
- extract and save embedded thumbnail else create new resized thumbnail,

I can:
- rotate the picture according to orientation and update exif data,
- extract and save the embedded thumbnail.

However, it appears that only RasterImage has the Resize Proportionally method .

Also what can be done to speed up the picture manipulation?
Right now I’m doing this:

foreach (string file in System.IO.Directory.GetFiles(myDir, .jpg”, System.IO.SearchOption.TopDirectoryOnly))
{
using (JpegImage image = (JpegImage)Image.Load(file))
{
if (image.ExifData != null)
{
if (image.ExifData.Orientation != null)
{
if (image.ExifData.Orientation != Aspose.Imaging.Exif.Enums.ExifOrientation.TopLeft)
{
switch (image.ExifData.Orientation)
{
case Aspose.Imaging.Exif.Enums.ExifOrientation.LeftBottom:
image.RotateFlip(RotateFlipType.Rotate270FlipNone);
break;
case Aspose.Imaging.Exif.Enums.ExifOrientation.BottomRight:
image.RotateFlip(RotateFlipType.Rotate180FlipNone);
break;
case Aspose.Imaging.Exif.Enums.ExifOrientation.RightTop:
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
break;
}
image.ExifData.Orientation = Aspose.Imaging.Exif.Enums.ExifOrientation.TopLeft;
image.Save();
}
}
		<span style="color:blue;">if</span> (image.ExifData.Thumbnail != <span style="color:blue;">null</span>)
		{
			<span style="color:green;">// extract embedded thumbnail</span>
			<span style="color:#2b91af;">JpegImage</span> thumbnail = (<span style="color:#2b91af;">JpegImage</span>)image.ExifData.Thumbnail;
			thumbnail.Save(file.Insert(file.LastIndexOf(<span style="color:#a31515;">"."</span>), <span style="color:#a31515;">"-tn"</span>), <span style="color:blue;">true</span>);
		}
	}
}

}







Hi Morten,


Thank you for contacting Aspose support.

We believe you have misinterpreted the parameter description for the RasterImage.Rotate method that accepts three parameters and performs the rotation on any specified angle. One of these parameters is of Boolean type that causes the resultant image to re-size proportionally during the rotation process.

If you wish to perform the resize operation by providing only one parameter (either width or height) you may use the ResizeWidthProportionally or ResizeHeightProportionally methods that will be available with the upcoming release of Aspose.Imaging for .NET 2.6.0. The aforesaid release is currently in QA phase, and will be published in the next week. We have attached the ticket IMAGING-34280 (Resize Image Proportionally) to this thread so that when v2.6.0 is available for public use, you could be notified here with the download link to the upgraded API.

Regarding your concerns about the performance, please try setting the cache in your application and see if the performance improves. In case you are unable to notice any improvement, please provide the sample image along with your complete source code in shape of a sample application.

C#

RasterImage rasterImage = (RasterImage)image;
if (!rasterImage.IsCached)
{
rasterImage.CacheData();
}


Please also note that the current implementation of Aspose.Imaging APIs uses Color[] for internal structure, and this mechanism utilizes more memory because the Color[] stores additional information along with 4 bytes of color. We are in process to change the internal structure to use byte[] instead of Color[] to improve the performance in terms of memory as well as time.

hi Baba
thanks for taking time to reply.

I may have misinterpreted the v2.5 feature description about resize proportionally, however, it read to me like aspose.imaging now could resize an image and keep its proportions intact. I’ll be looking forward to ResizeHeightProportionally and ResizeWidthProportionally.

Abount speed. Even if I add

if (!image.IsCached)
image.CacheData();
immediately after using… the provided code still takes approx 2 sec. for an average 2.5MG JPG image (which unfortunately is too slow in my case).

/Morten

Hi Morten,


Thank you for writing back,

Regarding the performance related concerns, I doubt that we can further improve the performance with current internal structure of Aspose.Imaging APIs. However, if you can provide a sample application along with your sample image, we can benchmark the performance and keep evaluating the scenario with every release until we change the internal structure as discussed in the previous post.

Please note, we have currently introduced the said changes for BMP file format and moving forward to improve the performance for other file formats as well.

The issues you have found earlier (filed as IMAGING-34280) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Morten,


Please refer to the article on Resizing Images Proportionally, and feel free to contact us if you face any difficulty or have any questions for us.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.