Free Support Forum - aspose.com

Use GetThumbnail to set to fixed width and maintain proportions

Hi,


I have the following C# code which generates a thumbnail from a slide and saves it to disk:

Image img = slide.GetThumbnail(0.1f, 0.1f);
string thumbPath = Path.Combine(thumbDirectory, thumbFilename);
img.Save(thumbPath, ImageFormat.Gif);

This is working fine, but now, instead of setting the thumbnail to 1/10 of the size of the original, I would like to set it to a width of 200 px, maintaining the original proportions. How can I do this?

If I could get hold of the original height and width of the slide, and I would calculate the new dimensions myself, but I can’t seem to find this information…

Thanks.

Hi Joao,


Thanks for your interest in Aspose.Slides.

I would suggest you to please use the code snippet shared over this thread link. It will allow you to generate the custom size slide thumbnail for PPTX. Please share if I may help you further in this regard.

Thanks and Regards,

Hi Mudassir,


Many thanks for your very quick reply, which put me on the right track. Customer support doesn’t get much better than this.

I understand now that I couldn’t find the size and width properties because they belong to the presentation, not to the individual slides.

Just for the record, here is my final code:

Presentation pres = new Presentation(doc.FilePath);

float slideWidth = pres.SlideSize.Size.Width;
float slideHeight = pres.SlideSize.Size.Height;
int desiredWidthThumb = 200;
int desiredHeightThumb = Convert.ToInt32((desiredWidthThumb / slideWidth) * slideHeight);

Image img = slide.GetThumbnail(new Size(desiredWidthThumb, desiredHeightThumb));

I notice there is also a slight difference for ppt and pptx files, retrieving the dimensions of the presentation. For ppt, it’s:

float slideWidth = pres.SlideSize.Width;
float slideHeight = pres.SlideSize.Height;

while for pptx, it is:

float slideWidth = pres.SlideSize.Size.Width;
float slideHeight = pres.SlideSize.Size.Height;

Hi Joao,


Yes, your observation is right that finding slide size for PPT and PPTX are slightly different. In case of PPT, you have the provision to generate the slide thumbnail with your custom dimension even. Please follow this link for more details. Please share, if I may help you further in this regard.

Thanks and Regards,