I am trying to convert a PDF to a JPG using wand.
I would like to adjust the size of the jpg based on the docHeight, which is a global variable.
The size of the jpg would be determined by the max dimension's ratio with the target page it will be placed on.
I seem to be failing right from the starting gate, and I cannot figure out why.
It seems the file is not being read in my with statement.
my with Image statement returns
>>>>with Image(filename = thumbOriginal, resolution = (RESOLUTION,RESOLUTION)) as img:
print img
'NoneType' object has no attribute '__getitem__'
What is wrong with how I am reading the file?
it is mostly borrowed from this question. I can barely find any info on how to properly make this conversion.
with Image(filename = thumbOriginal, resolution = (RESOLUTION,RESOLUTION)) as img:
print img # prints 'NoneType' object has no attribute '__getitem__'
img_width = img.width
print "img_width: "+str(img_width) # prints 0 if I comment out "print img" statement
img_height = img.height
print "img_height: "+str(img_height) # prints 0 if I comment out "print img" statement
if img_width > img_height:
ratio = float(dest_width / img_width) # Fails for float divided by 0 if I comment out "print img" statement
else: ratio = float(dest_height / img_height) # Fails for float divided by 0 if I comment out "print img" statement
img.resize(int(ratio*img_width), int(ratio *img.height))
img.alpha_channel = False
img.format = 'jpg'
img.save(filename = thumb)
I've also tried a simpler version I found on a different stackoverflow question:
with Image(filename = thumbOriginal, resolution = 300) as img:
print img
img.compression_quality = 99
img.save(filename=thumb)
but am getting the same error
'NoneType' object has no attribute '__getitem__'
I know that the pdf is there. I can open it manually and it works just fine.
I have also tried removing the resolution argument altogether with no luck.
When I include a ...
print thumbOriginal
.... statement, it returns the correct and complete file path.