I'm trying to use this blog post to convert one pdf to a jpg, however everytime I try to run this simple script I get this exception wand.exceptions.WandError: wand contains no images MagickWand-56' # error/magick-image.c/MagickWriteImage/13001
from wand.image import Image
with Image(filename="myFile.pdf") as img:
img.save(filename="myFile.png")
I'm using the latest version of Wand and Python 3.4.2. The only thing I can think of is possibly a version compatibility issue.
So just to close the question, the problem is missing ghostscript library on mac, as indicated in my comment above:
"maybe then some libraries missing. do you use linux/windows/mac?
check what is required there for pdfs? ghostscript maybe? "
Related
I intend to use opencv and pytesseract to extract text of out images. On executing the following code in a Python 3.7 Interpreter, I am receiving a error I'm not sure I understand.
import cv2
import pytesseract
#tesseract.exe location provided
pytesseract.tesseract_cmd=r'C:\\Users\\shree\\AppData\\Local\\Programs\\Tesseract-OCR\\tesseract.exe'
#image location provided
img=cv2.imread('C:\\Users\\shree\\Desktop\\hey.jpeg')
text=pytesseract.image_to_string(img)
print(text)
error shown
P.S:
I have installed opencv and pytessearct in
"C:\Users\shree\AppData\Local\Programs\Python\Python37-32\Scripts"
Python 3.7 Interpreter is installed in
"C:\Users\shree\AppData\Local\Programs\Python\Python37-32"
Please excuse if this is an obvious/dumb question. Actually, I'm just starting out. I read about this at https://towardsdatascience.com/read-text-from-image-with-one-line-of-python-code-c22ede074cac
A Detailed answer and an alternate way(if required) would be highly appreciated.
Thanks!
Replace the line,
pytesseract.tesseract_cmd=r'C:\\Users\\shree\\AppData\\Local\\Programs\\Tesseract-OCR\\tesseract.exe'
with,
pytesseract.pytesseract.tesseract_cmd = r'C:\\Users\\shree\\AppData\\Local\\Programs\\Tesseract-OCR\\tesseract.exe'
This should fix the issue if tesseract is installed properly.
My goal is to generate (in Python under Windows) a bitmap image rendering any unicode character, including in particular emojis. I have installed several emoji-friendly fonts (including Symbola) for testing purpose.
So far I've tried PIL, matplotlib and pygame, but none of these are able to do it under Windows (the first two apparently can do it on some versions of Linux / MacOS, while pygame is explicitly limited to characters up to 0xffff, which rules out emojis).
I found that reportlab is able to generate a PDF with emojis (while its bitmap renderer fails to properly render them), but I still need to find a way to extract the emoji character from the PDF and convert it to bitmap. I feel like there has to be a simpler way...
NB: this question is related to Rendering Emoji with PIL but I do not necessarily want to use PIL if another library can do the job
I eventually found a solution in Is there any good python library for generating and rendering text in image format?. Although it is based on a third-party executable, as mentioned it is easy to wrap in Python.
Exact steps were as follows:
Install ImageMagick from https://www.imagemagick.org/script/download.php#windows
Set environment variable MAGICK_HOME to installation folder
Install Pillow to be able to manipulate easily the resulting image in Python (conda install pillow)
Download and install the Symbola font from https://fontlibrary.org/en/font/symbola
And my test script:
import os
import subprocess
import PIL.Image
to_render = '🤓'
output_file = 'rendered_emoji.bmp'
subprocess.run([
os.path.join(os.environ['MAGICK_HOME'], 'magick.exe'),
'convert', '-font', 'Symbola', '-size', '50x50',
'-gravity', 'center', f'label:{to_render}', output_file])
image = PIL.Image.open(output_file)
image.show()
I am using moviepy to try resize a video clip but every time I try I get this error. Can anyone explain how I can fix it? Thanks
My python code
Import everything needed to edit video clips
from moviepy.editor import *
# Load video clip
myclip = VideoFileClip("dog.mov")
myclip.resize( (460,720) ) # New resolution: (460,720)
myclip.write_videofile("resized_clip.mp4") #write new video file
The error
File "/usr/local/lib/python3.4/dist-packages/PIL/Image.py", line 699, in tostring
"Please call tobytes() instead.")
Exception: tostring() has been removed. Please call tobytes() instead.
Looks like you are using PIL, I would try using Pillow, a support fork that is maintained. MoviePY recommends you use Pillow in lieu of Pil in it's docs:
http://zulko.github.io/moviepy/install.html
For advanced image processing you will need one or several of these
packages. For instance using the method clip.resize requires that at
least one of Scipy, PIL, Pillow or OpenCV are installed.
The Python Imaging Library (PIL) or, better, its branch Pillow .
i'm trying to utilize PIL to open a jpeg image and assign it to a Tkinter's label.
However whenever i try to open the image i get the same problem as this guy
I tried all the suggestions he got and also the ones i found here but it doesn't seem to fix, by installing PIL or Pillow(i tried that too) during the setup i get :
*** TKINTER support not available
*** JPEG support not available
And whenever i run my code i get an IOError: decoder jpeg not available
I'm using python 2.7.
Can someone provide a good method to make PIL or Pillow work with jpeg support? I've been googling extensively for two days, but all the possible fixes that i found don't seem to work for me
Installing libjpeg-dev should do the trick, as proposed by the link you provided. But if it doesn't help (I ran into that as well) you can consider upgrading to Pillow 3, it looks like you are running Pillow 2. This also helped me getting rid of the errors, don't know why exactly..
I have a problem with a python program (python 2.7.3, X11 Tkinter, py2app 0.6.4, MacOS X 10.7.4) that I'm trying to export to py2app. The problem only started occurring in the standalone py2app-ified app version of the program. When I run the python source file from which the app was created, the problem does not exist, so I feel it must have something to do with the py2app export.
The problem: When I start the GUI, the first time I try to load a valid image file, the image fails to load, and I get the following error from the PIL Image module:
File "Image.pyc", line 1980, in open
IOError: cannot identify image file
When I then (without closing the GUI or anything) try to open the exact same file, it loads perfectly, no errors or problems. This happens every time, with any image file I try - the first attempt to load fails, subsequent attempts succeed. I should add that after that first error, no image files ever fail to load - even if they are different from the first one.
A few notes:
- The image file is a sequence, and is very large (around 300 MB), so to speed up the loading process, I use a mmap. I have tried removing the mmap step, and handing a regular file object directly to ImagePIL.open it directly, and the problem is unaffected.
- I also tried seeking to the beginning of the file before giving it to ImagePIL.open, but that had no effect.
- The py2app setup file is pretty vanilla - it just includes a few config files and an icon.
Here is the relevant part of the offending image load function:
import Image as ImagePIL
import mmap as m
...
...
def loadImage(self):
errorLog.debug("Attempting to open image \""+self.filenameVar.get()+"\"")
try:
if self.fileMap is not None:
self.fileMap.close()
imageFile = open(self.filenameVar.get(), 'r')
self.fileMap = m.mmap(imageFile.fileno(), 0, prot=m.PROT_READ)
# self.fileMap.seek(0)
self.imageSeries = ImagePIL.open(self.fileMap)
imageFile.close()
except(IOError):
errorLog.exception("Failed to open image \""+self.filenameVar.get()+"\"")
return
I'm pretty stumped - any ideas? Thanks in advance!
Edit: I should add that Tkinter, PIL, and py2app were installed using MacPorts 2.1.2, in the off chance that helps.
It seems that py2app does not include PIL's image plugins into the application bundle even though one of the py2app recipes tries to ensure that they are included.
One thing you could try is to build with "python setup.py py2app --packages=PIL" and then use "import PIL.Image as ImagePIL" to use it.
I don't understand yet why the PIL recipe doesn't work, it might be something in the way MacPorts builds python packages (I don't use MacPorts myself).
The problem is the result of inconsistency between Pillow version 3.0.0 and py2app.
I suggest two solution to avoid PIL (Pillow)
Use opencv instead of PIL.
uninstall the current version of Pillow and install a previous one like 1.7.8