• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Extendscript question - getting orientation info for copied images

Explorer ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

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));

 

TOPICS
Scripting

Views

485

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Nov 14, 2020 Nov 14, 2020

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 n

...

Votes

Translate

Translate
Community Expert ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

var orientation = Thumb.rotation;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

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

NewThumb.rotation = OldThumb.rotation;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

Ah I follow now, thank you SuperMerlin. Bear in mind I'm very unfamiliar with Javascript so feeling my way through at the moment 🙂

 

So I've now got:

var bm = new BitmapData(thumbs[i].spec);                
if(bm instanceof BitmapData)
{
                    bm.rotation=thumbs[i].rotation;
                    // create the path and file name
                    var exportFilePath = destinationFolder + "/" + thumbs[i].name;
                    bm.exportTo(new File(exportFilePath));              
}

 

That does show var bm as having a rotation of -90 but it doesn't work unfortunately, the file is created without the orientation info (when I check the file info in Bridge it shows the orientation as 1(Normal).

 

Any idea as to why the orientation isn't being picked up in the created file please? I've also tried:

bm.rotate(-90);

on a test file in known portrait orientation and that doesn't work either.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

Have you tried seting the rotation after the bitmap has been exported?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

Thanks SuperMerlin, yes I think that would work, I know this is a daft question but can you give me a clue re how to access the exported file to do that please?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

Untested, but you could try...

var bm = new BitmapData(thumbs[i].spec);                
if(bm instanceof BitmapData)
{
                    // create the path and file name
                    var exportFilePath = destinationFolder + "/" + thumbs[i].name;
                    bm.exportTo(new File(exportFilePath));   
                    var th = new Thumbnail(exportFilePath);
                    th = thumbs[i].rotation;                 
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

Thanks SuperMerlin, tried that, not sure why but it doesn't seem to like:

var th = new Thumbnail(exportFilePath);

 

Just a thought, can I get Bridge to go to the folder defined in var exportFilePath? I'll be able to flip them manually from there if there's no way to do it in the script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

Try...

var th = new Thumbnail(new File(exportFilePath));

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

Thanks for that SuperMerlin, it runs through ok now but still no luck with the rotation though 😞 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 13, 2020 Nov 13, 2020

Copy link to clipboard

Copied

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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 14, 2020 Nov 14, 2020

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines