makaleler / Python Programlama / image resize işlemi

image resize işlemi

01.01.2012 17:58:26

Selamun Aleykum,

Python da image resize örneği
#------------------------------------------------------------------------------
# Resim Resize Yapalım Width Height filename parametre olsun
def resize_photo(target_path, source_path, filename, width, height):
    try:
        img = Image.open(source_path + filename).resize( (width, height) )
        full_file_name = target_path + filename
        print full_file_name
        out = file(os.path.splitext(full_file_name)[0]+".jpg", "w")
        try:
            img.save(out, "JPEG")
        finally:
            out.close()
        komut = "jpegoptim %s" % (full_file_name)
        try:
            pid = subprocess.Popen(komut, shell=True, stdin=subprocess.PIPE,
                           stdout=subprocess.PIPE, stderr=subprocess.PIPE,)
            pid.wait()
        except Exception, err:
            if DEBUG:
                raise
            else:
                print(str(err))
    except Exception, err:
        if DEBUG:
            raise
        else:
            print(str(err))


Kullanımı
 resize_photo(DOWNLOADED_IMAGE_220x163_PATH, DOWNLOADED_IMAGE_PATH,  filename, 220, 163)

yazar husonet

Yorumlar

Bu içerik için sizde yorum yapabilirsiniz!
anasayfa | makaleler | haberler | dosyalar | linkler | hakkımızda