예제 #1
0
    def load(self, context, name=None, namespace=None, data=None):
        with photoshop.maintained_selection():
            layer = photoshop.import_smart_object(self.fname)

        self[:] = [layer]

        return photoshop.containerise(name, namespace, layer, context,
                                      self.__class__.__name__)
예제 #2
0
    def update(self, container, representation):
        layer = container.pop("layer")

        with photoshop.maintained_selection():
            photoshop.replace_smart_object(
                layer, api.get_representation_path(representation))

        photoshop.imprint(layer,
                          {"representation": str(representation["_id"])})
예제 #3
0
    def load(self, context, name=None, namespace=None, data=None):
        layer_name = self._get_unique_layer_name(context["asset"]["name"],
                                                 name)
        with photoshop.maintained_selection():
            layer = stub.import_smart_object(self.fname, layer_name)

        self[:] = [layer]
        namespace = namespace or layer_name

        return photoshop.containerise(name, namespace, layer, context,
                                      self.__class__.__name__)
예제 #4
0
    def process(self, instance):

        staging_dir = self.staging_dir(instance)
        self.log.info("Outputting image to {}".format(staging_dir))

        # Perform extraction
        files = {}
        with photoshop.maintained_selection():
            self.log.info("Extracting %s" % str(list(instance)))
            with photoshop.maintained_visibility():
                # Hide all other layers.
                extract_ids = [
                    x.id for x in photoshop.get_layers_in_layers([instance[0]])
                ]
                for layer in photoshop.get_layers_in_document():
                    if layer.id not in extract_ids:
                        layer.Visible = False

                save_options = {}
                if "png" in self.formats:
                    save_options["png"] = photoshop.com_objects.PNGSaveOptions()
                if "jpg" in self.formats:
                    save_options["jpg"] = photoshop.com_objects.JPEGSaveOptions()

                file_basename = os.path.splitext(
                    photoshop.app().ActiveDocument.Name
                )[0]
                for extension, save_option in save_options.items():
                    _filename = "{}.{}".format(file_basename, extension)
                    files[extension] = _filename

                    full_filename = os.path.join(staging_dir, _filename)
                    photoshop.app().ActiveDocument.SaveAs(
                        full_filename, save_option, True
                    )

        representations = []
        for extension, filename in files.items():
            representations.append({
                "name": extension,
                "ext": extension,
                "files": filename,
                "stagingDir": staging_dir
            })
        instance.data["representations"] = representations
        instance.data["stagingDir"] = staging_dir

        self.log.info(f"Extracted {instance} to {staging_dir}")
예제 #5
0
    def process(self, instance):

        staging_dir = self.staging_dir(instance)
        self.log.info("Outputting image to {}".format(staging_dir))

        # Perform extraction
        stub = photoshop.stub()
        files = {}
        with photoshop.maintained_selection():
            self.log.info("Extracting %s" % str(list(instance)))
            with photoshop.maintained_visibility():
                # Hide all other layers.
                extract_ids = set([ll.id for ll in stub.
                                   get_layers_in_layers([instance[0]])])

                for layer in stub.get_layers():
                    # limit unnecessary calls to client
                    if layer.visible and layer.id not in extract_ids:
                        stub.set_visible(layer.id, False)

                save_options = []
                if "png" in self.formats:
                    save_options.append('png')
                if "jpg" in self.formats:
                    save_options.append('jpg')

                file_basename = os.path.splitext(
                    stub.get_active_document_name()
                )[0]
                for extension in save_options:
                    _filename = "{}.{}".format(file_basename, extension)
                    files[extension] = _filename

                    full_filename = os.path.join(staging_dir, _filename)
                    stub.saveAs(full_filename, extension, True)

        representations = []
        for extension, filename in files.items():
            representations.append({
                "name": extension,
                "ext": extension,
                "files": filename,
                "stagingDir": staging_dir
            })
        instance.data["representations"] = representations
        instance.data["stagingDir"] = staging_dir

        self.log.info(f"Extracted {instance} to {staging_dir}")
예제 #6
0
    def update(self, container, representation):
        """ Switch asset or change version """
        layer = container.pop("layer")

        context = representation.get("context", {})

        namespace_from_container = re.sub(r'_\d{3}$', '',
                                          container["namespace"])
        layer_name = "{}_{}".format(context["asset"], context["subset"])
        # switching assets
        if namespace_from_container != layer_name:
            layer_name = self._get_unique_layer_name(context["asset"],
                                                     context["subset"])
        else:  # switching version - keep same name
            layer_name = container["namespace"]

        path = api.get_representation_path(representation)
        with photoshop.maintained_selection():
            stub.replace_smart_object(layer, path, layer_name)

        stub.imprint(layer, {"representation": str(representation["_id"])})