def scale_image(data, width=60, height=80, compression_quality=70, as_png=False, preserve_aspect_ratio=True):
 img = image_from_data(data)
 if preserve_aspect_ratio:
  (scaled, nwidth, nheight) = fit_image(img.width(), img.height(), width, height)
  if scaled:
   img = img.scaled(nwidth, nheight, Qt.KeepAspectRatio, Qt.SmoothTransformation)
 elif ((img.width() != width) or (img.height() != height)):
  img = img.scaled(width, height, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
 fmt = (u'PNG' if as_png else u'JPEG')
 (w, h) = (img.width(), img.height())
 return (w, h, image_to_data(img, compression_quality=compression_quality, fmt=fmt))

def scale_image ( data , width = 60 , height = 80 , compression_quality = 70 , as_png = False , preserve_aspect_ratio = True ) : img = image_from_data ( data ) if preserve_aspect_ratio : ( scaled , nwidth , nheight ) = fit_image ( img . width ( ) , img . height ( ) , width , height ) if scaled : img = img . scaled ( nwidth , nheight , Qt . KeepAspectRatio , Qt . SmoothTransformation ) elif ( ( img . width ( ) != width ) or ( img . height ( ) != height ) ) : img = img . scaled ( width , height , Qt . IgnoreAspectRatio , Qt . SmoothTransformation ) fmt = ( u'PNG' if as_png else u'JPEG' ) ( w , h ) = ( img . width ( ) , img . height ( ) ) return ( w , h , image_to_data ( img , compression_quality = compression_quality , fmt = fmt ) )
scale an image .