dlemstra / dlemstra/Magick.NET

MagickImage.Read() should raise an exception when specifying an invalid FrameIndex

Open
#813 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4k
Forks
451
Avg merge
11h 55m
Merged PRs (30d)
3

Description

First, thanks for maintaining this - it's great!

### Prerequisites

- [x] I have written a descriptive issue title
- [x] I have verified that I am using the latest version of Magick.NET
- [x] I have searched [open](https://github.com/dlemstra/Magick.NET/issues) and [closed](https://github.com/dlemstra/Magick.NET/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported

### Description
When trying to read a specific frame past the last frame from e.g. a PDF, a `MagicImage` is disposed, and

```Requested FirstPage is greater than the number of pages in the file: 1
No pages will be processed (FirstPage > LastPage).
```
is written on stdout.

Instead, I think an exception should be raised so that this situation can be dealt with in a nicer way than the sample below.

```csharp
var magickReadSettings = new MagickReadSettings {FrameIndex = 42};
using (MagickImage mi = new MagickImage())
{
try
{
mi.Read("onePagePdf.pdf", magickReadSettings);
// after reading, mi is _disposed_ if we have read past end. Try to access a field to
// see if this is the case (and if it is, catch the exception)
var dummy = mi.Width;
}
catch (System.ObjectDisposedException)
{
Console.WriteLine("read past the last frame.");
}
}
```

An additional nice-to-have would be a fast way of determining the number of pages in a PDF without having to load the whole thing :)

### System Configuration
ios, linux.

- Magick.NET version: 7.22.2.2
- Environment (Operating system, version and so on): seen on mac, dockerized ubuntu
- Additional information:

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.