I am trying to record a script that will resize pictures of varying sizes to a particular dimension, in this case, 1920 pixels wide. Any ideas how I can do this?
If I use "resample" to resize a photo to the desired size, and record that action as a script, the resulting script will only work on other images that are the identical size of the image I used when recording the script. How can I write a script that will resize images to the same width, regardless of their original size?
After you have recorded and saved your script in PhotoPaint, open the script file (.csc) with Notepad and delete the line of code that begins with SetDocumentInfo... and then resave. Now it should work on any size image. On Windows 7 saved scripts are located here:
C:\Users\YOUR USERNAME\AppData\Roaming\Corel\CorelDRAW Graphics Suite X7\PHOTO-PAINT\scripts
Patti
pranderson said:After you have recorded and saved your script in PhotoPaint, open the script file (.csc) with Notepad and delete the line of code that begins with SetDocumentInfo... and then resave. Now it should work on any size image.
This only works if all the images are the same aspect ratio. Does anyone a way to do this for a batch of images of different aspect ratios to always resize to longest edge to the same pixel dimension?
RoyReed said:Does anyone a way to do this for a batch of images of different aspect ratios to always resize to longest edge to the same pixel dimension?
The following script works if you want a particular width. It will respect aspect ratios. Change the p# and the first number after Image Resample to match the desired width. Note: The two 72 numbers is dpi/resolution and TRUE is anti-aliasing on.
WITHOBJECT "CorelPHOTOPAINT.Automation.17"
h& = .GetDocumentHeight() w& = .GetDocumentWidth() p# = 250 / w h = h * p .ImageResample 250, h, 72, 72, TRUEEND WITHOBJECT
------------
Reverse the values if you want a particular height:
WITHOBJECT "CorelPHOTOPAINT.Automation.17" h& = .GetDocumentHeight() w& = .GetDocumentWidth() p# = 250 / h w = w * p .ImageResample w, 250, 72, 72, TRUEEND WITHOBJECT
RoyReed said:Thanks Patti I have a batch of 300 random photos from a client to rescale. I don't really want to go through them to sort the portrait from landscape ones - which I think I'd have to do (if I understand your scripts correctly).
Actually, it will do what you want -- and it will respect the aspect ratio/proportions. The problem was my wording when I described it was wrong. I have edited my post to correct that.
If you want a particular width use the first script.
If you want a particular height use the second script.
I used the first script on the following images. They were various sizes and one was portrait orientation. They now have a 250 px width, but their proportions stayed true.
Okay. I think I still was confused about what Roy was after. Good thing I don't write scripts for a living!
The following script should resize the width of landscape oriented images to the specified size. If the image orientation is portrait, it will change the short side to the specified size. Just change 250 to whatever the width is needed, and change the dpi's (72) to what you want.
-------------------------
WITHOBJECT "CorelPHOTOPAINT.Automation.17" h& = .GetDocumentHeight() w& = .GetDocumentWidth()
IF h > w THEN p# = 250 / h w = w * p .ImageResample w, 250, 72, 72, TRUE
ELSE p# = 250 / w h = h * p .ImageResample 250, h, 72, 72, TRUE END IFEND WITHOBJECT
---------------------
It worked for me, but perhaps someone could test it and see if it works for them?
pranderson said:WITHOBJECT "CorelPHOTOPAINT.Automation.17" h& = .GetDocumentHeight() w& = .GetDocumentWidth() IF h > w THEN p# = 250 / h w = w * p .ImageResample w, 250, 72, 72, TRUE ELSE p# = 250 / w h = h * p .ImageResample 250, h, 72, 72, TRUE END IFEND WITHOBJECT
Hi Patti
I just tried this script (saved as .csc in the same folder as the other .csc files) but I get an error message saying the file 'contains an error and could not be run.'
I cannot explain it -- but also I tried copying what I posted here and saving it as a script and I get the error message as well. It shouldn't make any difference, it's just a simple text file. It used to be (X6 and earlier) that a .bmp file was saved along with the script file, but X7 doesn't do that. I am wondering if there is something else going on under the hood that we don't see.
To create my script....What I did was record a script in PPX7 and opened it in Notepad. I made my changes to the code and then just saved over the original. It works fine when I use that script.
I have attached my original .csc, so if you want, you can try it to see if it will work for you.
Finally figured out how to attach/add the .csc file. I changed its extension to .txt, so you will need to change it back to .csc. The only other thing I can think of would be for you to record/open one of your own scripts, save as with a new name, replacing the script code with what I gave here. It should not be this much trouble to share a script, wish Tony Severenuk (or someone who knows) would throw in some thoughts here.
BTW...it's crazy that this forum won't allow Corel .csc scripts!
WITHOBJECT "CorelPHOTOPAINT.Automation.17" h& = .GetDocumentHeight() w& = .GetDocumentWidth() IF h > w THEN p# = 250 / h w = w * p .ImageResample w, 250, 72, 72, TRUE ELSE p# = 250 / w h = h * p .ImageResample 250, h, 72, 72, TRUE END IF END WITHOBJECT