コード例 #1
0
def convert_jpg_to_png(subfolder, instance_id):
    file_source_name = "%s.jpg" % instance_id
    file_target_name = "%s.png" % instance_id
    thumbnail_folder = create_folder(subfolder)
    file_source_path = os.path.join(thumbnail_folder, file_source_name)
    file_target_path = os.path.join(thumbnail_folder, file_target_name)

    im = Image.open(file_source_path)
    im.save(file_target_path)
    fs.rm_file(file_source_path)
    return file_target_path
コード例 #2
0
def convert_jpg_to_png(file_source_path):
    """
    Convert .jpg file located at given path into a .png file with same name.
    """
    folder_path = os.path.dirname(file_source_path)
    file_source_name = os.path.basename(file_source_path)
    file_target_name = "%s.png" % file_source_name[:-4]
    file_target_path = os.path.join(folder_path, file_target_name)

    im = Image.open(file_source_path)
    im.save(file_target_path)
    fs.rm_file(file_source_path)
    return file_target_path