emcconville / wand

The ctypes-based simple ImageMagick binding for Python
http://docs.wand-py.org/
Other
1.42k stars 199 forks source link

convert format(some) not work in django rest framework #623

Closed Chhunneng closed 1 year ago

Chhunneng commented 1 year ago

As I try to convert many file type on my computer, it worked normally. But in django rest framework on webserver, not work. In serializer, I create a temporary directory, then I save file from request body to directory and I use wand to read image from temporary and write it back for converted file. It shows error and not sure it error because wand or imagemagick

sh: line 1: JxrDecApp: command not found
/usr/bin/mv: cannot stat '/tmp/magick-tmdXaDsLOZqhpZw5bieSNrektDXDvS3P.pnm': No such file or directory
Wand Error: unable to open file `/tmp/magick-Ki9jITFD8z4uhvzl22oySVB5TpnAlMon': No such file or directory @ error/constitute.c/ReadImage/620

Here is my code

temp_dir = tempfile.TemporaryDirectory()
original_picture = validated_data.pop("picture")
temp_original_picture_path = os.path.join(temp_dir.name, "filename.ARW")
temp_converted_picture_path = os.path.join(temp_dir.name, "filename.png")
# store file in TemporaryDirectory
with open(temp_original_picture_path, 'wb') as f:
    for chunk in original_picture.chunks():
        f.write(chunk)
try:
    from wand.image import Image as WandImage
    with WandImage(filename=temp_original_picture_path) as image:
        image.format = 'png'
        image.save(filename=temp_converted_picture_path)
except Exception as e:
    print("Wand Error:", e)

Note: but when I try on my PC it works normal

emcconville commented 1 year ago

It shows error and not sure it error because wand or imagemagick

The "command not found" is key. The server is not set-up to decode the image formats being submitted through the django application.

Ensure the server has all the decoding libraries installed. In this case, jpegxr support is needed, and should be provided by jxrlib. Tip for future projects: use unit testing to identify problems, and a combination of pyinfra & fabric to ensure all environments match.