Mfinley72
Mfinley72

Reputation: 21

.emf to .jpg conversion issues

I am using the following code to convert .emf files to .jpg.

import os, sys
from PIL import Image

for infile in sys.argv[1:]:
    f, e = os.path.splitext(infile)
    outfile = f + ".jpg"
    if infile != outfile:
        try:
            Image.open(infile).convert('RGB').save(outfile)
        except IOError:
            print("cannot convert", infile)

It creates the new file with the .jpg extension, but the file appears to be blank. Any suggestions? Thanks

I found another post that suggested adding the following:

from PIL import BmpImagePlugin,GifImagePlugin,Jpeg2KImagePlugin,JpegImagePlugin,PngImagePlugin,TiffImagePlugin,WmfImagePlugin

But the file still appears to be blank.

Upvotes: 1

Views: 244

Answers (1)

Mfinley72
Mfinley72

Reputation: 21

This is how I resolved the issue:

from wand.image import Image
import os,sys

infolder = 'C:/Original'
outfolder = 'C:/Converted'

for filename in os.listdir(infolder):
    infilename = os.path.join(infolder, filename)
    outfilename = os.path.join(outfolder, filename.replace('.emf', '.jpg'))
    if not os.path.isfile(infilename): continue
    if not os.path.getsize(infilename) > 999: continue
    oldbase = os.path.splitext(filename)
    with Image(filename =infilename) as img:
        with img.convert('jpg') as converted:
            converted.save(filename =outfilename)

Upvotes: 1

Related Questions