Skip to main content
Inspiring
November 13, 2020
Answered

Extendscript question - getting orientation info for copied images

  • November 13, 2020
  • 3 replies
  • 1317 views

Hi everyone, my first post in this community! I'm looking for a bit of help with scripting to automate copying files please.

 

I've been writing a simple script to copy selected thumbnails from bridge to a different folder. I'm completely new to javascript so feeling my way through - one problem that I've run into is that when the call is made to create the new bitmap file, the orientation information is lost so portrait images appear as landscape after they're copied to the new location.

 

Any suggestions as to how I can get the orientation information from the source file (the one that's been selected) prior to creating the new file? If I can get that then I can check if the newly created bitmap needs to be rotated but I can't work out how to access it. Here's what I've got so far:

 

 var thumbs = app.document.getSelection("psd, jpg, png, tif, gif");
        alert(thumbs.length+ "files to copy");
        for(var i = 0;i < thumbs.length;i++)
{
if(thumbs[i].spec instanceof File)
{
var thumb = thumbs[i];
// create a BitmapData object
                 var bm = new BitmapData(thumbs[i].spec);                 
if(bm instanceof BitmapData)
{
// create the path and file name
var exportFilePath = destinationFolder + "/" + thumbs[i].name;
// create the new file in the target location
bm.exportTo(new File(exportFilePath));

 

This topic has been closed for replies.
Correct answer kubicixfactor

Ok, I wondered if resizing was why. I publish a JPEG export script that resizes files and have to create bitmaps to do so but I haven't had problems with rotation.
To copy a file, use this syntax:

 

var myThumbs = app.document.selections;
var myFolder = Folder('~/Desktop/');
myThumbs[0].copyTo(myFolder);


Ah that's useful to know, thank you Lumigraphics! I'm so new to this that even the most basic calls need a few pointers!

 

I managed to navigate the rotation problem by looking a bit more closely at the JS guide BitmapData functions and used:

var bm = new BitmapData(thumbs[i].spec);

var rotatedBM=bm.rotate(-90);

rotatedBM.exportTo(new File(exportFilePath));

 

Doubtless not the tidiest (or most efficient) way to do it but at least I've solved this particular problem (well I think I have!). I really do need to get my head into a book to understand this a lot more, completely clueless at the moment re functions for example.

3 replies

Brainiac
November 13, 2020

Why not just copy the files? You don't need to create a whole new bitmap.

Inspiring
November 13, 2020

I can't work out how to just copy the files through the script. Any advice on how to do that please?

Brainiac
November 13, 2020

Thanks for your suggestion. One point that's worth adding is that I may want to create different sizes of the files.

 

The reason I'm creating this script is to quickly process files at a point of sale for customers. So they purchase a digital copy of a file (in either low or high resolution) and the script uploads it to a specific Dropbox folder. I have an assistant and going through the process of selecting the files and manaually copying them can potentially introduce errors.


Ok, I wondered if resizing was why. I publish a JPEG export script that resizes files and have to create bitmaps to do so but I haven't had problems with rotation.
To copy a file, use this syntax:

 

var myThumbs = app.document.selections;
var myFolder = Folder('~/Desktop/');
myThumbs[0].copyTo(myFolder);

SuperMerlin
Inspiring
November 13, 2020

var orientation = Thumb.rotation;

Inspiring
November 13, 2020

Thank you, I've looked at orientation and that was my intention - but it won't work because once the new file has been created the orientation data seems to be removed, so the only way to get it the right way up is by doing it manually?

SuperMerlin
Inspiring
November 13, 2020

I don't follow as you can reference the old file to the new file....

NewThumb.rotation = OldThumb.rotation;

jbm007
Adobe Expert
November 13, 2020

Lumagraphis are resident script guru who lurks here should be able to help you.