SmartObjectLayer the size is changed after setContents and updateModifiedContent

this is my code:

LinkDataSource contentsSource = layer.getContentsSource();
contentsSource.setFileType(fileType);
layer.setContents(imageBytes);
layer.updateModifiedContent();

psd file SmartObjectLayer exists Puppet Warp ,Is this the reason? by the way i use Aspose.PSD for Java,how can i deal with SmartObjectLayer and Puppet Warp,Please tell me how to deal with it Thank you。

@wailau

When working with a SmartObjectLayer in Aspose.PSD, if you notice that the size changes after calling setContents and updateModifiedContent, it could indeed be related to the Puppet Warp feature applied to the smart object. Puppet Warp allows for non-destructive transformations, which can affect the dimensions of the layer when you modify its contents.

To handle this situation, you can follow these steps:

  1. Check Warp Settings: Ensure that the WarpSettings of the SmartObjectLayer are correctly configured. You can access and modify these settings using the getWarpSettings() and setWarpSettings(WarpSettings value) methods.

  2. Update the Layer: After setting the new contents, make sure to call updateModifiedContent() to refresh the layer’s cache. This is crucial for the changes to take effect properly.

  3. Use the Correct Resolution: If the new content has a different resolution than the original, it may lead to unexpected size changes. You can specify the resolution when replacing the contents using the ReplaceContents method, which allows you to pass a ResolutionSetting parameter.

Here is a sample code snippet demonstrating how to replace the contents of a SmartObjectLayer while considering the resolution:

using Aspose.PSD.FileFormats.Psd;
using Aspose.PSD.FileFormats.Psd.Layers.SmartObjects;
using Aspose.PSD.ImageOptions;

// Load the PSD file
using (PsdImage psd = (PsdImage)Image.Load("path/to/your/file.psd"))
{
    foreach (var layer in psd.Layers)
    {
        if (layer is SmartObjectLayer smartObjectLayer)
        {
            // Set new contents
            smartObjectLayer.ReplaceContents("path/to/new/content.jpg", new ResolutionSetting(300, 300)); // Specify resolution
            smartObjectLayer.UpdateModifiedContent(); // Update the layer
        }
    }
    psd.Save("path/to/output/file.psd");
}

By following these steps, you should be able to manage the size changes effectively when dealing with SmartObjectLayer and Puppet Warp. If you continue to experience issues, consider checking the specific warp settings or the properties of the new content being applied.

my aspose-psd for java version is 23.6,also i try version 25.2 The problem still exists

This is my psd file https://www.qpmarketnetwork.com/file/file/e2b6027e8769f19baccea84184182f10.psd

@wailau
Could you please provide full code that was used for opening of Psd Image. Also, code of loading image for the replacement is also missed.

At this moment, Aspose.PSD doesn’t support Pupper Warp, but the issue can be not only warp, but also in the way of preparing data.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PSDNET-2367

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like

Thank you very much for your answer,Below is my related code.

Load psd file code

        // opening Psd Image
        String psdPath = FilenameUtils.concat(fileProcessor.getPsdDir(), templateUrl);
//        InputStream inputStream = fileProcessor.getPsdInputStreamByUrl(templateUrl);
        try (PsdImage templateFile = (PsdImage) PsdImage.load(psdPath)) {

            log.info("Load MockupTemplate {} to PsdImage, cost {} ms", psdPath, System.currentTimeMillis() - start);

            Map<String, LayerPlaceholder> layerPlaceholderMap = toMap(layerPlaceholders);
            Map<String, LayerProcessParams> layerProcessParamsMap = toMap(layerProcessParams);

            start = System.currentTimeMillis();
            process(templateFile, layerPlaceholderMap, layerProcessParamsMap);
            log.info("process MockupTemplate, cost {} ms", System.currentTimeMillis() - start);

            FileUploadJsonResponse result = output(templateFile, request);
            response.setFileUrl(result.getData().getUrl());
            response.setFormat(result.getData().getFormat());
            response.setFileName(result.getData().getFileName());

        } catch (Exception e) {
            throw BusinessExceptionBuilder.of(610004, ImmutableMap.of("templateUrl", psdPath, "message", e.getMessage()));
        }

code of loading image for the replacement

SmartObjectLayer layer = LayerPlaceholderProcessor.obtainLayer(template, spec.getCode(), SmartObjectLayer.class);
        byte[] imageBytes;
        String defaultFileType = commonPropertiesService.getKeyValueAndApplicationModeForNoException(FileProcessor.DEFAULT_FILE_TYPE_KEY);
        String fileType = StringUtils.isBlank(defaultFileType) ? "jpg" : defaultFileType;
        try {
            List<ImagePipeline> imagePipeline = params.getImagePipeline();
            if (CollectionUtils.isNotEmpty(imagePipeline)) {
                ByteInfo byteInfo = buildPipeline(params);
                imageBytes = byteInfo.getBytes();
                fileType = byteInfo.getFormat();
            } else {
                if (fileProcessor.isImage(params.getImageUrl())) {
                    fileType = FilenameUtils.getExtension(params.getImageUrl());
                }
                imageBytes = fileProcessor.getBytesByUrl(params.getImageUrl(), fileType);
            }
        } catch (IOException e) {
            throw BusinessExceptionBuilder.of(610003, ImmutableMap.of("layerCode", params.getCode(), "imageUrl", params.getImageUrl(), "message", e.getMessage()));
        }
        if (imageBytes != null && imageBytes.length > 0) {
            LinkDataSource contentsSource = layer.getContentsSource();
            contentsSource.setFileType(fileType);
            layer.setContents(imageBytes);
            layer.updateModifiedContent();
        }

when my code run in

layer.updateModifiedContent();

I find the SmartObjectLayer`s height and width is change

    int height = layer.getHeight();
    int width = layer.getWidth();

alse the Pupper Warp size change with the SmartObjectLayer

I try Pictures of different pixels the SmartObjectLayer The size will be changed,

height * width 
image:500 * 500
Before rendering                                 After rendering
smartObject1:  326 * 1115                           396 * 3575
smartObject3:  149 * 1115                           460 * 3290

height * width 
image:2000 * 2000
Before rendering                           After rendering
smartObject1:  326 * 1115                    1189 * 10726
smartObject3:  149 * 1115                    1381 * 9870

height * width 
image:100 * 100
Before rendering                            After rendering
smartObject1:  326 * 1115                     59 * 536
smartObject3:  149 * 1115                     69 * 494

height * width 
image:326 * 1115
Before rendering                           After rendering
smartObject1:  326 * 1115                    194 * 1748
smartObject3:  149 * 1115                    225 * 1609

height * width 
image:149 * 1115
Before rendering                               After rendering
smartObject1:  326 * 1115                    89 * 799   
smartObject3:  149 * 1115                    103 * 735 


height  * width 
image:650 * 1500
Before rendering                                  After rendering
smartObject1:  326 * 1115                    386 * 3486
smartObject3:  149 * 1115                    449 * 3208

By the way my Java version is 8

@wailau
Thank you. I’ve updated your ticket and created Java ticket also, but on the release its ID can be changed, it’s easier to track its status with .NET Id, once it will be fixed, it will be also fixed in Java release.

We will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PSDJAVA-713

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like