! Sample Script: Picture Resizer

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Image/Pixel-Color Operations >

! Sample Script: Picture Resizer

 

 

   This is one of the many small everyday scripts you can create over time with the Smart Package Robot. In this case, you can create an icon for the script and place a shortcut on your desktop. When you drag a graphic file onto it, it automatically resizes the image to a specified size set in the script and moves it to a folder that is a subfolder of the original folder where the graphic file was located.

 

For example, if you’ve taken a lot of pictures with a megapixel camera and want to send them via email, the typical problem arises: each picture may be 5 or 6 MB, making it too large for email. You want to resize the images to a size that is clear but still suitable for emailing. That's exactly what this script does. You can drag either a single file or an entire folder onto it. If you drag a single file, it gets resized to about 300 KB. If you drag an entire folder, the whole folder gets resized, and a subfolder containing the smaller images ready for emailing is created. The new commands IFI. and IDI. are used to determine if something is a folder or a file.

 

#SmartPackageRobot #ImageResizing #EmailOptimization #FileManagement #AutomationTools

 

'

'SPR Script-file: New Script_1

'Purpose:

'Author: Theo Gottwalld

'Creation date: 03-05-2025 at 18:53:52

'===========================================================

'#EXE:?path\

'#SPI:ForceWrite

'#ICS:5

' PictureScaler.mrt - Scales images to 2/3 of 4K (2560x1712) and saves as JPG

' Date: March 17, 2025

 

' Define constants

: $$WID=2560  ' Target width

: $$HEI=1712  ' Target height

 

' Get command-line input

: $$INP=$cmdexe$

'$$INP=C:\Users\theog\Desktop\DCIM\100MSDCF\DSC02371.jpg

'$$INP=C:\Users\theog\Desktop\DCIM\100MSDCF

' Check if input is a file

IFI.$$INP

GSB.ProcessFile|$$INP

ELS.

IDI.$$INP

GSB.ProcessFolder|$$INP

ELS.

MBX.Invalid input: $$INP - Must be a file or folder!

EIF.

EIF.

 

ENR.

 

' Subroutine to process a single file

:ProcessFile

$$FIA=§§_01

 ' Check if it’s an image file using wildcard pattern

IVP.$$FIA={{&WILDC:*.jpg}&OR:{&WILDC:*.png}&OR:{&WILDC:*.bmp}}

  ' Extract path and filename

GFT.hb|$$FIA|$$DIR|$$NAM

  ' Create scaled subfolder

VAR.$$OUT=$$DIRscaled\

 

NDI.$$OUT

MKD.$$OUT

EIF.

   ' Load image into IR 0

ANA.Load|0|§§_01

IVV.$tos$=0

MBX.Error loading $$NAM

RET.

EIF.

   ' Scale to 2560x1712 into IR 1

ANA.ResizeTo|0|1|$$WID|$$HEI

'ANA.Show|1!

 

VAR.$$NEW=$$OUT$$NAM_scaled.jpg

   ' Check for overwrite

IFI.$$NEW

MBX.File $$NEW already exists - Overwritten!

EIF.

'MBX.$$NEW

ANA.Save|1|$$NEW

IVV.$tos$=0

MBX.Error saving $$NEW

ELS.

'MBX.Scaled file saved to $$NEW

EIF.

ELS.

   ' Skip non-image files silently

EIF.

RET.

 

' Subroutine to process a folder

:ProcessFolder

$$MIN=§§_01

 ' Create scaled subfolder

VAR.$$OUT=$$MINscaled\

NDI.$$OUT

MKD.$$OUT

EIF.

' Enumerate files (only files, no recursion)

FEF.Process|$$FIL|$$MIN|*.*|4

MBX.Folder processing complete! $#tos# files found.

RET.

 

' Label for FEF enumeration

:Process

GSB.ProcessFile|$$FIL

RET.