# SaveAs jpg quality not working

**URL:** <https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597>\
**Category:** UXP Developer Tool\
**Tags:** uxp\
**Created:** [April 9, 2025, 1:06pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597 "2025-04-09T13:06:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fred](https://forums.creativeclouddeveloper.com/u/fred)\
**Post date:** [April 9, 2025, 1:06pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/1 "2025-04-09T13:06:03Z")

</div>

Hello,  
The quality option doesn’t seem to work. I get:  
File size: 824KB with quality:12  
File size: 681KB with quality:1  
Quality 1 should be a much smaller file size … I don’t understand what I am doing wrong…  
Thx for your help,  
fred

```auto
        const storage = require("uxp").storage;
        const lfs = storage.localFileSystem;
        
        await require('photoshop').core.executeAsModal(async () => {
            try {
                let f = await lfs.getFileForSaving("Logo_OK_FINAL_TODAY_LAST.jpg");
        
                await app.activeDocument.saveAs.jpg( f, {
                    embedColorProfile: true, quality: 1
            }, true );

            } catch (error) {
                console.error("Error creating export file:", error.message);
            }
        })

```

---

<div class="post-metadata">

**Author:** ![jduncan](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jduncan/32/4301_2.png) [@jduncan](https://forums.creativeclouddeveloper.com/u/jduncan)\
**Post date:** [April 9, 2025, 2:23pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/2 "2025-04-09T14:23:30Z")

</div>

It really depends on the file contents. For example, if the image is a solid white square, there isn’t much data for the JPEG compression algorithm to compress, so the file size difference between quantity 12 and 1 would be small.

To test, open your image in Photoshop and then open the save for web dialog via `File > Export > Save for Web (Legacy)...`. Adjust the quantity and check the file size at different qualities and see if you get the same results as the script.

 ![CleanShot 2025-04-09 at 10.18.38@2x](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/9/9d0c4327f0962893d2dff525b3d450c92ea01a45.jpeg)

And, just so you know, when I test a color picture using your script, the difference between quality 1 and quality 12 is evident in the file size and also visually.

---

<div class="post-metadata">

**Author:** ![fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fred](https://forums.creativeclouddeveloper.com/u/fred)\
**Post date:** [April 10, 2025, 12:27pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/3 "2025-04-10T12:27:22Z")

</div>

Hi Duncan,  
Thank you for your response.  
I tried different export types in the Photoshop interface and the only one exporting to a very small file in the lowest quality is, like you said: **SaveForWeb (Legacy)**.

This works very well in Extendscript:

```auto
                var options = new ExportOptionsSaveForWeb();
                    options.format = SaveDocumentType.JPEG;
                    options.includeProfile = true;
                    options.quality = 3;
                    options.optimized = true;

                // export to JPG
                app.activeDocument.exportDocument(exportFile, ExportType.SAVEFORWEB, options);

```

Is there a UXP code available doing that (API ou BatchPlay) ?

Thx,  
Fred

---

<div class="post-metadata">

**Author:** ![jduncan](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jduncan/32/4301_2.png) [@jduncan](https://forums.creativeclouddeveloper.com/u/jduncan)\
**Post date:** [April 10, 2025, 4:39pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/4 "2025-04-10T16:39:38Z")

</div>

Your code should work as long as the image can be successfully compressed by the JPEG algorithm. Using your code with a JPEG picture I get the following result.

- Quality 12 = 2.2 MB jpeg file
- Quality 1 = 301 KB jpeg file

As you can see, a lower quality does result in a smaller file size using your code. Also note, if I use the legacy Export for Web dialog and set the quality to 10 (roughly 1 on a 1-12 scale) the file size is very similar as what was exported from your script.

Can you post an example image that is giving you trouble? Maybe that will help figure out why you are not getting the expected results.

 ![CleanShot 2025-04-10 at 12.31.28@2x](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/5/5d3cb260e5ad28b48e496445a3d10b8b926ac38d.jpeg)  
 ![CleanShot 2025-04-10 at 12.31.33@2x](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/d/d7ecafd749782dfea1d3df76c29f15f59fee5ec6.jpeg)  
 ![CleanShot 2025-04-10 at 12.37.14@2x](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/7/75550cea2d14999885f77476520a267b79ceaf51.jpeg)

---

<div class="post-metadata">

**Author:** ![fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fred](https://forums.creativeclouddeveloper.com/u/fred)\
**Post date:** [April 14, 2025, 11:47am UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/5 "2025-04-14T11:47:02Z")

</div>

Hello, I coded a quick .psjs file to check the saveas jpg of a 300x600.psd with a solid green background with 2 different quality settings and I really dont understand what’s wrong here.

with quality = 10 the file size is: **624 KB**.  
with quality = 1 the file size is: **622 KB**.

If I use Export \> Export As in photoshop, the file is **1.5 KB** …

```auto
const photoshop = require("photoshop");
const { constants } = photoshop;
const fs = require("uxp").storage.localFileSystem;
const app = photoshop.app;
const { showAlert } = photoshop.core;

    await require('photoshop').core.executeAsModal(async () => {
        
        try {
            let options = {
                embedColorProfile: false, // Disable color profiles
                quality: 1, // Adjust quality (1-12)
                formatOptions: constants.JPEGFormatOptions.OPTIMIZEDBASELINE
            };

            const myFolder = await fs.getFolder();
            await showAlert("myFolder: " + myFolder)
            const uniqueFileName = `JPG_quality_${options.quality}.jpg`;
            const exportFile = await fs.createEntryWithUrl(`${myFolder.nativePath}/${uniqueFileName}`, { overwrite: true });
            await app.activeDocument.saveAs.jpg(exportFile, options, true);
                    
        } catch (error) {
            await showAlert("error: " + error)
            console.error("Error during export:", error.message);
        }
    });

```

 ![Screenshot 2025-04-14 at 13.15.03](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/7/756c454fecac3eb794d7ffa623ece26e1fd83e7e.jpeg)

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [April 14, 2025, 2:06pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/6 "2025-04-14T14:06:59Z")

</div>

Not sure now, but I think I saw some post saying that in some case quality value is 1-255. Can you try setting it 255 and see what happens? No guarantees though 🙂

---

<div class="post-metadata">

**Author:** ![fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fred](https://forums.creativeclouddeveloper.com/u/fred)\
**Post date:** [April 14, 2025, 2:24pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/7 "2025-04-14T14:24:38Z")

</div>

Hi, thanks for the tip. I just tried quality = 255 and the file size is: **624 KB** ☹

I really don’t understand. **SaveForWeb** in Extendscript used to to do this really well but Adobe removed it from UXP if I understand correctly…

---

<div class="post-metadata">

**Author:** ![jduncan](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jduncan/32/4301_2.png) [@jduncan](https://forums.creativeclouddeveloper.com/u/jduncan)\
**Post date:** [April 14, 2025, 2:31pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/8 "2025-04-14T14:31:02Z")

</div>

So, the first thing that jumps out at me is that your exported file sizes seem way too big for a 300x600 image. I mean, a real saved Photoshop psd file at 300x600 with a simple green background is only 40 KB on my system…

Using an identical 300x600 at 72 ppi file,

If I run your script, I get:

```auto
JPG_Quality_1.jpg @ 13 KB
JPG_Quality_12.jpg @ 14 KB

```

If I use Export As, I get:

```auto
JPG_Quality_1.jpg @ 1 KB
JPG_Quality_7.jpg @ 2 KB

```

If I use Save For Web (Legacy), I get:

```auto
JPG_Quality_12.jpg @ 2 KB // 12 to match the 1 from above on a 1-12 scale 
JPG_Quality_100.jpg @ 3 KB

```

If I increase the ppi to 300, the exported sizes using your script are still only:

```auto
JPG_Quality_12.jpg @ 13 KB
JPG_Quality_100.jpg @ 14 KB

```

As you can see, none of the methods export the same file sizes. I know from previous experience scripting with Illustrator that different parts of the program use different code and the quality and exported sizes from a script can differ quite a bit. This still doesn’t explain the really large files sizes you are getting so I fear I may be out of solutions…

This may be a long shot but are you using the latest version of Photoshop? If not, maybe try updating and see if you get the same numbers.

---

<div class="post-metadata">

**Author:** ![fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fred](https://forums.creativeclouddeveloper.com/u/fred)\
**Post date:** [April 14, 2025, 2:51pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/9 "2025-04-14T14:51:00Z")

</div>

Wow! thank you so much for looking into that… I just tried with a brand new 300x600.psd with just a red background and I do get a **15KB** jpg file …

Now, i am comparing the 2 PSDs to catch any differences.

---

<div class="post-metadata">

**Author:** ![fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fred](https://forums.creativeclouddeveloper.com/u/fred)\
**Post date:** [April 14, 2025, 3:17pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/10 "2025-04-14T15:17:34Z")

</div>

So, I think that I spotted the difference between the 2 PSDs:

The green one has a **FILL LAYER**. In Photoshop: Layer \> New Fill Layer \> Solid Color…  
When selected, this layer has no properties in the properties panel.

The red one is just a **PIXEL** layer filled with red.  
When selected, this layer has properties in the properties panel, like Transform, Align, etc..

Using uxp SaveAs jpg, the PSD with Fill Layer is not compressed (624KB) but the one with Pixel is (15KB)…

 ![Screenshot 2025-04-14 at 17.15.48](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/2/25d2a4948512c32be74d36f4ca9038454259850c.jpeg)  
 ![Screenshot 2025-04-14 at 17.16.17](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/5/55f627c6af3b36e6dded8413535c5a6a1208917c.jpeg)

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [April 14, 2025, 3:19pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/11 "2025-04-14T15:19:18Z")

</div>

Wait… This makes SaveAs JPEG via API pretty much useless 😕

---

<div class="post-metadata">

**Author:** ![fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fred](https://forums.creativeclouddeveloper.com/u/fred)\
**Post date:** [April 14, 2025, 3:23pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/12 "2025-04-14T15:23:39Z")

</div>

Well, I am going to ask the designers at my company NOT to use that **FILL LAYER** in their PSDs for now …

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [April 14, 2025, 4:21pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/13 "2025-04-14T16:21:12Z")

</div>

Or merge all layers to new raster layer on a new document, then export and close that document

---

<div class="post-metadata">

**Author:** ![jduncan](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jduncan/32/4301_2.png) [@jduncan](https://forums.creativeclouddeveloper.com/u/jduncan)\
**Post date:** [April 14, 2025, 5:26pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/14 "2025-04-14T17:26:19Z")

</div>

Yeah, I would think it shouldn’t matter. Maybe first flatten the image in your script and then use the export to ensure you get the smallest file size. Seems like a bug in the API to me.

---

<div class="post-metadata">

**Author:** ![fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fred](https://forums.creativeclouddeveloper.com/u/fred)\
**Post date:** [April 15, 2025, 8:21am UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/15 "2025-04-15T08:21:55Z")

</div>

Hello, thank you all for your help.  
I tried to flatten the PSD before SaveAs jpg and … it doesn’t work ☹ The exported jpg with quality = 1 is **630KB**.  
Cheer,  
Fred

```auto
const photoshop = require("photoshop");
const { constants } = photoshop;
const fs = require("uxp").storage.localFileSystem;
const app = photoshop.app;
const { showAlert } = photoshop.core;

    await require('photoshop').core.executeAsModal(async () => {
       
        try {

            let options = {
                embedColorProfile: false, // Disable color profiles
                quality: 1, // Adjust quality (1-12)
                formatOptions: constants.JPEGFormatOptions.OPTIMIZEDBASELINE
            };

            await app.activeDocument.flatten();

            const myFolder = await fs.getFolder();
            await showAlert("myFolder: " + myFolder)
            const uniqueFileName = `JPG_quality_${options.quality}.jpg`;
            const exportFile = await fs.createEntryWithUrl(`${myFolder.nativePath}/${uniqueFileName}`, { overwrite: true });
            await app.activeDocument.saveAs.jpg(exportFile, options, true);
                    
        } catch (error) {
            await showAlert("error: " + error)
            console.error("Error during export:", error.message);
        }
    });

```

---

<div class="post-metadata">

**Author:** ![fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fred](https://forums.creativeclouddeveloper.com/u/fred)\
**Post date:** [April 15, 2025, 12:44pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/16 "2025-04-15T12:44:35Z")

</div>

**Latest update:**  
I did what Karmalaks suggested above:  
_merge all layers to new raster layer on a new document, then export and close that document_  
and it finally worked **(33KB)**. I am not sure why you need those extra steps. Can someone explain?  
Fred

```auto
const photoshop = require("photoshop");
const { constants } = photoshop;
const fs = require("uxp").storage.localFileSystem;
const app = photoshop.app;
const { showAlert } = photoshop.core;

    await require('photoshop').core.executeAsModal(async () => {
        
        try {

            let options = {
                embedColorProfile: true, // Disable color profiles
                quality: 3, // Adjust quality (1-12)
                formatOptions: constants.JPEGFormatOptions.OPTIMIZEDBASELINE
            };

            await app.activeDocument.mergeVisibleLayers();
            await app.activeDocument.flatten();
            
            // unlock all layers
            app.activeDocument.activeLayers[0].allLocked = false;
    
            // Create a new document with the same dimensions as the active document
            const activeDoc = app.activeDocument;
            const newDoc = await app.documents.add({
                width: activeDoc.width,
                height: activeDoc.height,
                resolution: activeDoc.resolution,
                mode: activeDoc.mode,
                fill: constants.DocumentFill.TRANSPARENT,
            });
    
            // Duplicate content into the new document
            await activeDoc.activeLayers[0].duplicate(newDoc);
                
            const myFolder = await fs.getFolder();
            // await showAlert("myFolder: " + myFolder)
            const uniqueFileName = `JPG_quality_${options.quality}.jpg`;
            const exportFile = await fs.createEntryWithUrl(`${myFolder.nativePath}/${uniqueFileName}`, { overwrite: true });
            await app.activeDocument.saveAs.jpg(exportFile, options, true);

        } catch (error) {
            await showAlert("error: " + error)
            console.error("Error during export:", error.message);
        }
    });

```

---

<div class="post-metadata">

**Author:** ![jduncan](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jduncan/32/4301_2.png) [@jduncan](https://forums.creativeclouddeveloper.com/u/jduncan)\
**Post date:** [April 15, 2025, 1:39pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/17 "2025-04-15T13:39:21Z")

</div>

Something still doesn’t add up. I created a 300x600 @ 72 ppi Photoshop file with one single green Solid Color fill layer. When I use your script from yesterday to export a JPEG at quality 1, I get a 13 KB file (quality 12 is 14 KB). See attached screenshots.

Can you share your sample file so I can inspect it?

 ![CleanShot 2025-04-15 at 09.35.06@2x](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/f/feff663f2d2d9ae3aa374c2e0d5d6281eff63c91.jpeg)

 ![CleanShot 2025-04-15 at 09.35.10@2x](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/5/59d781c4ace14fbb2941339fd28d90bfdf588b7a.jpeg)

 ![CleanShot 2025-04-15 at 09.38.44@2x](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/b/bf15a25e98a47374262c527648bd0807e5219075.jpeg)

---

<div class="post-metadata">

**Author:** ![fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fred](https://forums.creativeclouddeveloper.com/u/fred)\
**Post date:** [April 15, 2025, 1:56pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/18 "2025-04-15T13:56:05Z")

</div>

Yes, here are the 2 PSDs.  
[PSDs.zip](https://forums.creativeclouddeveloper.com/uploads/short-url/jgoFgQsncEGPJ0wtYmyBLA0LwtT.zip) (190.2 KB)

---

<div class="post-metadata">

**Author:** ![jduncan](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jduncan/32/4301_2.png) [@jduncan](https://forums.creativeclouddeveloper.com/u/jduncan)\
**Post date:** [April 15, 2025, 2:23pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/19 "2025-04-15T14:23:05Z")

</div>

Okay, your green file has over 10,000 lines of metadata (check File \> File Info…). My example PSD only has 16 lines for comparison. Those 10,000 extra lines are what is causing the file size inflation. Most of your meta data is `photoshop:DocumentAncestors`. I have found a few forum posts about people with the same issue. Did this file have other stuff before? Is this green layer copied from another file? It seems Photoshop can keep metadata that is no longer needed. I would first start a fresh new file and run the test again to see if you get the same file size and metadata. If not, there is an issue with the exact file you have.

**Forum Links:**

- [https://community.adobe.com/t5/photoshop-ecosystem-discussions/larger-file-sizes/m-p/10875717](https://community.adobe.com/t5/photoshop-ecosystem-discussions/larger-file-sizes/m-p/10875717)
- [https://community.adobe.com/t5/photoshop-ecosystem-discussions/inflated-jpg-file-size-photoshop-document-ancestors-metadata/m-p/8055434](https://community.adobe.com/t5/photoshop-ecosystem-discussions/inflated-jpg-file-size-photoshop-document-ancestors-metadata/m-p/8055434)
- [https://community.adobe.com/t5/photoshop-ecosystem-discussions/remove-documentancestors-recursively-for-all-smartobjects-in-a-psd/m-p/13046190](https://community.adobe.com/t5/photoshop-ecosystem-discussions/remove-documentancestors-recursively-for-all-smartobjects-in-a-psd/m-p/13046190)

---

<div class="post-metadata">

**Author:** ![fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fred](https://forums.creativeclouddeveloper.com/u/fred)\
**Post date:** [April 15, 2025, 2:54pm UTC](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597/20 "2025-04-15T14:54:19Z")

</div>

Yes, i think you are right. The **300x600\_green.psd** is **816KB**.  
It is a cleaned version of an older file. I removed a lot of layers to simplify it but like you said it seems that Photoshop keeps metadata that is no longer needed.  
When starting from a fresh file, there is no problem to export the jpg file with a low file size.

The problem is that I get PSD files from designers and they probably reuse old files.  
I can ask them to start fresh. I will also look for info in the list of forums you sent and try to remove the old metadata.

Once again, thank you so much for your help.  
Fred

[Next page](https://forums.creativeclouddeveloper.com/t/saveas-jpg-quality-not-working/10597.md?page=2)
