I'm trying to make thumbnails from pdfs. To do it, I need to import wand.
It runs fine if I do `./manage.py runserver` from the command line, but if I run from PyCharm, it breaks.
When I step through the code, the problem is that the code used to open the blob is always empty. It's the right class (wand.image) but it's an empty one. The object I pass it is a pdf, but the blob conversion, which produces no error at all, is empty.
Again, if I launch the server from the command line, it works, but if I launch from PyCharm, it breaks.
Here's the code I'm running:
from wand.image import Image as WandImage
from wand.color import Color
def convert_to_thumb(pdf_path, slug):
with open(pdf_path) as f:
image_binary = f.read()
all_pages = WandImage(blob=image_binary) #<-- Here image_binary is a pdf
single_image = all_pages.sequence #<-- BOOM! all_pages is a wand.image, but it's empty. Gives an Index error
with WandImage(single_image) as i:
i.format = 'png'
i.background_color = Color('white')
i.alpha_channel = 'remove'
save_name = slug + '_pdf_preview.png'
i.save(filename='/foo/bar/' + save_name)