Sync util restructuring
This commit is contained in:
1 parent
9025044ae5
commit
721917bb02
7 files changed
+64
-28
No files matched your search
@@ -0,0 +1,8 @@
|
|||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
|
def read_image(src):
|
||||||
|
try:
|
||||||
|
return Image.open(src)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return None
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from image.image import read_image
|
||||||
|
from image.resize import optimize, thumbnail
|
||||||
|
|
||||||
|
|
||||||
|
def image_processor(images_dir, public_base_url, sizes, name_generator):
|
||||||
|
def process(file):
|
||||||
|
image = read_image(file)
|
||||||
|
if not image:
|
||||||
|
return None
|
||||||
|
|
||||||
|
basename = os.path.basename(file)
|
||||||
|
uri, ext = os.path.splitext(basename)
|
||||||
|
|
||||||
|
image_dict = {}
|
||||||
|
for size in sizes:
|
||||||
|
size_name, width, height = size
|
||||||
|
|
||||||
|
image_filename = name_generator(uri, size_name, ext)
|
||||||
|
d = os.path.join(images_dir, image_filename)
|
||||||
|
image_url = os.path.join(public_base_url, image_filename)
|
||||||
|
|
||||||
|
do_optimize = size_name == 'original'
|
||||||
|
thumb = optimize(image, d, quality=90) if do_optimize else thumbnail(image, d, (width, height))
|
||||||
|
width, height = thumb.size
|
||||||
|
image_dict[size_name] = {
|
||||||
|
'url': image_url,
|
||||||
|
'size': size_name,
|
||||||
|
'width': width,
|
||||||
|
'height': height
|
||||||
|
}
|
||||||
|
|
||||||
|
return image_dict
|
||||||
|
return process
|
||||||
@@ -2,14 +2,6 @@ import os
|
|||||||
|
|
||||||
from subprocess import call
|
from subprocess import call
|
||||||
|
|
||||||
__author__ = 'Roman Timashev'
|
|
||||||
|
|
||||||
from PIL import Image
|
|
||||||
|
|
||||||
|
|
||||||
def read_image(src):
|
|
||||||
return Image.open(src)
|
|
||||||
|
|
||||||
|
|
||||||
def thumbnail(image, dest, size, ext=None):
|
def thumbnail(image, dest, size, ext=None):
|
||||||
image.thumbnail(size)
|
image.thumbnail(size)
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
import os
|
import os
|
||||||
from datetime import datetime
|
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import lxml.html
|
import lxml.html
|
||||||
from markdown import markdown
|
from markdown import markdown
|
||||||
import time
|
|
||||||
|
|
||||||
import img
|
|
||||||
from Album import Album
|
|
||||||
import lxml_utils
|
import lxml_utils
|
||||||
import settings
|
import settings
|
||||||
|
from Album import Album
|
||||||
from Product import Product
|
from Product import Product
|
||||||
|
from image import resize
|
||||||
|
|
||||||
__author__ = 'Roman Timashev'
|
__author__ = 'Roman Timashev'
|
||||||
|
|
||||||
@@ -129,7 +130,7 @@ class GalleryReader:
|
|||||||
def create_image(self, name, filename, sizes, ext, base_url):
|
def create_image(self, name, filename, sizes, ext, base_url):
|
||||||
thumbs = {}
|
thumbs = {}
|
||||||
for size, width, height in sizes:
|
for size, width, height in sizes:
|
||||||
source_image = img.read_image(filename)
|
source_image = resize.read_image(filename)
|
||||||
sw, sh = source_image.size
|
sw, sh = source_image.size
|
||||||
if sw < sh:
|
if sw < sh:
|
||||||
width, height = height, width
|
width, height = height, width
|
||||||
|
|||||||
+7
-8
@@ -1,13 +1,12 @@
|
|||||||
from glob import glob
|
|
||||||
import os
|
import os
|
||||||
import markdown as md
|
from glob import glob
|
||||||
|
|
||||||
import lxml.html as html
|
import lxml.html as html
|
||||||
|
import markdown as md
|
||||||
from lxml.etree import tostring
|
from lxml.etree import tostring
|
||||||
import re
|
|
||||||
import pymongo
|
|
||||||
import requests
|
|
||||||
import img
|
|
||||||
import lxml_utils
|
import lxml_utils
|
||||||
|
from image import resize
|
||||||
|
|
||||||
__author__ = 'tmshv'
|
__author__ = 'tmshv'
|
||||||
|
|
||||||
@@ -210,9 +209,9 @@ for cf in catalog_files:
|
|||||||
d = os.path.join(images_dir, image_filename)
|
d = os.path.join(images_dir, image_filename)
|
||||||
pi[size_name] = 'http://static.touchtwin.ru/images/{img}'.format(img=image_filename)
|
pi[size_name] = 'http://static.touchtwin.ru/images/{img}'.format(img=image_filename)
|
||||||
if size_name == 'original':
|
if size_name == 'original':
|
||||||
img.optimize(image, d, quality=90)
|
resize.optimize(image, d, quality=90)
|
||||||
else:
|
else:
|
||||||
img.minify(image, d, size[:2])
|
resize.minify(image, d, size[:2])
|
||||||
|
|
||||||
images.append(pi)
|
images.append(pi)
|
||||||
i += 1
|
i += 1
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ from glob import glob
|
|||||||
|
|
||||||
from pymongo import MongoClient
|
from pymongo import MongoClient
|
||||||
|
|
||||||
import img
|
|
||||||
import settings
|
import settings
|
||||||
|
from image import resize
|
||||||
|
|
||||||
|
|
||||||
def generate_image_filename(image, size_name, ext):
|
def generate_image_filename(image, size_name, ext):
|
||||||
@@ -24,7 +24,7 @@ def generate_image_filename(image, size_name, ext):
|
|||||||
|
|
||||||
def process_file(file):
|
def process_file(file):
|
||||||
sizes = settings.image_sizes
|
sizes = settings.image_sizes
|
||||||
image = img.read_image(file)
|
image = resize.read_image(file)
|
||||||
images_dir = '/Users/tmshv/Desktop/Hudozka Awards'
|
images_dir = '/Users/tmshv/Desktop/Hudozka Awards'
|
||||||
public_base_url = 'https://static.shlisselburg.org/art/awards/'
|
public_base_url = 'https://static.shlisselburg.org/art/awards/'
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ def process_file(file):
|
|||||||
d = os.path.join(images_dir, image_filename)
|
d = os.path.join(images_dir, image_filename)
|
||||||
image_url = os.path.join(public_base_url, image_filename)
|
image_url = os.path.join(public_base_url, image_filename)
|
||||||
|
|
||||||
thumb = img.optimize(image, d, quality=90) if size_name == 'original' else img.thumbnail(image, d, (width, height))
|
thumb = resize.optimize(image, d, quality=90) if size_name == 'original' else resize.thumbnail(image, d, (width, height))
|
||||||
|
|
||||||
width, height = thumb.size
|
width, height = thumb.size
|
||||||
award['thumbs'][size_name] = {
|
award['thumbs'][size_name] = {
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
from functools import reduce
|
|
||||||
from glob import glob
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from functools import reduce
|
||||||
|
from glob import glob
|
||||||
|
|
||||||
from pymongo import MongoClient
|
from pymongo import MongoClient
|
||||||
import img as img_util
|
|
||||||
from read_gallery_1 import GalleryReader
|
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
|
from image import resize as img_util
|
||||||
|
from read_gallery_1 import GalleryReader
|
||||||
|
|
||||||
__author__ = 'Roman Timashev'
|
__author__ = 'Roman Timashev'
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user