def add_image(self, album_id, imagename, title, comment, reduce_size=False, size=800, colors=False): mime = mimetypes.guess_type(imagename)[0] if mime in SUPPORTED_MIMES or mime in CONVERTED_MIMES: temp = None if reduce_size is True or colors is True or\ mime in CONVERTED_MIMES: pixbuf = GdkPixbuf.Pixbuf.new_from_file(imagename) temp = tempfile.mkstemp(suffix='.png', prefix='picapy_tmp', dir='/tmp')[1] if reduce_size is True: pixbuf = picasamod.scale_pixbuf(pixbuf, size) print('reduced size of %s' % temp) if colors is True: pixbuf = picasamod.grayscale_pixbuf(pixbuf) print(('reduced colors of %s' % temp)) pixbuf.savev(temp, 'png', [], []) print(('%s converted!' % temp)) imagename = temp ans = self.add_photo(album_id, afile=imagename, filename=title, caption=comment) print('The ans %s' % ans) if temp is not None and os.path.exists(temp): os.remove(temp) if ans: return ans return None
def on_button_clicked(self, widget, operation): if operation == "load-new-image": dialog = Gtk.FileChooserDialog( _("Select one images to upload to Picasa Web"), self, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK), ) dialog.set_default_response(Gtk.ResponseType.OK) filter = Gtk.FileFilter() filter.set_name(_("Imagenes")) filter.add_mime_type("image/png") filter.add_mime_type("image/jpeg") filter.add_mime_type("image/gif") filter.add_mime_type("image/x-ms-bmp") filter.add_mime_type("image/x-icon") filter.add_mime_type("image/tiff") filter.add_mime_type("image/x-photoshop") filter.add_mime_type("x-portable-pixmap") filter.add_pattern("*.png") filter.add_pattern("*.jpg") filter.add_pattern("*.gif") filter.add_pattern("*.bmp") filter.add_pattern("*.ico") filter.add_pattern("*.tiff") filter.add_pattern("*.psd") filter.add_pattern("*.ppm") dialog.add_filter(filter) preview = Gtk.Image() dialog.set_preview_widget(preview) dialog.connect("update-preview", self.update_preview_cb, preview) response = dialog.run() if response == Gtk.ResponseType.OK: self.filename = dialog.get_filename() f = open(self.filename, "rb") data = f.read() f.close() pbl = GdkPixbuf.PixbufLoader() pbl.write(data) pbuf = pbl.get_pixbuf() pbl.close() if pbuf is not None: self.aimage2.set_from_pixbuf(pbuf) dialog.destroy() elif operation == "rotate-left": pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: pixbuf = picasamod.rotate_pixbuf(pixbuf, 90) self.aimage2.set_from_pixbuf(pixbuf) elif operation == "rotate-right": pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: pixbuf = picasamod.rotate_pixbuf(pixbuf, 270) self.aimage2.set_from_pixbuf(pixbuf) elif operation == "flip-horizontal": pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: pixbuf = picasamod.flip_pixbuf(pixbuf, True) self.aimage2.set_from_pixbuf(pixbuf) elif operation == "flip-vertical": pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: pixbuf = picasamod.flip_pixbuf(pixbuf, False) self.aimage2.set_from_pixbuf(pixbuf) elif operation == "grayscale": pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: pixbuf = picasamod.grayscale_pixbuf(pixbuf) self.aimage2.set_from_pixbuf(pixbuf) elif operation == "instagram-sunset": pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: image = utils.pixbuf2image(pixbuf) filter = filters.CFilterSunset() new_image = filter.applyFilter(image) pixbuf = utils.image2pixbuf(new_image) self.aimage2.set_from_pixbuf(pixbuf) elif operation == "instagram-colorful": pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: image = utils.pixbuf2image(pixbuf) filter = filters.CFilterColorful() new_image = filter.applyFilter(image) pixbuf = utils.image2pixbuf(new_image) self.aimage2.set_from_pixbuf(pixbuf) elif operation == "instagram-groovy": pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: image = utils.pixbuf2image(pixbuf) filter = filters.CFilterGroovy() new_image = filter.applyFilter(image) pixbuf = utils.image2pixbuf(new_image) self.aimage2.set_from_pixbuf(pixbuf) else: pass
def on_button_clicked(self, widget, operation): if operation == 'load-new-image': dialog = Gtk.FileChooserDialog( _('Select one images to upload to Picasa Web'), self, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) dialog.set_default_response(Gtk.ResponseType.OK) filter = Gtk.FileFilter() filter.set_name(_('Imagenes')) filter.add_mime_type('image/png') filter.add_mime_type('image/jpeg') filter.add_mime_type('image/gif') filter.add_mime_type('image/x-ms-bmp') filter.add_mime_type('image/x-icon') filter.add_mime_type('image/tiff') filter.add_mime_type('image/x-photoshop') filter.add_mime_type('x-portable-pixmap') filter.add_pattern('*.png') filter.add_pattern('*.jpg') filter.add_pattern('*.gif') filter.add_pattern('*.bmp') filter.add_pattern('*.ico') filter.add_pattern('*.tiff') filter.add_pattern('*.psd') filter.add_pattern('*.ppm') dialog.add_filter(filter) preview = Gtk.Image() dialog.set_preview_widget(preview) dialog.connect('update-preview', self.update_preview_cb, preview) response = dialog.run() if response == Gtk.ResponseType.OK: self.filename = dialog.get_filename() f = open(self.filename, 'rb') data = f.read() f.close() pbl = GdkPixbuf.PixbufLoader() pbl.write(data) pbuf = pbl.get_pixbuf() pbl.close() if pbuf is not None: self.aimage2.set_from_pixbuf(pbuf) dialog.destroy() elif operation == 'rotate-left': pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: pixbuf = picasamod.rotate_pixbuf(pixbuf, 90) self.aimage2.set_from_pixbuf(pixbuf) elif operation == 'rotate-right': pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: pixbuf = picasamod.rotate_pixbuf(pixbuf, 270) self.aimage2.set_from_pixbuf(pixbuf) elif operation == 'flip-horizontal': pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: pixbuf = picasamod.flip_pixbuf(pixbuf, True) self.aimage2.set_from_pixbuf(pixbuf) elif operation == 'flip-vertical': pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: pixbuf = picasamod.flip_pixbuf(pixbuf, False) self.aimage2.set_from_pixbuf(pixbuf) elif operation == 'grayscale': pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: pixbuf = picasamod.grayscale_pixbuf(pixbuf) self.aimage2.set_from_pixbuf(pixbuf) elif operation == 'instagram-sunset': pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: image = utils.pixbuf2image(pixbuf) filter = filters.CFilterSunset() new_image = filter.applyFilter(image) pixbuf = utils.image2pixbuf(new_image) self.aimage2.set_from_pixbuf(pixbuf) elif operation == 'instagram-colorful': pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: image = utils.pixbuf2image(pixbuf) filter = filters.CFilterColorful() new_image = filter.applyFilter(image) pixbuf = utils.image2pixbuf(new_image) self.aimage2.set_from_pixbuf(pixbuf) elif operation == 'instagram-groovy': pixbuf = self.aimage2.get_pixbuf() if pixbuf is not None: image = utils.pixbuf2image(pixbuf) filter = filters.CFilterGroovy() new_image = filter.applyFilter(image) pixbuf = utils.image2pixbuf(new_image) self.aimage2.set_from_pixbuf(pixbuf) else: pass