예제 #1
0
def psd_traverse(layers):
    for layer in layers:
        layer['blend_mode'] = str(layer['blend_mode'])[2:-1]


        timestamp = str(int(time.time()))
        layer_image_path = path + timestamp + ".png"

        if layer['mask_data']:
            layer['mask_data'] = {
                'top': layer['mask_data'].top,
                'left': layer['mask_data'].left,
                'bottom': layer['mask_data'].bottom,
                "right": layer['mask_data'].right,
                'background_color': layer['mask_data'].background_color,
                'flags': {'pos_relative_to_layer': layer['mask_data'].flags.pos_relative_to_layer,
                    'mask_disabled': layer['mask_data'].flags.mask_disabled,
                    'invert_mask': layer['mask_data'].flags.invert_mask,
                    'user_mask_from_render': layer['mask_data'].flags.user_mask_from_render,
                    'parameters_applied': layer['mask_data'].flags.parameters_applied, }

                }

        while os.path.isfile(layer_image_path):
            layer_image_path = path + timestamp + str(random.randint(0, 1000)) + ".png"

        try:
            layer_image = pil_support.extract_layer_image(raw_data, layer['index'])
            layer_image.save(layer_image_path)

            with open(layer_image_path, "rb") as image_file:
                encoded_string = base64.b64encode(image_file.read())
                layer['image'] = str(encoded_string)[2:-1]
                
            os.remove(layer_image_path)
        except:
            pass

        if 'layers' in layer:
            psd_traverse(layer['layers'])
        else:
            pass
예제 #2
0
 def _layer_as_PIL(self, index):
     return pil_support.extract_layer_image(self.decoded_data, index)
예제 #3
0
 def _layer_as_PIL(self, index):
     return pil_support.extract_layer_image(self.decoded_data, index)