当前位置: 首页>>代码示例>>Python>>正文


Python Image.scale方法代码示例

本文整理汇总了Python中pgmagick.Image.scale方法的典型用法代码示例。如果您正苦于以下问题:Python Image.scale方法的具体用法?Python Image.scale怎么用?Python Image.scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pgmagick.Image的用法示例。


在下文中一共展示了Image.scale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: thumbnail

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [as 别名]
def thumbnail(request, type, identifier):
    response = HttpResponse(mimetype="image/png")
    size = str(request.GET.get("size", "190x270"))
    if not re.match("\d+[x]\d+", size):
        size = "190x270"

    cache_key = "thumbnail:%s:%s:%s" % (type, identifier, size)
    cached = cache.get(cache_key)
    if cached is None:
        if type == "file":
            file_ = str(os.path.join(settings.INCOMING_DIRECTORY, identifier))
        elif type == "document":
            document = get_object_or_404(Document, pk=identifier)
            file_ = Blob(document.document.read())

        image = Image(file_)
        image.filterType(FilterTypes.SincFilter)
        image.scale(size)

        output = Blob()
        image.write(output, "png")
        response.write(output.data)
        cache.set(cache_key, output.data)
    else:
        response.write(cached)

    return response
开发者ID:NaPs,项目名称:Docbucket,代码行数:29,代码来源:views.py

示例2: test_scale_jpeg

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [as 别名]
 def test_scale_jpeg(self):
     img = api.Image((400, 400), 'blue')
     img.write(self.tmp_filename_jpg)
     img2 = Image(Blob(open(self.tmp_filename_jpg).read()),
                  Geometry(200, 200))
     img2.scale('200x200')
     img2.write(self.tmp_filename_jpg)
开发者ID:IsaacHuang,项目名称:SAphotoMachines,代码行数:9,代码来源:test_cookbook.py

示例3: crop

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [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)
开发者ID:timrc,项目名称:schproj,代码行数:62,代码来源:files.py

示例4: resize3

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [as 别名]
    def resize3( srcFile="", destFile="", w=200,h=200, color="", crop=False, align="center" ):

        img = Image(srcFile)
        img.scale("%dx%d>"%(w,h))
        img.profile("*",Blob())
        img.write(destFile)
        return "True"
开发者ID:sqj0213,项目名称:photoEncode,代码行数:9,代码来源:myGraphicsMagick.py

示例5: resize8

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [as 别名]
    def resize8( srcFile="", destFile="", w=200,h=200 ):
        img = Image(srcFile)

        #.def("extent", (void (Magick::Image::*)(const Magick::Geometry&, const Magick::Color&, const Magick::GravityType))&Magick::Image::extent)
        #白色背景图
        backImg = None

        #sw源图宽度
        sw = img.columns()
        #sh源图高度
        sh = img.rows()
        #若目标图的宽或高都比源图大则不处理
        if ( sw <= w and sh <= h ):
            backImg = Image(Geometry(w,h), 'white' )
            backImg.composite(img, GravityType.CenterGravity, co.OverCompositeOp)
            backImg.profile("*",Blob())
            backImg.write(destFile)
            return "True"
        #目标的宽或高都比源图的小则进行裁剪
        elif ( sw > w and sh > h ):
            #源图的宽高比
            sratio = float(sw)/float(sh)
            rratio = float(w)/float(h)
            #若源图宽高比大于目标图的宽高比的话,则就高缩放,从0,0位置裁前源图宽
            #print sratio,rratio
            if ( sratio > rratio ):
                hscale = float(h)/float(sh)
                rw = int(sw*hscale)
                rh = int(sh*hscale)
            else:
                wscale = float(w)/float(sw)
                rw = int(sw*wscale)
                rh = int(sh*wscale)

            linePos = int( (rw-w)/2)
            colPos = int( (rh-h)/2)

            img.scale("%dx%d"%(rw,rh))
            img.crop(Geometry(w,h,linePos,colPos))
            img.profile("*",Blob())
            img.write(destFile)
            return "True"
        elif ( sw > w ):
            backImg = Image(Geometry(w,h), 'white' )
            img.crop(Geometry(w,sh,int((sw-w)/2)))
            backImg.composite(img,GravityType.CenterGravity,co.OverCompositeOp )
            backImg.profile("*",Blob())
            backImg.write(destFile)
            return "True"
        elif ( sh > h ):
            backImg = Image(Geometry(w,h), 'white' )
            img.crop( Geometry(sw,h,0,int((sh-h)/2) ) )
            backImg.composite(img, GravityType.CenterGravity,co.OverCompositeOp )
            backImg.profile("*",Blob())
            backImg.write(destFile)
            return "True"
        return "True"
开发者ID:sqj0213,项目名称:photoEncode,代码行数:59,代码来源:myGraphicsMagick.py

示例6: test

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [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' )
开发者ID:NicHub,项目名称:pousadajardimdosanjos-v3-hugosource,代码行数:11,代码来源:tif2jpg.py

示例7: resize2

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [as 别名]
 def resize2( srcFile="", destFile="", w=200,h=200 ):
     blobData = Blob(open(srcFile).read())
     if ( h != -1 ):
         img = Image( blobData, Geometry(w, h))
         img.scale("%dx%d!" % (w,h))
     else:
         img = Image( blobData )
         img.scale("%dx!" % w )
     img.profile("*",Blob())
     img.write(destFile)
     return "True"
开发者ID:sqj0213,项目名称:photoEncode,代码行数:13,代码来源:myGraphicsMagick.py

示例8: resize0

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [as 别名]
    def resize0( srcFile="", destFile="", w=200 ):

        img = Image(srcFile)
        sw = img.columns()
        sh = img.rows()
        if ( sw > w  ):
            tw = w
            th = sh*(float(w)/float(sw))
            img.scale("%dx%d"%(tw,th))
        img.profile("*", Blob())
        img.write(destFile)
        return "True"
开发者ID:sqj0213,项目名称:photoEncode,代码行数:14,代码来源:myGraphicsMagick.py

示例9: resize7

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [as 别名]
    def resize7( srcFile="", destFile="", w=200,h=200 ):
        img = Image(srcFile)

        #白色背景图
        backImg = None

        #sw源图宽度
        sw = img.columns()
        #sh源图高度
        sh = img.rows()
        #若目标图的宽或高都比源图大则不处理
        if ( sw <= w and sh <= h ):
            backImg = Image(Geometry(w,h), 'white' )
            backImg.composite(img, Geometry( sw, sh, 0, 0 ), co.OverCompositeOp)
            backImg.profile("*",Blob())
            backImg.write(destFile)
            return "True"
        #目标的宽或高都比源图的小则进行裁剪
        elif ( sw > w and sh > h ):
            #源图的宽高比
            sratio = float(sw)/float(sh)
            rratio = float(w)/float(h)
            #若源图宽高比大于目标图的宽高比的话,则就高缩放,从0,0位置裁前源图宽
            #print sratio,rratio
            if ( sratio > rratio ):
                hscale = float(h)/float(sh)
                rw = int(sw*hscale)
                rh = int(sh*hscale)
            else:
                wscale = float(w)/float(sw)
                rw = int(sw*wscale)
                rh = int(sh*wscale)
            img.scale("%dx%d"%(rw,rh))
            img.crop(Geometry(w,h,0,0))
            img.profile("*",Blob())
            img.write(destFile)
            return "True"
        elif ( sw > w ):
            backImg = Image(Geometry(w,h), 'white' )
            img.crop(Geometry(w,sh))
            backImg.composite(img,Geometry(w,h,0,0),co.OverCompositeOp )
            backImg.profile("*",Blob())
            backImg.write(destFile)
            return "True"
        elif ( sh > h ):
            backImg = Image(Geometry(w,h), 'white' )
            img.crop( Geometry(sw,h) )
            backImg.composite(img, Geometry(w,h,0,0),co.OverCompositeOp )
            backImg.profile("*",Blob())
            backImg.write(destFile)
            return "True"
        return "True"
开发者ID:sqj0213,项目名称:photoEncode,代码行数:54,代码来源:myGraphicsMagick.py

示例10: resize10

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [as 别名]
    def resize10( srcFile="", destFile="", w=200 ):
        img = Image( srcFile )
        sw = img.columns()
        sh = img.rows()
        scale = sw*sh

        if ( scale > w ):
            tw = int(sw*((float(w)/float(scale))**0.5))
            th = int(w/tw)
            img.scale("%dx%d"%(tw,th))
        img.profile("*",Blob())
        img.write(destFile)
        return "True"
开发者ID:sqj0213,项目名称:photoEncode,代码行数:15,代码来源:myGraphicsMagick.py

示例11: addScreenshot

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [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]))
开发者ID:temna-net,项目名称:OpenRA-Resources,代码行数:53,代码来源:handlers.py

示例12: test_scale_jpeg

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [as 别名]
 def test_scale_jpeg(self):
     img = api.Image((400, 400), 'blue')
     img.write(self.tmp_filename_jpg)
     with open(self.tmp_filename_jpg, 'rb') as fp:
         b = Blob(str(fp.read()))
         img2 = Image(b, Geometry(200, 200))
         if sys.platform.lower() == 'darwin':
             # NOTE: error occur when use '200x200' param
             #       -----------------------------------------------------
             #       RuntimeError: Magick: Application transferred too few
             #       scanlines (x.jpg) reported by coders/jpeg.c:344 (JPEGErrorHandler)
             img2.scale('199x199')
         else:
             img2.scale('200x200')
         img2.write(self.tmp_filename_jpg)
开发者ID:hhatto,项目名称:pgmagick,代码行数:17,代码来源:test_cookbook.py

示例13: resize9

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [as 别名]
    def resize9( srcFile="", destFile="", w=200,h=200, color="", crop=False, align="center" ):
        img = Image(srcFile)

        #白色背景图
        backImg = None

        #sw源图宽度
        sw = img.columns()
        #sh源图高度
        sh = img.rows()

        #目标图与源图的宽比例
        wScale = float(w)/float(sw)
        #目标图与源图的高比例
        hScale = float(h)/float(sh)

        if ( w > sw or h > sh ):
            if (wScale == hScale ):
                tw = w
                th = h
            elif ( wScale < hScale ):
                th = h
                tw = sw*wScale
            else:
                tw = w
                th = sh*hScale
        elif( w<sw or h < sh ):
            if (wScale == hScale ):
                tw = w
                th = h
            elif ( wScale < hScale ):
                th = h
                tw = sw*wScale
            else:
                tw = w
                th = sh*hScale
        else:
            tw = sw
            th = sh
        img.scale("%dx%d"%(tw,th))
        backImg = Image(Geometry(w,h), 'white' )
        backImg.composite(img,GravityType.CenterGravity,co.OverCompositeOp )
        backImg.profile("*",Blob())
        backImg.write(destFile)
        return "True"
开发者ID:sqj0213,项目名称:photoEncode,代码行数:47,代码来源:myGraphicsMagick.py

示例14: specificRecord

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [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
  )
开发者ID:milogert,项目名称:website,代码行数:47,代码来源:controllers.py

示例15: bobross

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import scale [as 别名]
	def bobross(self,imgStr):
		print "bobross()"
		bob=Image('bob-transparent-canvas.png')
		bob.matte(True)
		#print "1"
		img=Image(imgStr)
		#print "2"
		newsize=Geometry(200,343)
		newsize.aspect(True)
		img.scale(newsize)
		#print "3"
		img=self.watercolor(img)
		#print "4"
		result=Image(bob.size(),'white')
		result.composite(img,392,22,CompositeOperator.OverCompositeOp)
		result.composite(bob,0,0,CompositeOperator.OverCompositeOp)
		
		return result
开发者ID:adamriggs,项目名称:reddit-api,代码行数:20,代码来源:imgfx.py


注:本文中的pgmagick.Image.scale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。