If you want to open file with Layer effects please check the following code:
PsdLoadOptions loadOpt = new PsdLoadOptions();
// For the Applying of effects
loadOpt.setLoadEffectsResource(true);
// For the Applying of Warp Transform
loadOpt.setAllowWarpRepaint(true);
If you want create effects from scratch, please check the following example:
try (PsdImage image = (PsdImage)Image.load(inputFilePath)) {
IGradientColorPoint[] gradientColorPoints = new IGradientColorPoint[] {
new GradientColorPoint(Color.getRed(), 0, 50),
new GradientColorPoint(Color.getGreen(), 1024, 50),
new GradientColorPoint(Color.getBlue(), 2048, 50)
};
@Harbs
I have opened three tickets in our internal issue tracking system according to this task and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PSDNET-1958,PSDNET-1959,PSDJAVA-598
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.
This issue it’s a API Limitation that exists at this moment. Layers contain only its’ pixeldata. So it’s impossible to export Layer with the Effects in this way layer.save(outputFileStream, pngOptions); But this API feature is frequently requested, so I created tasks to improve API.
At this moment to make export of layer with Layer Effects you need to make all layers invisible except exporting one and then save whole Image to PNG with needed layer.
Please check the following code:
private static void ExportLayerWithEffect(PsdImage image, int layerToExportIndex) {
Layer[] layers = image.getLayers();
boolean[] layerStates = new boolean[layers.length];
for (int i = 0; i < layers.length; i++) {
layerStates[i] = layers[i].isVisible();
layers[i].setVisible(false);
}
layers[layerToExportIndex].setVisible(true);
PngOptions pngOpt = new PngOptions();
pngOpt.setColorType(PngColorType.TruecolorWithAlpha);
image.save("SomePath.png");
for (int i = 0; i < layers.length; i++) {
layers[i].setVisible(layerStates[i]);
}
}
Hi, I have applied your example and the layers are exported but the effects do not show in the export. Can you confirm with the PSD above? Here is my export code based on your example:
public class Main {
public static void main(String[] args) {
boolean testing = true;
checkLicense();
if (testing) {
saveLayerToPng(1, false);
saveLayerToPng(2, false);
saveLayerToPng(3, false);
saveLayerToPng(4, false);
return;
}
}
private static void saveLayerToPng(int layerIndex, boolean addEffectManually) {
boolean applyEffects = true;
File psdFile = new File("psds/effects/text-shape-font-effects.psd");
PsdLoadOptions loadOptions = null;
File outputImage = new File("layer_" + layerIndex + ".png");
if (applyEffects) {
loadOptions = new PsdLoadOptions();
loadOptions.setLoadEffectsResource(true);
loadOptions.setAllowWarpRepaint(true);
System.out.println("Setting load effects to true");
}
FileInputStream inputFileStream = null;
try {
inputFileStream = new FileInputStream(psdFile);
} catch (FileNotFoundException e) {
System.err.println("File <" + psdFile.getPath() + "> does not exist");
System.exit(1);
} catch (SecurityException e) {
System.err.println("File <" + psdFile.getPath() + "> cannot be read");
System.exit(1);
}
Image image = Image.load(inputFileStream, loadOptions);
// Image image = Image.load(inputFileStream);
PsdImage psdImage = (PsdImage) image;
PngOptions pngOptions = new PngOptions();
pngOptions.setColorType(PngColorType.TruecolorWithAlpha);
// output with effects
Layer[] layers = psdImage.getLayers();
boolean[] layerStates = new boolean[layers.length];
for (int i = 0; i < layers.length; i++) {
layerStates[i] = layers[i].isVisible();
layers[i].setVisible(false);
}
layers[layerIndex].setVisible(true);
try {
FileOutputStream outputFileStream = new FileOutputStream(outputImage);
psdImage.save(outputFileStream, pngOptions);
// psdImage.save(outputFileStream);
System.out.println("Saved layer to " + outputImage.getPath());
} catch (Exception e) {
// throw new TaskException("Failed to output image to file: " +
// outputImage.getPath(), e);
System.err.println("Failed to output image to file: " + outputImage.getPath());
System.exit(1);
}
}
}
You may have to adjust the code to work with your test program. I am only getting the normal layer with no effects applied.
@Harbs @velara1 I’ve checked your file, so I can confirm that Aspose.PSD has issues with rendering or reading multiple effects.
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): PSDJAVA-608,PSDNET-2003
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.
@velara1 when you use ReadOnlyMode, Aspose.PSD takes pixel-perfect saved preview of file. If you open file without ReadOnlyMode, then according to LoadEffectsResource property effects will be rerendered or ignored.
OK. Then the ReadOnlyMode is saving the composite image embedded in the PSD correct? That won’t have the effects on the layers.
So the effects are created by the rendering engine. If it’s not, then we are simply attempting to get the layer image with effects applied (no editing is needed).
If you are taking feature requests on this topic:
layer.png() or layer.save() saves the image with effects
flag if the effects are ignored or not supported yet
layer.save() or psdImage.save() trims the transparent pixel edges (autocrop) but optionally or only as much as the minimum of the layer width and height
Ideally, the Autocrop or trim feature would not completely trim all the whitespace area of a layer. If it is a psdImage composite it would trim the excess areas not part of the layer. Or if it is exported a text layer, if the original text layer is 100x100 normally it may have transparency around it already. That white space is part of the margins. So you don’t want to trim all of that white space. But when effects are applied, like a drop shadow and you have to use the psdImage.save() method the layer content size maybe less than 100x100 if you trim all the transparent pixels. So the final layer size will be less than the artboard size but not less than the layer size. I hope that makes sense.
@Harbs @velara1 I’ve checked readonlymode with this file and created new bug.
After the investigation of feature-request, I’ll create related task and them to this forum issue. Maybe it’s better to create separate forum topic for it.
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-2004
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.
@velara1 sure. These bugs will be fixed on Java too. I specified .NET issues and missed the Java version of bugs to ensure correct forum notifications. These issues are presented in whole Aspose.PSD Family. The notifications of .NET versions will be sent sooner.
The issues you have found earlier (filed as PSDNET-2003) have been fixed in this update. This message was posted using Bugs notification tool by yaroslav.lisovskyi
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.