HI Sergey, Basically i have recorded a macro when in it does the following step:
Open MS Paint
Goto file and Open a image from one folder
resize the image in height and width
save as same file name in another folder.
while i was able to successfully do for one, i am finding it difficult to loop , use for each. Can you help me, possibly i can share my screen with you.
HI Manjuts, i am looking for a looping. Had explain to Mr Sergey Basically i have recorded a macro when in it does the following step:
Open MS Paint
Goto file and Open a image from one folder
resize the image in height and width
save as same file name in another folder.
while i was able to successfully do for one, i am finding it difficult to loop
it’s a manual process and can be quite time-consuming. There are more efficient tools available for batch image resizing, but I’ll provide you with the steps you can follow using MS Paint.
Firstly Create a new text file with the extention .ps1 .
then open example.ps1 and add this script.
# Specify the source and destination folders
$sourceFolder = "C:\Path\To\Source\Folder"
$destinationFolder = "C:\Path\To\Destination\Folder"
# Specify the desired width and height
$desiredWidth = 800
$desiredHeight = 600
# Get a list of image files in the source folder
$imageFiles = Get-ChildItem -Path $sourceFolder -Filter *.jpg
# Loop through each image file
foreach ($imageFile in $imageFiles) {
# Open MS Paint
Start-Process mspaint
# Wait for MS Paint to open
Start-Sleep -Seconds 2
# Open the image in MS Paint
Start-Process -FilePath "mspaint.exe" -ArgumentList $imageFile.FullName
# Wait for MS Paint to open the image
Start-Sleep -Seconds 2
# Resize the image using the keyboard shortcuts (Alt + H + R)
[System.Windows.Forms.SendKeys]::SendWait("%h")
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait("r")
Start-Sleep -Milliseconds 500
# Enter the desired width and height
[System.Windows.Forms.SendKeys]::SendWait("$desiredWidth")
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait("$desiredHeight")
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
Start-Sleep -Milliseconds 500
# Save the image with a new name in the destination folder
[System.Windows.Forms.SendKeys]::SendWait("%f")
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait("a")
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait("$destinationFolder\$($imageFile.BaseName)_resized.jpg")
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
Start-Sleep -Milliseconds 500
# Close MS Paint
[System.Windows.Forms.SendKeys]::SendWait("%{F4}")
Start-Sleep -Milliseconds 500
}
Note: Replace the $sourceFolder and $destinationFolder with your source.
On PowerShell run this .\scriptname.ps1
This just an example… test it on your dev environment. i found one tool https:jpegcompressor.com/ if you have small quantity of image and want fine compression of your images then you can use above tool.