question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am using the latest version of Magick.NET
  • I have searched open and closed 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

   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.

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:

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dlemstracommented, Jan 7, 2021

Is it possible to reproduce the issue in GitHub actions?

p.s. Getting a fast page count will become available in the next release.

0reactions
dlemstracommented, Jul 3, 2021

We made some changes in the PDF reading, can you give it another try with the latest release @martinkoch-geniebelt? And I would advise you to use the new PdfInfo class to get the page count.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - ImageMagick.NET - Faster performance
You can specify the page you want to read with the FrameIndex ... If you specify a page that is too high an...
Read more >
Magick.NET
ImageMagick is a powerful image manipulation library that supports over 100 major file formats (not including sub-formats). With Magick.NET you can use ...
Read more >
C# (CSharp) ImageMagick MagickImage.Read Examples
Description: The MagickImage Read method is part of the ImageMagick library in C# and is used to read and decode images from a...
Read more >
C# (CSharp) ImageMagick MagickReadSettings Examples
Class that contains setting for when an image is being read. ... FrameIndex = 1; settings. ... public void Test_Constructor() { ExceptionAssert.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found