RetouchPRO

Go Back   RetouchPRO > Tools > Software > Photoshop Scripting
Register Blogs FAQ Site Nav Search Today's Posts Mark Forums Read


Photoshop Scripting Learning and sharing for all platforms

Script to Detect Upright and View images

Reply
 
Thread Tools
  #1  
Old 01-06-2008, 11:23 AM
Cameraken's Avatar
Cameraken Cameraken is offline
Senior Member
 
Join Date: Feb 2005
Location: Lancashire (UK)
Posts: 1,158
Script to Detect Upright and View images

Hi

Let's assume I have a CD full of pictures. All the pictures are different sizes some are upright and some are view, some may even be square. (But they are all correctly orientated)

What I would like to do is create a batch file to:

Find the longest side and reduce (or enlarge) it to 600 pixels
Pad out the shortest side to 600 pixels with a white background
Save the new square image to a new folder

I guess I need something like this

Code:
if (activeDocument.width > activeDocument.height) {activeDocument.resizeImage(null, null, activeDocument.width/longside, ResampleMethod.BICUBICSMOOTHER); }
else 
{activeDocument.resizeImage(null, null, activeDocument.height/longside, ResampleMethod.BICUBICSMOOTHER); }
But I can't get it to work correctly in PS7. Everything on the web I found seems to be for CS and doesn't work in PS7. I don't have the skills to convert them. Any ideas welcome.

I also found this
http://ps-scripts.com/bb/viewtopic.php?=&p=2524

but I can't get that working either


Thanks for your help

Ken.
Reply With Quote top
  #2  
Old 01-06-2008, 02:27 PM
DannyRaphael's Avatar
DannyRaphael DannyRaphael is offline
Moderator
 
Join Date: Mar 2002
Location: Near Seattle, Washington, USA
Posts: 6,300
Re: Script to Detect Upright and View images

For what you're trying to accomplish and considering "are all correctly orientated," I believe an action will do it.

Try the one attached. Does this work for you?
Attached Files
File Type: zip 600 pxl x 600 pxl.zip (825 Bytes, 26 views)
Reply With Quote top
  #3  
Old 01-06-2008, 04:06 PM
Cameraken's Avatar
Cameraken Cameraken is offline
Senior Member
 
Join Date: Feb 2005
Location: Lancashire (UK)
Posts: 1,158
Re: Script to Detect Upright and View images

Hi Danny.

Thanks for your help.

The action you have created does work.

I did not realise this would be possible with an action. I assumed I would need script.
The big advantage of script over actions is that they are very easy to edit. Although I am not sure if it's possible to use scripts and batch together.

As you may have guessed this is for web page pictures. Square images are much easier to handle.
I simplified my question because I thought I could just alter the script for different sized images but I also need thumbnail and medium images as well. And actions are not easily editable.

Please could I trouble you for an explanation so that I can 'read' this and recreate it for the other sizes of images.

Where do I find 'Fit Image'?
Will I be able to set 72dpi?
Will I be able to save with different names? Or should I save with Batch.

Sorry I'm not good with actions. (or scripts, or Batch)

Danny. How about a 'Retouch Pro Action' for attaching images to posts.


Ken.

Last edited by Cameraken; 01-06-2008 at 07:06 PM.
Reply With Quote top
  #4  
Old 01-07-2008, 05:09 AM
DannyRaphael's Avatar
DannyRaphael DannyRaphael is offline
Moderator
 
Join Date: Mar 2002
Location: Near Seattle, Washington, USA
Posts: 6,300
Re: Script to Detect Upright and View images

Quote:
Originally Posted by Cameraken View Post
Hi Danny.

Thanks for your help.

The action you have created does work.
My pleasure. Glad it worked.
Quote:
I did not realise this would be possible with an action. I assumed I would need script.
The fact your images were "pre-rotated" is what made an action (only) solution possible. Had this not been the case, engaging a script would have been necessary to automatically rotate images that needed to be rotated 90 degrees within a batch process.
Quote:
The big advantage of script over actions is that they are very easy to edit.
...that's assuming one can get the script working to begin with. One of the challenges is understanding enough about programming to write your own scripts or at least copy/paste or cobble together snipets of code written by others.

The other challenge is script compatibility, or lack thereof, of a given script across versions. Since PS7 Adobe has "upgraded" the JS libraries a couple times which amounts a script written under PS 7 may or may not run under CS, CS2 or CS3 and vice versa, which is probably what bit you here.

Once a script is working I agree that changing command settings can usually be done easily in Notepad or other text editor.
Quote:
Although I am not sure if it's possible to use scripts and batch together.
It's definitely possible. The way it usually works is to record an action that "calls" (plays) one or more scripts, then invoke the action via the Batch command.

The other way is to write your own or use a pre-written script that is fully functional and independent, like "Image Processor" (a JS installed starting with CS, or maybe it was CS2). These types of scripts don't need Batch. The script dialog is similar to Batch where one specifies Source and Destination folders and other script-specific options.

Quote:
As you may have guessed this is for web page pictures. Square images are much easier to handle.

I simplified my question because I thought I could just alter the script for different sized images but I also need thumbnail and medium images as well. And actions are not easily editable.
Hmmm... not sure what you mean here. Most of the time the settings in a given action step can be modified by double-clicking the step, entering new values or move slider controls as needed, click OK and the step is modified.
Quote:
Please could I trouble you for an explanation so that I can 'read' this and recreate it for the other sizes of images.

Where do I find 'Fit Image'? File > Automate > Fit image
Will I be able to set 72dpi? That could be done by recording Image > Image Size

Will I be able to save with different names? Or should I save with Batch. I was assuming you would invoke the action via File > Automate > Batch, where one can specify new file names.

Sorry I'm not good with actions. (or scripts, or Batch) I know how you feel and have the shark bite scars to prove it!

Danny. How about a 'Retouch Pro Action' for attaching images to posts. Now that would be a neat trick! Fact is something like that probably could be programmed, but it would take someone a lot sharper than me to do it!
Further considerations...

Option A: I found this site that has specific If-then-else JS code for PS7.
http://www.hanfordlemoore.com/photoshop/index.htm

Option B: If that does not work for you and/or you want to spell out all the specifics of where you want to go/what you want to do, perhaps a couple actions would be the way to go.
* Specific image sizes, e.g., 600 px x 600 px - What others?
* (new) File name examples
* anything else you can think of

I'll be glad to help if I can.
Reply With Quote top
  #5  
Old 01-08-2008, 08:50 AM
Cameraken's Avatar
Cameraken Cameraken is offline
Senior Member
 
Join Date: Feb 2005
Location: Lancashire (UK)
Posts: 1,158
Re: Script to Detect Upright and View images

Hi Danny.

I found 'Fit Image'
I have never used that before. In fact I've never even seen it before.
It's amazing that I can use this program for years and still not be aware of all the features.

I've also added a Image > Image size
Which changes the pictures to 600 x 600 @ 72 dpi (8.333" x 8.333")

So this is working perfectly.

I can now make two more actions for my medium and small sized images.


Quote:
Most of the time the settings in a given action step can be modified by double-clicking the step, entering new values or move slider controls as needed, click OK and the step is modified.
Yes that’s correct but actions that get used very seldom and I tend to forget what needs altering. Scripts/code (to me) is easier to read and modify.
However by making three actions for the three different image sizes means that they should not need altering in the future, which solves the problem.

Thanks for the link to the script.
A script to decide which action to run. It certainly opens up more possibilities.


Thanks for all your help Danny.


Ken.
Reply With Quote top
Reply

  RetouchPRO > Tools > Software > Photoshop Scripting


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 10:17 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
Copyright © 2016 Doug Nelson. All Rights Reserved