本文整理汇总了Python中pgmagick.Image.quality方法的典型用法代码示例。如果您正苦于以下问题:Python Image.quality方法的具体用法?Python Image.quality怎么用?Python Image.quality使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgmagick.Image
的用法示例。
在下文中一共展示了Image.quality方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: crop
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import quality [as 别名]
def crop(request, block):
id = int(request.GET.get('id', -1))
data = json.loads(request.GET.get('data', []))
from core.models import File
file = File.objects.get(id=id)
file_crop_data = file.data.get('scale', {})
from pgmagick import Image, Geometry
file_path = '%s/%s' % (MEDIA_ROOT, file.path)
full_file_path = '%s/%s' % (file_path, file.file_name)
for crop_data in data:
#
# do not crop same image twice
#
if crop_data['name'] in file_crop_data:
local_crop_data = file_crop_data[crop_data['name']]
if 'scaled_width' in local_crop_data and 'scaled_height' in local_crop_data and 'crop_x' in local_crop_data and 'crop_y' in local_crop_data:
if local_crop_data['scaled_width'] == int(crop_data['scaled_width']) and local_crop_data['scaled_height'] == int(crop_data['scaled_height']) and local_crop_data['crop_x'] == int(crop_data['crop_x']) and local_crop_data['crop_y'] == int(
crop_data['crop_y']):
continue
image = Image(str(full_file_path))
g = Geometry(int(crop_data['scaled_width']), int(crop_data['scaled_height']), 0, 0)
image.scale(g)
gc = Geometry(int(crop_data['width']), int(crop_data['height']), int(crop_data['crop_x']), int(crop_data['crop_y']))
image.crop(gc)
image.quality(100)
image.sharpen(1.0)
full_scaled_image_path = '%s/%s_%s' % (file_path, crop_data['prefix'], file.file_name)
image.write(str(full_scaled_image_path))
scale_data = dict(
width=int(crop_data['width']),
height=int(crop_data['height']),
scaled_width=int(crop_data['scaled_width']),
scaled_height=int(crop_data['scaled_height']),
crop_x=int(crop_data['crop_x']),
crop_y=int(crop_data['crop_y']),
center_x=crop_data['center_x'],
center_y=crop_data['center_y'],
quality=100,
sharpen=1.0,
prefix=crop_data['prefix'],
name=crop_data['name'],
cropped=True
)
file.data['scale'][crop_data['name']] = scale_data
file.save()
return dict(status='success', message='Image %s was successfully cropped.' % file.title, id=id)
示例2: test
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import quality [as 别名]
def test():
from pgmagick import Image, FilterTypes
im = Image( './chambres-deluxes-I/chambre-101-s-474.tif' )
im.quality( 100 )
im.filterType( FilterTypes.SincFilter )
im.scale( '100x100' )
im.sharpen( 1.0 )
im.write( 'output.jpg' )
示例3: addScreenshot
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import quality [as 别名]
def addScreenshot(f, arg, user_id, item):
if item == 'map':
Object = Maps.objects.filter(id=arg)
if not Object:
return False
if not (Object[0].user_id == user_id.id or user_id.is_superuser):
return False
else:
return False
tempname = '/tmp/screenshot.temp'
with open(tempname, 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
command = 'file -b --mime-type %s' % tempname
proc = Popen(command.split(), stdout=PIPE).communicate()
mimetype = proc[0].strip()
if mimetype not in ['image/jpeg','image/png','image/gif']:
return False
userObject = User.objects.get(pk=Object[0].user_id)
transac = Screenshots(
user = userObject,
ex_id = int(arg),
ex_name = item+"s",
posted = timezone.now(),
map_preview = False,
)
transac.save()
path = os.getcwd() + os.sep + __name__.split('.')[0] + '/data/screenshots/' + str(transac.id) + '/'
if not os.path.exists(path):
os.makedirs(path)
shutil.move(tempname, path + arg + "." + mimetype.split('/')[1])
command = 'identify -format "%w,%h" {0}'.format(path + arg + "." + mimetype.split('/')[1])
proc = Popen(command.split(), stdout=PIPE).communicate()
details = proc[0].strip().strip('"').split(',')
im = Image(Blob(open(path + arg + "." + mimetype.split('/')[1]).read()), Geometry(int(details[0]),int(details[1])))
scaleH = int(details[0]) / 100.0
scaleH = 250 / scaleH
scaleH = int(details[1]) / 100.0 * scaleH
im.quality(100)
im.filterType(FilterTypes.SincFilter)
im.scale('250x%s' % scaleH)
im.sharpen(1.0)
im.write(str(path + arg + "-mini." + mimetype.split('/')[1]))
示例4: specificRecord
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import quality [as 别名]
def specificRecord(theId):
# Get the record.
aRow = db.session.query(ServiceRecord, Vehicle).filter_by(id=theId).join(Vehicle).first()
aRecord = {
"id": aRow[0].id,
"year": aRow[1].year,
"make": aRow[1].make,
"model": aRow[1].model,
"date": aRow[0].date,
"miles": aRow[0].miles,
"description": aRow[0].description
}
# Get the filepaths for the photos.
import os
aPostfix = "vehicles/receipts/{}".format(theId)
aList = [url_for("static", filename=aPostfix + os.sep + x) for x in os.listdir("app/static/" + aPostfix)]
# Create the form.
aForm = PhotoForm()
# Check to see if the form is valid as well as a post request.
if aForm.validate_on_submit():
filename = secure_filename(aForm.upload.data.filename)
aSavePath = 'app/static/vehicles/receipts/{}/'.format(theId) + filename
aForm.upload.data.save(aSavePath)
# Convert the photo to nice web stuff.
from pgmagick import Image, InterlaceType
aImg = Image(aSavePath)
aImg.quality(80)
aImg.scale("80%")
aImg.interlaceType(InterlaceType.PlaneInterlace)
aImg.write(aSavePath)
flash("File uploaded", "success")
aForm = PhotoForm()
return render_template(
"vehicles/record.html",
theRecord=aRecord,
theFiles=aList,
theForm=aForm
)
示例5: Image
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import quality [as 别名]
import sys
from pgmagick import Image, FilterTypes as ft
# same
# convert SRC.jpg -filter Sinc -resize 500x500 -sharpen 1 -quality 100 DST.jpg
# gm convert SRC.jpg -filter Sinc -resize 500x500 -sharpen 1 -quality 100 DST.jpg
im = Image('./X.jpg')
im.quality(100)
im.sharpen(1.0)
im.write('./Y.jpg')
im = Image('./X.jpg')
im.quality(100)
im.filterType(ft.SincFilter)
im.scale('1000x1000')
im.sharpen(1.0)
im.write('./Y.jpg')
im = Image('./X.jpg')
im.quality(100)
im.filterType(ft.SincFilter)
im.scale('100x100')
im.sharpen(1.0)
im.write('./Y.jpg')
im = Image('./X.jpg')
im.quality(100)
im.filterType(ft.SincFilter)
im.scale('500x500')
im.sharpen(1.0)
示例6: post
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import quality [as 别名]
def post(self, gid=None):
good_keys = ['catalog', 'name', 'subname', 'price', 'discount']
good = dict()
if gid:
good = self.db.goods.find_one({'_id':gid})
for key in good_keys:
good[key] = self.get_argument(key, None)
if gid:
self.db.goods.save(good)
else:
#========= new id generate
gid = 'G'+(str(uuid.uuid4()).split('-'))[4].upper()
#========= image handler
# check pic exgister
if self.request.files == {} or 'pic' not in self.request.files:
self.write('<script>alert("请选择图片")</script>')
send_file = self.request.files['pic'][0]
# check pic format
image_type = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/bmp', 'image/png', 'image/x-png']
if send_file['content_type'] not in image_type:
self.write('<script>alert("仅支持jpg,jpeg,bmp,gif,png格式的图片")</script>')
# check pic size 4M
if len(send_file['body']) > 4 * 1024 * 1024:
self.write('<script>alert("请上传4M以下的图片");</script>')
# create temp file
tmp_file = tempfile.NamedTemporaryFile(delete=True)
tmp_file.write(send_file['body'])
tmp_file.seek(0)
# illegal pic can't open with Image
try:
image_one = Image(tmp_file.name)
except IOError:
logging.info(error)
logging.info('+'*30 + '\n')
logging.info(self.request.headers)
tmp_file.close()
self.write('<script>alert("图片不合法!")</script>')
# check pixel
if image_one.columns() < 250 or image_one.rows() < 250 or \
image_one.columns() > 2000 or image_one.rows() > 2000:
tmp_file.close()
self.write('<script>alert("图片长宽在250px~2000px之间!")</script>')
# saving two type
image_path = "./static/images/goods/"
image_format = send_file['filename'].split('.').pop().lower()
thumbnail_174 = image_path + gid + '_174.' + image_format
image_one.quality(100)
image_one.scale('174x174')
image_one.write(str(thumbnail_174))
thumbnail_94 = image_path + gid + '_94.' + image_format
image_one.quality(100)
image_one.scale('94x94')
image_one.write(str(thumbnail_94))
# close temp
tmp_file.close()
good['_id'] = gid
good['image1'] = thumbnail_174
good['image2'] = thumbnail_94
self.db.goods.insert(good)
self.redirect('/admin', permanent=True)