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


Python PythonMagick.Image类代码示例

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


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

示例1: get

 def get(self):
     self.set_header("Content-Type", "image/jpeg")
     image = Image("../image.jpg")
     image.resize(Geometry(100, 100))
     blob = Blob()
     image.write(blob)
     self.write(blob.data)
开发者ID:martinciu,项目名称:thumbnails,代码行数:7,代码来源:server.py

示例2: guardar_img

    def guardar_img(self, widget, string, img):
        filechooser = gtk.FileChooserDialog("Guardar Imagen", None, gtk.FILE_CHOOSER_ACTION_SAVE,
                                            (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        filechooser.set_default_response(gtk.RESPONSE_OK)
        filechooser.set_current_name(img.split("/")[3])
        filter = gtk.FileFilter()
        filter.set_name("Todos los archivos")
        filter.add_pattern("*")
        filechooser.add_filter(filter)
        filter = gtk.FileFilter()
        filter.set_name("Imágenes")
        filter.add_mime_type("image/png")
        filter.add_mime_type("image/jpeg")
        filter.add_mime_type("image/gif")
        filter.add_pattern("*.png")
        filter.add_pattern("*.jpg")
        filter.add_pattern("*.gif")
        filter.add_pattern("*.tif")
        filter.add_pattern("*.xpm")
        filechooser.add_filter(filter)

        respuesta = filechooser.run()

        if respuesta == gtk.RESPONSE_OK:
            try:
                fimg = Image(img)
                fimg.write(filechooser.get_filename())
                filechooser.destroy()
            except:
                pass
        else:
            filechooser.destroy()
开发者ID:jbnkuma,项目名称:remote_screenshot,代码行数:32,代码来源:visor.py

示例3: finish_response

    def finish_response(self, app_iter):
        if not self.scale:
            self.start_response(self.status, self.headers)
            self.output = app_iter
            return

        CONTENT_LENGTH.delete(self.headers)
        inBuffer = StringIO()
        try:
            for s in app_iter:
                self.logger.debug("Writing %d bytes into image buffer." % len(s))
                inBuffer.write(s)
        finally:
            if hasattr(app_iter, 'close'):
                app_iter.close()

        rawImg = Blob()
        rawImg.data = inBuffer.getvalue()
        inBuffer.close()
        image = Image(rawImg)
        self.logger.debug("Scaling image to %s" % self.scaled_size)
        image.scale(self.scaled_size[0])
        image.write(self.outbuffer)

        content_length = self.outbuffer.length()
        CONTENT_LENGTH.update(self.headers, content_length)
        CACHE_CONTROL.update(self.headers, s_maxage=CACHE_CONTROL.ONE_HOUR)
        self.start_response(self.status, self.headers)
开发者ID:bhagemeier,项目名称:swift-image-scaling,代码行数:28,代码来源:image_scaler.py

示例4: _CropGeometry

    def _CropGeometry(self, geometry):
        if not self._map_image:
            self._GenerateImage()

        image = Image(self._map_image)
        image.crop(geometry)

        return image
开发者ID:rodrigoac,项目名称:IBGETools,代码行数:8,代码来源:Map.py

示例5: thumbnail

    def thumbnail(self, infile, outfile, size, quality, no_upscale=False):
        #image = Image(infile)
        #image.resize(size)
        #image.write(outfile)

        quality = str(quality)
        if infile.endswith('.gif') or no_upscale:
            size = size+'>'
        resize = run(['/usr/bin/convert', '-interlace', "Plane", '-quality', quality, '-strip',  '-thumbnail', size, infile, outfile])
        image = Image(outfile)

        return { 'width': image.size().width(), \
                 'height': image.size().height() }
开发者ID:abach,项目名称:photongx,代码行数:13,代码来源:worker.py

示例6: manipula_img

 def manipula_img(self, img_r, nmsuc):
     """Procesa la imagen adquirida en formato xwd y la trasforma en jpg"""
     image_final = self.dir_tmp + nmsuc + ".jpg"
     contador = 0
     if path.exists(image_final):
         contador += 1
         image_final = self.dir_tmp + nmsuc + "_" + str(contador) + ".jpg"
         if path.exists(image_final):
             image_final = self.comprueba_nombre(image_final, nmsuc)
     img = Image(img_r)
     img.scale("1024x768")
     img.write(image_final)
     exe(image_final, nmsuc)
开发者ID:jbnkuma,项目名称:remote_screenshot,代码行数:13,代码来源:capturescreen_puesto.py

示例7: thumb

    def thumb(self, req):
        if self.mime_type.startswith('image') \
                and guess_extension(self.mime_type) in _image_exts:

            file_path = req.cfg.attachments_path + '/' + self.webname()
            img = Image(file_path.encode('utf-8'))

            width, height = req.cfg.attachments_thumb_size.get()
            img.scale(Geometry(width, height))

            thumb_path = req.cfg.attachments_thumb_path + '/' + self.webname()
            if not exists(dirname(thumb_path)):
                makedirs(dirname(thumb_path))
            img.write(thumb_path.encode('utf-8'))
开发者ID:ondratu,项目名称:morias,代码行数:14,代码来源:attachments.py

示例8: _ps2png

    def _ps2png(self, filename, relative):
        "Try to converts bands.ps -> bands.png and returns absolute filename"
        try:
            pspath  = self.bandsPS()
            pngpath = os.path.join(self._resultPath.localPath(), PNGBAND)   # Absolute

            # Rotate 90 degrees and convert .ps -> .png
            from PythonMagick import Image
            img     = Image(pspath)
            img.rotate(90)          # For some reason plotband.x rotates image
            img.write(pngpath)      # Write to .png file

            fpngpath = os.path.join(self._resultPath.localPath(relative), PNGBAND) # Format dependent
            return fpngpath         # If success, return path to .png file
        except:
            return None
开发者ID:danse-inelastic,项目名称:vnf,代码行数:16,代码来源:plotbandresult.py

示例9: main

def main():
    # os.environ["MAGICK_HOME"] = r"path_to_ImageMagick"

    if len(sys.argv) == 1:
        dirpath = '.'
    else:
        dirpath = sys.argv[1]

    temp_dir = os.path.join(dirpath, '.temp')
    if not os.path.exists(temp_dir):
        os.mkdir(temp_dir)

    for file_name in os.listdir(dirpath):
        if not os.path.isfile(file_name) or not file_name.endswith('.pdf'):
            continue
        print('Converting file {} ...'.format(file_name))
        in_path = os.path.join(dirpath, file_name)
        with open(in_path, 'rb') as handle:
            inputpdf = PdfFileReader(handle)
            for i in xrange(inputpdf.numPages):
                outputpdf = PdfFileWriter()
                outputpdf.addPage(inputpdf.getPage(i))
                new_file_name = file_name.replace('.pdf', '') + '_{}.pdf'.format(i)
                new_in_path = os.path.join(temp_dir, new_file_name)
                with open(new_in_path, 'wb') as handle:
                    outputpdf.write(handle)

                output_file_name = new_file_name.replace('.pdf', '.jpeg')
                output_path = os.path.join(dirpath, output_file_name)
                p = Image()
                p.density('1080')
                p.read(os.path.abspath(new_in_path))
                p.write(os.path.abspath(output_path))
                os.remove(new_in_path)
        os.rmdir(temp_dir)
开发者ID:SimoV8,项目名称:pdf2image,代码行数:35,代码来源:pdf2image.py

示例10: bmp_or_jpg_to_pdf

 def bmp_or_jpg_to_pdf(list_of_file_paths, destination_directory, delete_source=False):
     operation_result = {}
     invalid_file_paths = []
     for files in list_of_file_paths:
         if os.path.exists(files):
             continue
         else:
             invalid_file_paths.append(files)
             list_of_file_paths.remove(files)
     for files in list_of_file_paths:
         image = PyImage()
         image.density("600")
         image.read(files)
         file_name = os.path.basename(files)
         name, ext = os.path.splitext(file_name)
         file_name_at_destination = os.path.join(destination_directory, name + ".pdf")
         image.write(file_name_at_destination)
     if delete_source is True:
         for files in list_of_file_paths:
             os.remove(files)
     if not invalid_file_paths:
         operation_result.update({"code": 0, "invalid_file_paths": "None"})
     else:
         invalid_files = ",".join(list_of_file_paths)
         operation_result.update({"code": 1, "invalid_file_paths": invalid_files})
     return operation_result
开发者ID:gauravp19,项目名称:Image-Conversion,代码行数:26,代码来源:ImageOperations.py

示例11: __init__

    def __init__(self, filename, i):
        self.image = Image()
        self.image.density('%d' % DENSITY)
        self.image.read('%s[%d]' % (filename, i))

        temp = tempfile.NamedTemporaryFile(suffix='.png')
        self.image.write(temp.name)
        self.pimage = pygame.image.load(temp.name)
        temp.close()
开发者ID:DLu,项目名称:scanned_exam_grader,代码行数:9,代码来源:answersheet.py

示例12: EncodeImg

def EncodeImg(Ii,pathin,pathout):
	""" fonction qui encode un png en base64 
	Ii : l'element xml ou il faut la brancher
	pathin et pathout les chemins des fichiers """
 	print Ii.attrib
	ext=Ii.attrib['ext']	
	img_name  = Ii.attrib['name']
 	pathF=Ii.attrib['pathF'] +'/'
	
	# si ce n'est pas du png on converti en png
	if (Ii.attrib['ext'] != 'png'):
		im = Image(pathF+ img_name +'.' + ext)
		img_name = img_name + ".png"
		im.write(pathF + img_name)
	else:
            img_name  = Ii.attrib['name']+'.'+ext
      
	img_file = open(	pathF + img_name, "rb") 
	Ii.attrib.update({'name':img_name,'path':'/','encoding':"base64"})
	Ii.text=base64.b64encode(img_file.read())     
开发者ID:nennigb,项目名称:amc2moodle,代码行数:20,代码来源:grading.py

示例13: convert_images_to_tiff

    def convert_images_to_tiff(list_of_file_paths, destination_directory, delete_source=False):
        """
        This static method deals with converting images of type .bmp, .jpg, .png to .tiff.
        This method takes parameters they are as follows:
        :param list_of_file_paths: Example: ['C:\Users\gpatil\Desktop\image1.png', 'C:\Users\gpatilSample\image2.png']
        :param destination_directory: The directory where the converted images are to be saved
        :param delete_source: If the delete_source param is set to True then the original files will get erased after
               the conversion is completed
        :return: returns a dictionary containing the invalid file paths passed to the method (if any) and a result_code
                 that has the value 0 or 1 based on the success and failure of the operation
        """
        result_dictionary = {}
        invalid_files_list = []
        for paths in list_of_file_paths:
            if os.path.exists(paths) is False:
                invalid_files_list.append(paths)
                continue
            image_object = Image(paths)
            file_name = os.path.basename(paths)
            name, ext = os.path.splitext(file_name)
            print "Converting Image " + str(file_name) + " to TIFF"
            image_object.write(os.path.join(destination_directory, name + ".tiff"))
            print "Conversion Complete"
        if not invalid_files_list:
            result_dictionary.update({"result_code": 0, "invalid_file_paths": "None"})
        else:
            csv_list_of_invalid_file_paths = ",".join(invalid_files_list)
            result_dictionary.update({"result_code": -1, "invalid_file_paths": csv_list_of_invalid_file_paths})
            print "Following files at paths could not be converted"
            for files in invalid_files_list:
                print files

        if delete_source is True:
            for paths in list_of_file_paths:
                if os.path.exists(paths) is False:
                    invalid_files_list.append(paths)
                    continue
                os.remove(paths)
            print "Legacy files deleted successfully"
        return result_dictionary
开发者ID:gauravp19,项目名称:Python-TIFF-Convert-Compress-Rotate-Merge-using-IrfanView-and-PythonMagick,代码行数:40,代码来源:Operations-on-TIFF.py

示例14: rsr2png

def rsr2png(rsrfile):
	rsr2pct(rsrfile)
	pictfile = os.path.splitext(rsrfile)[0]+".pct"
	try:
		thumb = Image(str(pictfile))
	except:
		print pictfile
		raise
	thumb.opacity(100)
	thumb.scale(91,91)
	thumb.write(str(os.path.splitext(rsrfile)[0]+".png"))
开发者ID:netpete,项目名称:dmilo,代码行数:11,代码来源:rsrconvert.py

示例15: compress_tiff_files

 def compress_tiff_files(list_of_file_paths, destination_directory, delete_source=False):
     """
     This method deals with compression of TIFF images. ZipCompression algorithm is used from the PythonMagick
     library.
     :param list_of_file_paths: ['C:\Users\gpatil\Desktop\image1.tiff', 'C:\Users\gpatilSample\image2.tiff']
     :param destination_directory: 'C:\Users\gpatil\Desktop\image1.png'
     :param delete_source: If the delete_source param is set to True then the original files will get
            erased after they are compressed
     :return: returns a dictionary containing the invalid file paths passed to the method (if any) and a result_code
              that has the value 0 or 1 based on the success and failure of the operation
     """
     result_dictionary = {}
     invalid_files_list = []
     for paths in list_of_file_paths:
         if os.path.exists(paths) is False:
             invalid_files_list.append(paths)
             continue
         image_object = Image(paths)
         image_object.compressType(CompressionType.ZipCompression)
         file_name = os.path.basename(paths)
         print "Compressing Image" + str(file_name) + " to TIFF"
         image_object.write(os.path.join(destination_directory, file_name))
         print "Compression Complete"
     if not invalid_files_list:
         result_dictionary.update({"result_code": 0, "invalid_file_paths": "None"})
     else:
         csv_list_of_invalid_file_paths = ",".join(invalid_files_list)
         result_dictionary.update({"result_code": -1, "invalid_file_paths": csv_list_of_invalid_file_paths})
         print "Following files at paths could not be compressed"
         for files in invalid_files_list:
             print files
     if delete_source is True:
         for files in list_of_file_paths:
             if os.path.exists(paths) is False:
                 invalid_files_list.append(paths)
                 continue
             os.remove(files)
             print "Legacy files deleted successfully"
     return result_dictionary
开发者ID:gauravp19,项目名称:Python-TIFF-Convert-Compress-Rotate-Merge-using-IrfanView-and-PythonMagick,代码行数:39,代码来源:Operations-on-TIFF.py


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