Set image size limits

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Viewer MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-viewer -- dnx GroupDocs.Viewer.Mcp --yes
Folders, licensing and more →

The PngViewOptions and JpgViewOptions classes implement the IMaxSizeOptions interface that contains properties for size limits:

/// <summary>
/// Limits of image size options interface. 
/// </summary>
public interface IMaxSizeOptions
{
    /// <summary>
    /// Max width of an output image in pixels.
    /// </summary>
    int MaxWidth { get; set; }

    /// <summary>
    /// Max height of an output image in pixels.
    /// </summary>
    int MaxHeight { get; set; }
}
''' <summary>
''' Limits of image size options interface. 
''' </summary>
Public Interface IMaxSizeOptions
    ''' <summary>
    ''' Max width of an output image in pixels.
    ''' </summary>
    Property MaxWidth As Integer

    ''' <summary>
    ''' Max height of an output image in pixels.
    ''' </summary>
    Property MaxHeight As Integer
End Interface
Warning
If you set the ImageWidth/ImageHeight options, the ImageMaxWidth/ImageMaxHeight options are ignored.

To set the ImageMaxWidth/ImageMaxHeight options, follow these steps:

  1. Instantiate the Viewer object.
  2. Instantiate the PngViewOptions or JpgViewOptions object.
  3. Set MaxWidth and/or MaxHeight values.
  4. Call the View method.

The following code snippet shows how to set the output image size limits:

using GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
// ...

using (Viewer viewer = new Viewer("sample.jpg"))
{
    // Create a JPG or PNG file.
    JpgViewOptions viewOptions = new JpgViewOptions("result_{0}.jpg");
    // or PngViewOptions viewOptions = new PngViewOptions("result_{0}.png");
    
    // Specify the maximum width and height.
    viewOptions.MaxWidth = 800;
    viewOptions.MaxHeight = 600;

    viewer.View(viewOptions);
}
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
' ...

Module Program
    Sub Main(args As String())
        Using viewer As Viewer = New Viewer("sample.jpg")
            ' Create a JPG or PNG file.
            Dim viewOptions As JpgViewOptions = New JpgViewOptions("result_{0}.jpg")
            ' or PngViewOptions viewOptions = new PngViewOptions("result_{0}.png");
        
            ' Specify the maximum width and height.
            viewOptions.MaxWidth = 800
            viewOptions.MaxHeight = 600
        
            viewer.View(viewOptions)
        End Using
    End Sub
End Module