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:

/**
 * Limits of image size options interface.
 */
public interface IMaxSizeOptions {
    /**
     * Max width of an output image in pixels.
     */
    int getMaxWidth();
    /**
     * Max width of an output image in pixels.
     */
    int setMaxWidth();
    /**
     * Max height of an output image in pixels.
     */
    int getMaxHeight();
    /**
     * Max height of an output image in pixels.
     */
    int setMaxHeight();
}
Warning
If you call the setImageWidth/setImageHeight options, calls of the setImageMaxWidth/setImageMaxHeight methods are ignored.

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

  1. Instantiate the Viewer object.
  2. Instantiate the PngViewOptions or JpgViewOptions object.
  3. Call the setMaxWidth and/or setMaxHeight methods.
  4. Call the View.view() method.

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

import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.JpgViewOptions;
// ...

try (Viewer viewer = new Viewer("sample.jpg")) {
    JpgViewOptions viewOptions = new JpgViewOptions("result_{0}.jpg");
    // PngViewOptions viewOptions = new PngViewOptions("result_{0}.png");
    // Specify the maximum width and height.
    viewOptions.setMaxWidth(800);
    viewOptions.setMaxHeight(600);

    viewer.view(viewOptions);
}