Skip to content

Gravity function throwing exceptions on specific images #169

Closed
@Transigent

Description

@Transigent

Hi, first of all thanks for the superb NetVips library.

I have been doing some format tests for various images. For some images I am having an odd problem when I call WriteToFile after the Gravity function. Most JPG and various other formats (eg. WEBP, GIF, BMP, SVG, PDF, AVIF, TGA, JP2) all seem to work fine. In the code below, for each image:

  • I load a thumbnail fit to a 640x640 bounding box.
  • I write the thumb to disk.
  • Then I use Gravity to fill the non-image areas with grey.
  • Then I write the 'gravitized' image to disk.

I have supplied 4 sample images that are giving me trouble. For the first 3 (0016524.tiff, abcd.jfif, dddJFIF.jfif) I successfully load and WriteToFile the thumbnail but I get an exception on the line where I WriteToFile the Gravity processed image :

GravitizedImage.WriteToFile("C:\TestImages\" & FileNameWithoutExtension & "_GRAVITIZED.jpg", options)

0016524.tiff

unable to call VipsForeignSaveJpegFile
tiff2vips: out of order read -- at line 923, but line 0 requested

abcd.jfif

unable to call VipsForeignSaveJpegFile
VipsJpeg: out of order read at line 602

dddJFIF.jfif

unable to call VipsForeignSaveJpegFile
VipsJpeg: out of order read at line 480

For the 4th file zz12AVIF.avif it does not get past the thumbnail stage with the error:

unable to call VipsForeignSaveJpegFile
C:\TestImagesAll\zz12AVIF.avif: bad seek to 269202
heif: Invalid input: Unspecified: Bitstream not supported by this decoder (2.0)
which seems to imply that the format is not yet supported.

I am using the latest vips-dev ALL 8.12.2 version along with NetVips 2.1.0

I have tried running the command line tool vipsthumbnail.exe to create thumbs and they work except for the 4th file. I successfully use vips.exe to generate a file with plain Gravity applied, for the first 3 files, using

vips gravity abcd.jfif abcd.jpg centre 640 640 --background "128,128,128"

which works for all except the 4th file. Its like I am doing something wrong in the vb.net code.

Can you make any suggestions as to what I am doing wrong? Thanks for any advice.


My code is as follows:

Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
        Dim DI As New System.IO.DirectoryInfo("C:\TestImages\")
        For Each Fil In DI.GetFiles
            PreProcessImage(Fil.FullName)
        Next
    End Sub
Public Sub PreProcessImage(FileName As String)

        Dim options As New VOption From {{"strip", True}, {"Q", 80}}
        Dim bacgnd As Double() = {128.0}     '(mid grey)

        Try
            Dim FileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FileName)

            Dim OriginalImage = NetVips.Image.Thumbnail(FileName, 640)
            OriginalImage.WriteToFile("C:\TestImages\" & FileNameWithoutExtension & "_THUMBNAILED.jpg", options)

            Dim GravitizedImage = OriginalImage.Gravity(Enums.CompassDirection.Centre, 640, 640, Enums.Extend.Background, bacgnd)
            GravitizedImage.WriteToFile("C:\TestImages\" & FileNameWithoutExtension & "_GRAVITIZED.jpg", options)
            Dim ResizedToBitmap2 As System.Drawing.Bitmap = GravitizedImage.ToBitmap

        Catch ex As Exception
            Dim v = 888
        End Try

    End Sub

System - Windows 10, Version 10.0.19043 Build 19043
Project - VB.NET Framework 4.6.1, x64
Nuget Packages - NetVips 2.1.0, NetVips.Extensions 2.1.0, System.Buffers 4.5.1, System. Memory 4.5.5, System.Numerics.Vectors 4.5.0, System.Runtime.CompilerServices.Unsafe 6.0.0
libvips - vips-dev-w64-all-8.12.2.zip

TestFiles.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions