0

What is wrong with my erroneous code? Wand making tempfiles and not delete them. I have try os.remove, but then I get error WindowsError: [Error 32].

What is wrong?

name = "testname"
fullFilename = "test" + "/" + str(name) + ".png"
with Image(file=url, resolution=400) as image:
    images=image.sequence
    for i in range(len(images)):
        Image(images[i]).save(filename=fullFilename)
        with Image(filename=fullFilename, resolution=300) as img:
                    img.compression_quality = 99
                    img.type = 'grayscale'
                    img.save(filename=fullFilename)
            with open(fullFilename, "rb") as imageFile:
                tiffData = imageFile.read()
                infoArray = ["2017","777","NO",tiffData,"OK",id]
                saveToDatabase(infoArray)
fmw42
  • 46,825
  • 10
  • 62
  • 80
mattias77
  • 13
  • 3
  • Thanks for the answer. I miss the " when i copy the code to stackoverflow:(. I have change " – mattias77 Dec 11 '18 at 08:13
  • not sure sure what your `saveToDatabase()` is doing, but I'm under the impression that saving large objects to relational databases is generally discouraged… – Sam Mason Dec 11 '18 at 09:44
  • Thanks Sam. I know that saving image on database is not god. I`m still learning:). The goal is exract differerent mulit pdf files to singel png or tiffs. Then make ocr on each image and then delete pages with wrong text. Then make a new diffrent multi pdf from key words from the passed pages. – mattias77 Dec 11 '18 at 09:59

1 Answers1

0

What is wrong with my erroneous code?

Looks like your doing a lot of I/O operations. Try reducing the code down to something minimal & complete.

with Image(file=url, resolution=400) as image:
    for page_src in image.sequence:
        with Image(page_src) as page_dst:
            page_dst.compression_quality = 99
            page_dst.type = 'grayscale'
            tiffData = page_dst.make_blob('TIFF')
            infoArray = ["2017","777","NO",tiffData,"OK",id]
            saveToDatabase(infoArray)

Wand making tempfiles and not delete them. I have try os.remove, but then I get error WindowsError: [Error 32].

Looks like the files are being accessed by another program. Try removing them after python does a clean shutdown, and ImageMagick has time to run terminus routine.

fmw42
  • 46,825
  • 10
  • 62
  • 80
emcconville
  • 23,800
  • 4
  • 50
  • 66