Need reference code to use Scripting API for java to resize images
Copy link to clipboard
Copied
Hello,
As per my initially discussion with adobe team on phone, We have raised our query with adobe team in below portal and link.
Need to resize TIFF with transparency
After a week of time, they come back with answer but shared solution was not able to clear our query. Now they have asked us to post our query in this portal. In short we are moving one forum to other forum of adobe to clear our query.
Here is our question.
We need sample java script or API to resize TIFF (Multi layer - Transparency ) images using java code. We have checked below links but we can't find the way how to use this java script to resize images using java code. https://www.adobe.com/devnet/photoshop/scripting.html
Hoping for a quick response.
Thanks
Rikin
Explore related tutorials & articles
Copy link to clipboard
Copied
For clarity: Do you really mean native Java code – and not Javascript (Adobe Extendscript) ?
Is this right?
Apart from that (if you not mean Java) you can use Photoshop scripting DOM eg.
Document.resizeCanvas (width: UnitValue , height: UnitValue , anchor: AnchorPosition )
or Action-Manager-Code (you will need ScriptListener for that).
Copy link to clipboard
Copied
The latest Adobe documentation is downloadable from this link Adobe Photoshop Scripting the link you post it shows in photoshop-cc-javascript-ref-2019.pdf page 95
and on page 96 the example code
Only width and height is required.... The ducDoc was opened from a tif file the may be an error in the code the statement in there I believe should be
duckDoc.resizeImage(flowerDoc.width, flowerDoc.height);
not
duckDoc.resize(flowerDoc.width, flowerDoc.height);
for Resize seems to be for a layer and layers within a layer set and is a relative resize and other thinhs like selections
The resize in the example code may also distort the image for I see no logic to preserve the documents aspect ratio. The resized document would not be distorted if both image have the same aspect ratio.
Copy link to clipboard
Copied
Hello JJMack,
Thanks for your reply.
But If i will use this Java Script then it's compulsory to install Photoshop in my PC. Am i Right?
I want to resize images without installing Photoshop So is there any SDK in Native java , any Photoshop API or any other option using that i can resize images using Java.
Thanks,
Rikin
Copy link to clipboard
Copied
It looks as it's native to Java, see:-
https://memorynotfound.com/java-resize-image-fixed-width-height-example/
Copy link to clipboard
Copied
Hi Merlin,
Thank you for your quick update but sorry to say Its not workable for us.
Let me explain you in detail.
we are from software company and we are developing one software for our client in java technology . He has business of printing. He want to resize different format (PNG, JPEG, Tif) Photoshop image into specific sizes using our software. we are able to do it if image have only RGB or CMYK layer for .tif image but client has also added few additional layer of Photoshop in same image Now when we are resize this image using any third party lib or native code, Its lost that additional layer apart from RGB and CMYK and also transparency so we need Photoshop SDK or API using which we can resize those images with all its property.
JJMack​ : coudk you please also look into it?
Our Need :
we are looking SDK/API/lib which we can integrate it our java software and that will allow us to resize all type of images those have additional layer our Photoshop and also keep all the propitiates of the images.
we have also contact third party for same and we have received below response
The file contains Photoshop specific tags which are not supported in anything other than PhotoShop and does not look compatible with other image viewers.
So we do not support these.
0x8649 Photoshop Collection of Photoshop 'Image Resource Blocks'.
0x935C ImageSourceData Used by Adobe Photoshop.
I hope now its clear to you. Please can you advise us how can we take it forward because we are hanging from last 1 months.
Looking forward to hearing from you ASAP...
Copy link to clipboard
Copied
It might be best to have a look at the ImageMagick API, as I believe it support psd, tif, etc.
Copy link to clipboard
Copied
SuperMerlin​ Thank you for your suggestion but We have already tried ImageMagick.
In JPG & PNG images ImageMagick resize images properly. But If we use it for multi layer TIFF images then resized image lost it's Transparency and also lost some channels. and in some CMYK images color properties is also changed.
Copy link to clipboard
Copied
I don't know of anything else that would help you. Photoshop needs to be installed to use the API/COM but not sure if there is COM for JAVA, also Photoshop must be opened to use it allthough you can have it not visible. (Splash screen still shows on startup)
Copy link to clipboard
Copied
SuperMerlin​ We have licence of Photoshop. We will install Photoshop. Can you please guide us how to use Photoshop API to resize images. I want to know It's compulsory to open at Photoshop when we call API to resize images?
Copy link to clipboard
Copied
If all you want to do is resize image files with Photoshop. All you need to do is use the Image Processor script. Or better still Download and install Image Processor Pro from the web its free and more flexible the Adobe Image Processor script the installs with Photoshop. These Image Processors can be used from Bridge and Photoshop. In Photoshop menu File>Scripts>Image Processor... or menu File>Atomate>Image Processor Pro...
Copy link to clipboard
Copied
Hi JJMack​
Thank you very much for your quick update and reply on it.
I would like to inform you that i have resize image using my JAVA Software.[ i dont want use Photoshop GUI] Can you guide us for photoshop API/SDK that we can integrate with our software and we will be able to perform same action using our software.
Looking forward to hearing from you...
Copy link to clipboard
Copied
Adobe Photoshop has a plug-in ScriptingSupport that supports an old JavaScript implementation with a Photoshop DOM added and it is the only JavaScript Interface I know available for use with Photoshop. If you want to use Photoshop without using its GUI the only way I that can be done is by creating a Photoshop Droplet. A droplet could use a Photoshop Script and the user would never see Photoshop GUI. The Photoshop executed this way would not display its GUI. The Photoshop module would still contain its GUI. It would be like running Photoshop as a background task.
Copy link to clipboard
Copied
I don't know of any Photoshop API for Java so can't help there. I know there is C#, VB, Python COMs
An example of C# to create a document, create new layer, resize ,save and close document.
using System;
namespace ResizeTIFF
{
class Program
{
static void Main(string[] args)
{
//Photoshop will open if not open.
dynamic app = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.Application")); //Late Binding
app.Visible = true;
app.Preferences.RulerUnits = 1; //pixels
app.Documents.Add(1800, 600, 300, "Temp File", 2/* NewDocumentMode.RGB*/, 1 /* DocumentFill.WHITE*/);
app.ActiveDocument.ArtLayers.Add(); //add a new layer
//Only one item required (width/height) for constraint
app.ActiveDocument.ResizeImage(1000 /*width*/, null/*height*/, 300/*resolution*/, 5/* ResampleMethod.BICUBICSHARPER*/);
SaveTIFF(app, @"c:/tmp/test.tif");
}
static void SaveTIFF(dynamic app, string saveFile)
{
dynamic tiffSaveOptions = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.TiffSaveOptions"));
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.transparency = true;
tiffSaveOptions.imageCompression = 2; //TiffEncodingType.TIFFLZW;
app.ActiveDocument.SaveAs(saveFile, tiffSaveOptions, true, 2);
app.ActiveDocument.Close(2); //close document do not save changes
}
}
}
Copy link to clipboard
Copied
Hi SuperMerlin​
Thank you for your support and update.
will you able to guide us from where can get answer of our shared question. ?
we have already developed our entire software in java technology. Now just we are looking that java code which will allow us to resize image using our java application.
Thank you again for all your support !
Copy link to clipboard
Copied
Sorry I cannot find any COM for Java, the only other way I can think of is to create jsx scripts on the fly then execute the script.
Copy link to clipboard
Copied
You seem to want to resize Tiff layered image and write resized Layer Tiff files. If these Layered Tiff files were created using Photoshop. IMO it is very likely that some layers may have some Adobe priority Tags and data that may only be supported by Adobe code. In their Applications and in their SDK. Adobe most like publish information about their data structures. However I would not state Adobe has a stellar reputation of having up to date and correct documentation. Adobe changes thing and introduces many bugs its not possible to keep all things Adobe up to date there are too many problems. Many applications that support Tiff file do not support Tiff layers they only support the Files composite. Have you look at Adobe SDK. I feel one way or an other you will need to use some Adobe Code. Adobe keep adding new layer options and features. Even if a layer data structure is encapsulated. Tags and data structure will most likely continue to evolve and need to be supported code will need to be update.
Copy link to clipboard
Copied
ImageMagick site seems toe indicate Tiff Photoshop Layer can be read or ignored. I see nothing to indicate the it can write Tiff files with Photoshop Layers. Only reading support was specified. If you want to support Photoshop data why do you not want to use Photoshop. I would think writing Photoshop Layers into a Tiff format files would be very hard to write in using Java without some library API support.
Copy link to clipboard
Copied
You are asking a Java dummy to look into your problem don't be a bigger dummy then me. I do not Know Java of Image File formats. I do know what you want to do is not simple. Image are encoded may different ways. You are going to requite some Toolkit designed to work on all the Image File formats you need to support.
Full compatibility for all file formats may not be possible. Adobe add new layer types and new layer features from time to time File Formats evolve and change If there is no compatibility issue today the may be one tomorrow or some time after that.
Copy link to clipboard
Copied
I did not realize you did not want to use Photoshop gor you asked the question in a Photoshop Scripting forum. You should use a Web Html forum or a or a JavaScript forum or a Java forum. Even the JavaScript implementation used by Adobe is old and has a Photoshop DOM added. I do not know how well Java can edit binary and text data in image files. There Are many Image File formats. Images are encoded many ways. Photoshop does not even support all Image file formats and some images file formats are converted to a Photoshop raster layer and can not be saved like the imported image file.

