Skip to main content
Inspiring
Nov 13, 2020 12:20 PM UTC
Answered

Extendscript question - getting orientation info for copied images

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 is closed to new replies. Start a new post to keep the conversation going.
kubicixfactorCorrect answer
Inspiring
Nov 14, 2020 11:15 AM UTC

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.

16 replies

Legend
Nov 13, 2020 1:47 PM UTC

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

Translate
Inspiring
Nov 13, 2020 2:12 PM UTC

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

Translate
Inspiring
Nov 13, 2020 2:18 PM UTC

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.

Translate
SuperMerlin
Inspiring
Nov 13, 2020 1:34 PM UTC

var orientation = Thumb.rotation;

Translate
Inspiring
Nov 13, 2020 2:15 PM UTC

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?

Translate
SuperMerlin
Inspiring
Nov 13, 2020 3:16 PM UTC

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

NewThumb.rotation = OldThumb.rotation;

Translate
jbm007
Community Expert
Community Expert
Nov 13, 2020 12:24 PM UTC

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

Translate