def perspective(image, width, height, skew_x, skew_y, offset_x, offset_y, left, top, back_color, opacity, resample, crop, transpose): image = imtools.convert_safe_mode(image) if transpose == 'NONE': transpose = None else: transpose = getattr(Image, transpose) image = image.transpose(imtools.get_reverse_transposition(transpose)) if opacity != 100 or back_color != '#000000': image = image.convert('RGBA') if width != 0: width = 1 / width if height != 0: height = 1 / height offset_x = offset_x * width offset_y = offset_y * height skew_x = math.tan(r(skew_x)) skew_y = math.tan(r(skew_y)) matrix = (width, skew_x, offset_x, skew_y, height, offset_y, left, top) perspectived = image.transform(image.size, Image.PERSPECTIVE, matrix, resample) result = imtools.fill_background_color( perspectived, HTMLColorToRGBA(back_color, (255 * opacity) / 100)) if crop: result = imtools.auto_crop(result) if not (transpose is None): result = result.transpose(transpose) return result
def apply(self, photo, setting, cache): info = photo.info w, h = info['size'] values = self.values(info, pixel_fields={ 'Render Width': w, 'Render Height': h, 'Box Depth': h, }) mode = info['mode'] if mode in ('RGBA', 'LA') or mode == 'P' and 'transparency' in info: values['input_image_1'] = 'file_in.png' mode = 'RGBA' else: values['input_image_1'] = 'file_in.bmp' mode = 'RGB' values['render_path'] = 'file_out.png' command = self.construct_command(values) #we need to create our temp folder explicitly as #blender renders to a folder and not to a filename output_dir = tempfile.mkdtemp() output_filename = os.path.join(output_dir, '0001.png') photo.call(command, output_filename=output_filename, mode=mode) #remove temp folder (should be done by same process) shutil.rmtree(output_dir) if self.get_field('Auto Crop', info): layer = photo.get_layer() layer.image = imtools.auto_crop(layer.image) return photo
def perspective(image, width, height, skew_x, skew_y, offset_x, offset_y, left, top, back_color, opacity, resample, crop, transpose): image = imtools.convert_safe_mode(image) if transpose == 'NONE': transpose = None else: transpose = getattr(Image, transpose) image = image.transpose(imtools.get_reverse_transposition(transpose)) if opacity != 100 or back_color != '#000000': image = image.convert('RGBA') if width != 0: width = 1 / width if height != 0: height = 1 / height offset_x = offset_x * width offset_y = offset_y * height skew_x = math.tan(r(skew_x)) skew_y = math.tan(r(skew_y)) matrix = (width, skew_x, offset_x, skew_y, height, offset_y, left, top) perspectived = image.transform(image.size, Image.PERSPECTIVE, matrix, resample) result = imtools.fill_background_color(perspectived, HTMLColorToRGBA(back_color, (255 * opacity) / 100)) if crop: result = imtools.auto_crop(result) if not (transpose is None): result = result.transpose(transpose) return result
def apply(self, photo, setting, cache): info = photo.info w, h = info['size'] values = self.values(info, pixel_fields={ 'Render Width': w, 'Render Height': h, 'Box Depth': h, }) mode = info['mode'] if mode in ('RGBA', 'LA') or mode == 'P' and 'transparency' in info: values['filein'] = 'file_in.png' mode = 'RGBA' else: values['filein'] = 'file_in.bmp' mode = 'RGB' command = self.construct_command(values) #we need to create our temp folder explicitly as #blender renders to a folder and not to a filename output_dir = tempfile.mkdtemp() output_filename = os.path.join(output_dir, '0001.png') photo.call(command, output_filename=output_filename, mode=mode) #remove temp folder (should be done by same process) shutil.rmtree(output_dir) if self.get_field('Auto Crop', info): layer = photo.get_layer() layer.image = imtools.auto_crop(layer.image) return photo
def crop(image, mode=None, all=0, left=0, right=0, top=0, bottom=0): if mode == _t('Auto'): image = auto_crop(image) elif mode == _t('All'): image = ImageOps.crop(image, border=all) else: w, h = image.size box = (left, top, w - right, h - bottom) image = image.crop(box) return image
def crop(image, mode=None, all=0, left=0, right=0, top=0, bottom=0): if mode == _t('Auto'): image = auto_crop(image) elif mode == _t('All'): image = ImageOps.crop(image, border=all) else: w, h = image.size box = ( left, top, w - right, h - bottom) image = image.crop(box) return image