from PIL import Image
from tempfile import NamedTemporaryFile
import os


def is_image_compressable(path):
    ACCEPTABLE = [".jpg", ".png"]
    ext = os.path.splitext(path)[1].lower()
    return ext in ACCEPTABLE


def _detect_valid_format(path):
    ext = os.path.splitext(path)[1].lower()
    return {".jpg": "jpeg", ".png": "png"}.get(ext)


def compress(path, size=(1024, 3000)):
    im = Image.open(path)
    im.thumbnail(size, Image.ANTIALIAS)
    with NamedTemporaryFile(delete=False) as temp:
        im.save(temp, _detect_valid_format(path), quality=100, optimize=True)
        return temp

6bf1fd682a6ff9427d37383340eb9861fec9bcda
<mask token>


def compress(path, size=(1024, 3000)):
    im = Image.open(path)
    im.thumbnail(size, Image.ANTIALIAS)
    with NamedTemporaryFile(delete=False) as temp:
        im.save(temp, _detect_valid_format(path), quality=100, optimize=True)
        return temp

<mask token>


def is_image_compressable(path):
    ACCEPTABLE = ['.jpg', '.png']
    ext = os.path.splitext(path)[1].lower()
    return ext in ACCEPTABLE


<mask token>


def compress(path, size=(1024, 3000)):
    im = Image.open(path)
    im.thumbnail(size, Image.ANTIALIAS)
    with NamedTemporaryFile(delete=False) as temp:
        im.save(temp, _detect_valid_format(path), quality=100, optimize=True)
        return temp

<mask token>


def is_image_compressable(path):
    ACCEPTABLE = ['.jpg', '.png']
    ext = os.path.splitext(path)[1].lower()
    return ext in ACCEPTABLE


def _detect_valid_format(path):
    ext = os.path.splitext(path)[1].lower()
    return {'.jpg': 'jpeg', '.png': 'png'}.get(ext)


def compress(path, size=(1024, 3000)):
    im = Image.open(path)
    im.thumbnail(size, Image.ANTIALIAS)
    with NamedTemporaryFile(delete=False) as temp:
        im.save(temp, _detect_valid_format(path), quality=100, optimize=True)
        return temp

from PIL import Image
from tempfile import NamedTemporaryFile
import os


def is_image_compressable(path):
    ACCEPTABLE = ['.jpg', '.png']
    ext = os.path.splitext(path)[1].lower()
    return ext in ACCEPTABLE


def _detect_valid_format(path):
    ext = os.path.splitext(path)[1].lower()
    return {'.jpg': 'jpeg', '.png': 'png'}.get(ext)


def compress(path, size=(1024, 3000)):
    im = Image.open(path)
    im.thumbnail(size, Image.ANTIALIAS)
    with NamedTemporaryFile(delete=False) as temp:
        im.save(temp, _detect_valid_format(path), quality=100, optimize=True)
        return temp

from PIL import Image
from tempfile import NamedTemporaryFile
import os


def is_image_compressable(path):
    ACCEPTABLE = [".jpg", ".png"]
    ext = os.path.splitext(path)[1].lower()
    return ext in ACCEPTABLE


def _detect_valid_format(path):
    ext = os.path.splitext(path)[1].lower()
    return {".jpg": "jpeg", ".png": "png"}.get(ext)


def compress(path, size=(1024, 3000)):
    im = Image.open(path)
    im.thumbnail(size, Image.ANTIALIAS)
    with NamedTemporaryFile(delete=False) as temp:
        im.save(temp, _detect_valid_format(path), quality=100, optimize=True)
        return temp
