Saving Image is taking too much of time

log.info("Saving Creatives with name " + loggerName);
        pngOptions.setColorType(PngColorType.TruecolorWithAlpha);
        psdImage.resize(720,1280);
        psdImage.save(new FileOutputStream(outputFileName));
        psdImage.save(new FileOutputStream(outputFileName), pngOptions);
        //psdImage.save(new FileOutputStream(dataDir + appModel.getTitle()+ i +".jpeg"), jpegOptions);
        log.info("Creatives Build Successfully.");

saving image is taking around 30 sec. Is there any way to reduce this time?

Attaching Log for more clarification:
2021-03-24 10:53:52.511 INFO 17424 — [nio-8080-exec-4] Service.PlaystoreService : Saving Creatives with name Yelp Food, Delivery & Services3(5).png
Font cache was not available for : Poppins-Medium
Font cache was not available for : Poppins-Medium
Font cache was not available for : Poppins-Medium
Font cache was not available for : Poppins-Medium
Font cache was not available for : Poppins-Light
Font cache was not available for : Poppins-SemiBold
Font cache was not available for : Poppins-Light
2021-03-24 10:54:21.726 INFO 17424 — [nio-8080-exec-4] Service.PlaystoreService : Creatives Build Successfully.

@mail9deep

You may please share the source image with us so that we could investigate on our end to assess whether the performance can be improved for it or not.

Hi @mudassir.fayyaz,

Its generally taking for all the images around 30 seconds.

@mail9deep

As requested earlier, please share the requested information so that we may help you further in this regard.

Hi @mudassir.fayyaz

Attaching link of psd File: “Ad-format-final-1.psd - Google Drive
Also, I am replacing 3 images with the link of the following image provided below and saving that is taking too much of time.
“iconUrl”:“https://is5-ssl.mzstatic.com/image/thumb/Purple114/v4/25/68/3f/25683f90-1035-60fd-491d-bcd9f4908391/source/100x100bb.jpg”,
“screenshots”: “https://is2-ssl.mzstatic.com/image/thumb/Purple114/v4/bf/f5/d2/bff5d268-e148-2108-0e25-fae3ff2c6648/mzl.motjgfyx.jpg/392x696bb.jpg”,

Let me know if you want code also.

@mail9deep

Can you please confirm, if you are simply loading and saving PSD file that is taking time to save or you are performing any operating on file before saving. As in your code, there is a partial sample code of saving file only.

Hi @mudassir.fayyaz,

I am replacing images as well as text to psd file as per my requirements. If you want i can share my code for whole things.

@mail9deep

Please share the working sample code along with source files, obtained output and desired output file.

Hi @mudassir.fayyaz,

public ResponseEntity buildCreatives(AppModel appModel, PlaystoreBody playstoreBody,int i) throws IOException {
//TODO: Need to give proper path.
log.info(“Starting building creatives.”);
String dataDir = getDataDir();

    // Initialize License Instance
    License license = new License();
    // Call setLicense method to set license
    license.setLicense(dataDir +"Aspose.PSD.Java.lic");


    PngOptions pngOptions = new PngOptions();
    //pngOptions.setDefaultReplacementFont("Calibri Italic");
    //JpegOptions jpegOptions = new JpegOptions();
    //jpegOptions.setDefaultReplacementFont("Calibri Italic");
    PsdImage psdImage = (PsdImage) Image.load(dataDir + playstoreBody.getTemplateName());

    Map<String,Layer> layerMap = findLayer(psdImage);

    Layer layerToReplace = layerMap.get("logo");//findLayer("App Icon Layer", psdImage);

    //Setting Playstorename Name
    Layer playstoreName = layerMap.get("appstoreName");//findLayer("Playstore name",psdImage);
    if(null != playstoreName){
        TextLayer playStoreTextLayer = (TextLayer) playstoreName;
        String playstrName= appModel.getPlaystorename().substring(0,1).toUpperCase().concat(appModel.getPlaystorename().substring(1));
        playStoreTextLayer.updateText(playstrName,new Point(1300,4300),playStoreTextLayer.getFont().getSize()+5);
    }

    //Setting CTA Text

    Layer CTALayer = layerMap.get("ctaText");//findLayer("Install CTA _text",psdImage);
    if(null != CTALayer && CTALayer instanceof TextLayer){
        TextLayer txtlyr = (TextLayer) CTALayer;
        String innerText = txtlyr.getInnerText();
        if(innerText.length() <= playstoreBody.getCtaText().length()){
            //TODO: need to throw an exception for length of cta text;
            return customRestExceptionHandler.handleCtaError(HttpStatus.BAD_REQUEST,"Please provide proper length of CTA Text","CTA length too Long");
        }
        Color color = Color.fromArgb(playstoreBody.getCtaTextColorList().get(0),playstoreBody.getCtaTextColorList().get(1),playstoreBody.getCtaTextColorList().get(2));//getColor(playstoreBody.getCtaTextColor());
        if(!color.equals(Color.getEmpty())){
            txtlyr.updateText(playstoreBody.getCtaText(),txtlyr.getFont().getSize() + 10,color);
        }else {
            txtlyr.updateText(playstoreBody.getCtaText(), txtlyr.getFont().getSize() + 10);
        }
    }

    //setting developed by
    Layer developerLayer = layerMap.get("developerName");//findLayer("Developed by: John Doe",psdImage);
    if(null != developerLayer && developerLayer instanceof TextLayer){
        TextLayer developerTextLayer = (TextLayer) developerLayer;
        if(appModel.getPlaystorename().equalsIgnoreCase("zhushou")){
            developerTextLayer.updateText(appModel.getAuthor());
        }else {
            developerTextLayer.updateText("Developed By:" + appModel.getAuthor());
        }
    }

    //Setting app name:
    Layer appNameLayer = layerMap.get("appName");//findLayer("App name something",psdImage);
    if(null != appNameLayer && appNameLayer instanceof TextLayer){
        TextLayer appNameTextLayer = (TextLayer) appNameLayer;
        List<String> titleList = getTitleList(appModel.getTitle());
        String appName="";
        int count = 0;
        for(String word : titleList){
            count++;
            if(count%2==0){
                appName = appName +" "+ word + "\r";
            }else {
                appName = appName +" "+ word;
            }
        }
        if(titleList.size() == 3){
            appName = appName + "\r";
        }
        appNameTextLayer.updateText(appName,appNameTextLayer.getFont().getSize()-16);
    }


    //Replacing Logo of app.
    if (null != layerToReplace) {
        URL url = new URL(appModel.getIconUrl());
        InputStream inputStream = url.openStream();
        //FileInputStream inputStream = new FileInputStream(dataDir + playstoreBody.getNewImageName());
        //Image image = (Image) ImageIO.read(inputStream);
        Layer newLayer = new Layer(inputStream);
        Graphics graphics = new Graphics(layerToReplace);
        //graphics.clear(Color.getEmpty());
        graphics.drawImage(newLayer, new Rectangle(new Point(), new Size(Math.abs(layerToReplace.getWidth()), Math.abs(layerToReplace.getHeight()))));

    }

    //Adding screenshot:Base
    //Layer scrshotLayer = findLayer("app_screenshot_rectangle",psdImage);
    Layer scrshotLayer = layerMap.get("appImage");//findLayer("Base",psdImage);
    if (null != scrshotLayer) {
        log.info("Replacing Screenshot Image");
        URL url = new URL(appModel.getScreenshots()[i-1]);
        InputStream inputStream = url.openStream();
        BufferedImage image = ImageIO.read(url);
        //FileInputStream inputStream = new FileInputStream(dataDir + playstoreBody.getNewImageName());
        Layer newLayer = new Layer(inputStream);
        Graphics graphics = new Graphics(scrshotLayer);
        //graphics.clear(Color.getEmpty());
        Double aspectRatio = image.getWidth()/(double)image.getHeight();
        int height = (int)Math.round(scrshotLayer.getWidth()/aspectRatio);
        graphics.drawImage(newLayer, new Rectangle(new Point(), new Size(scrshotLayer.getWidth(), height)));
        log.info("Screenshot Image Replaced.");
    }

    //replacing playstore icon:playstore_rectangle
    Layer playstoreIconLayer = layerMap.get("appstoreIcon");//findLayer("Playstore_icon",psdImage);
    if(null != playstoreIconLayer){
        //URL url = new URL(appModel.getScreenshots()[i-1]);
        //InputStream inputStream = url.openStream();
        FileInputStream inputStream = new FileInputStream(dataDir + appModel.getPlaystorename()+".png");
        Layer newLayer = new Layer(inputStream);
        //Layer newLayer = new Layer(is);
        Graphics graphics = new Graphics(playstoreIconLayer);
        //graphics.clear(Color.getEmpty());
        graphics.drawImage(newLayer, new Rectangle(new Point(), new Size(Math.abs(playstoreIconLayer.getWidth()), Math.abs(playstoreIconLayer.getHeight()))));

    }


    //changing cta box color
    Layer ctaBoxLayer = layerMap.get("ctaColor");//findLayer("Install_cta_rect",psdImage);
    if(null != ctaBoxLayer && ctaBoxLayer instanceof FillLayer){
        Color color = Color.fromArgb(playstoreBody.getCtaBoxColorList().get(0),playstoreBody.getCtaBoxColorList().get(1),playstoreBody.getCtaBoxColorList().get(2));//getColor(playstoreBody.getCtaTextColor());
        FillLayer recLayer = (FillLayer) ctaBoxLayer;
        IColorFillSettings settings = (IColorFillSettings) recLayer.getFillSettings();
        settings.setColor(color);
        recLayer.setFillSettings(settings);
        recLayer.update();
    }



    File file = new File(dataDir + appModel.getTitle()+i+".png");
    String outputFileName = dataDir + appModel.getTitle()+i+".png";
    String loggerName = appModel.getTitle()+i+".png";
    if(file.exists()){
        int f = 1;
        file = new File(dataDir + appModel.getTitle()+i +"(" + f+")" +".png");
        while(file.exists()){
            f++;
            file = new File(dataDir + appModel.getTitle()+i +"(" + f+")" +".png");
        }
        outputFileName = dataDir + appModel.getTitle()+i +"(" + f+")" +".png";
        loggerName = appModel.getTitle()+i + "(" + f + ")" +".png";
    }
    log.info("Saving Creatives with name " + loggerName);
    pngOptions.setColorType(PngColorType.TruecolorWithAlpha);
    //psdImage.resize(720,1280);
    psdImage.save(new FileOutputStream(outputFileName));
    psdImage.save(new FileOutputStream(outputFileName), pngOptions);
    //psdImage.save(new FileOutputStream(dataDir + appModel.getTitle()+ i +".jpeg"), jpegOptions);
    log.info("Creatives Build Successfully.");
    psdImage.dispose();
    return new ResponseEntity<>(HttpStatus.OK);
}

above is the code for replacement and updating text of psd file. PSD file and images are shared above in chat.
Let me know if you need anything else.

@mail9deep

I have created a ticket with ID PSDJAVA-317 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.
Please also don’t remove the files shared before.

hi @mudassir.fayyaz,

can you let me know till what time this issue will be analysed or fixed?

@mail9deep

There are no updates available at the moment for the status of the issue. Please be patient and we will share notification with you as soon as it will be addressed.

Hi, I would really appreciate an update on this issue. Aspose.imaging.image Save() is taking 30 seconds for me too and I have similar code as mail9deep.

@scoutd could you please provide input file, configuration of environment including OS details and version of Aspose.PSD. Also, please note, this is very old topic and it’s Aspose.PSD topic, but your code contains Aspose.Imaging namespaces. I can ask for Aspose.Imaging team to help you with this issue if you need it.

Okay thank you I will reach out to the Aspose.Imaging team

@evgeniy.sidenko @samer.el-khatib hello, could you please help the customer. I think @scoutd will create new topic in Aspose.Imaging category, I can not move this topic because it affects Aspose.PSD.

Thank you I have created a new topic in the Aspose.Imaging Space