Hi,
Just updated to the latest version (19.11.0) of Conversion. Previously if in the conversion options width had a value set and height was null, the aspect ratio of the image would be maintained. Now it looks like if width is set and and height is null, the image becomes misshapen. Is there any way to set only one value and have other change automatically to stay proportional?
We can see the difference between output of 18.9 and 19.11. In both cases we set width to 500. 18.9.Jpg (103.3 KB) - output 19.11.jpg (280.5 KB) - output
Output generated from 18.9 is what you’re expecting in 19.11?
Aha, I’m very sorry I left out important information. In our old version we used viewer (18.9.0) for this function:
public async Task<List<Stream>> RenderThumbnails(Stream document, string documentName, int? height = null, int? width = null, string type = "png", uint fromIndex = 1, uint pageSize = 1)
{
Guard.ArgumentNotNull(document, "document");
var config = GetViewerConfig();
var imgHandler = new ViewerImageHandler(config);
var thumbnailOptions = GetThumbnailOptions(fromIndex, pageSize, height, width, type);
try
{
var memoryStream = new MemoryStream();
await document.CopyToAsync(memoryStream); //Stream type given by Akkadia or Dataroom is not seekable so need to copy into a memory stream
var extension = HelperMethods.GetFileExtension(documentName);
List<PageImage> result = null;
var conversionThread =
new Thread(() =>
{
try
{
result = imgHandler.GetPages(memoryStream, extension, thumbnailOptions);
}
catch (Exception e)
{
ExceptionHandler(documentName, e);
result = null;
}
});
conversionThread.Start();
conversionThread.Join(300000);
if (conversionThread.IsAlive)
conversionThread.Abort();
return result == null ? null : result.Select(thumb => thumb.Stream).ToList();
}
catch (Exception ex)
{
//if an conversion exception is encountered,
//return null so that we can simply present the document to the user instead of an exception or error
ExceptionHandler(documentName, ex);
return null;
}
}
private static ImageOptions GetThumbnailOptions(uint fromIndex, uint pageSize, int? height, int? width, string type)
{
var options = new ImageOptions()
{
CountPagesToRender = (int) pageSize,
PageNumber = (int) fromIndex
};
if (height != null && height > 0)
options.Height = (int) height;
if (width != null && width > 0)
options.Width = (int) width;
if (type.ToLower() == "jpg")
options.ConvertImageFileType = ConvertImageFileType.JPG;
if (type.ToLower() == "bmp")
options.ConvertImageFileType = ConvertImageFileType.BMP;
return options;
}
Viewer wasn’t an option for us when we upgraded though because of the formats we needed to move from and to, and we want to use only streams without ever saving the files. So we switched to using Conversion for most everything. Sorry again about the bad info to start with.
If you are looking for only document conversion module, please use GroupDocs.Conversion for .NET API and the latest version (19.11). You can set both width and height (because API allows you to set) and then let us know if there is any issue.
In GroupDocs.Conversion for .NET, you have to set height and width in order to get desired output. However, GroupDocs.Viewer for .NET has a built-in feature to adjust height if width only is given and vice versa.
We can investigate it and see if this behavor can be implemented in our document conversion API. Your investigation ticket ID is CONVERSIONNET-3505.
We have added an improvement in latest release of the API that is 20.1. You can now get proportional image if only Width or Height is provided during conversion.