def runTest(self): m = Image('http://img.plures.net/4577/38c5/e9b3/dadd/93dd/9182/23a2/5230.jpg') print m.getSize() print m.getMediaName() print m.getPath() print m.getFileType() print StringIO(m.thumbnail((150,150)))
def upload_media(self, insert_data, data): if (self.static_type not in self.upload_res_type) or not self.staticUrl: return; if self.upload_handler is None: self.upload_handler = getattr(uploader, self.static_type)(self.sync_profile) else: self.upload_handler.update(); images = data["images"] if len(images) == 0: return insert_data #download and get new name for img_url in images: image = Image(img_url) if image.fetched: image_hash, image_name = image.getMediaName() relative_path, abs_path = image.getPath(True) #相对路径 image_relative_path = os.path.join(relative_path, image_name) #绝对路径 用于保存图片以及上传 image_abs_path = os.path.join(abs_path, image_name) image.save(image_abs_path) #print image_abs_path, image_relative_path uploader.upload_image(self.upload_handler, image_abs_path, image_relative_path) for field in insert_data: data = insert_data[field] if data is not None: insert_data[field] = data.replace(img_url, urljoin(self.staticUrl, image_relative_path)) return insert_data
def upload_media(self, insert_data, data): if (self.static_type not in self.upload_res_type) or not self.staticUrl: return if self.upload_handler is None: self.upload_handler = getattr(uploader, self.static_type)(self.sync_profile) else: self.upload_handler.update() images = data["images"] if len(images) == 0: return insert_data #download and get new name for img_url in images: image = Image(img_url) if image.fetched: image_hash, image_name = image.getMediaName() relative_path, abs_path = image.getPath(True) #相对路径 image_relative_path = os.path.join(relative_path, image_name) #绝对路径 用于保存图片以及上传 image_abs_path = os.path.join(abs_path, image_name) image.save(image_abs_path) #async upload uploader.upload_image(self.upload_handler, image_abs_path, image_relative_path) for field in insert_data: data = insert_data[field] if data is not None: insert_data[field] = data.replace( img_url, urljoin(self.staticUrl, image_relative_path)) return insert_data
def runTest(self): m = Image( 'http://img.plures.net/4577/38c5/e9b3/dadd/93dd/9182/23a2/5230.jpg' ) print m.getSize() print m.getMediaName() print m.getPath() print m.getFileType() print StringIO(m.thumbnail((150, 150)))