Convert images while creating a folder

Hi all,
I frequently convert images to different sizes and I store it in a seperate folder.
Is it possible to create a sequence of commands to:

  1. Create a sub folder (let's say with the name: '128x128')
  2. Convert selected images to a certain size and move the converted images to the sub folder (i'm using the command: Image CONVERT HERE ADDSUFFIX HEIGHT=128 WIDTH=128 PRESERVEASPECTRATIO but I would like to replace HERE with the destination of the folder I just created)

Thanks for any hints!

Here's a stab at what you are looking for. I needed something similar myself. The button below will prompt you to either select or create a destination subfolder. It will also prompt you for how you want the size separated from the original name— the default separator is "-" (no quotes). You are also prompted for the width and height, though the command will maintain the aspect ratio, so these numbers could ultimately be a little off. After you are done answering questions, the folder is created and all selected images are resized and stored inside the designated folder with new names.

I have no idea what would happen if you selected a file that was not an image. I think Opus won't operate on unsupported images. I did not use ADDSUFFIX/S to add the size suffix, because I wanted the actual size, not small, medium, etc.

Currently, Opus is a bit temperamental with quotes and percent characters in MS-DOS Batch functions, which is why you will see some of the weird-looking code (like where I insert some characters, only to remove them later). I've already reported the relevant issues and GPSoftware will hopefully address them in an upcoming version.

<?xml version="1.0"?> <button display="both" effect="saturate"> <guid>{190B66E8-AF69-4F24-961F-9F667CB3452A}</guid> <label>Resize to Folder</label> <tip>Resizes selected images to a folder (prompts for folder name, divider, and size)</tip> <icon1>163</icon1> <function type="batch"> <instruction>:OpusDirectives</instruction> <instruction>Runmode HIDE</instruction> <instruction>@nofilenamequoting</instruction> <instruction> </instruction> <instruction>:Start</instruction> <instruction> @Echo OFF &amp; If /i NOT [%OS%]==[Windows_NT] Goto 95-98-ME</instruction> <instruction> Mode con: cols=80 lines=25</instruction> <instruction> Title Opus - Resize Images Into Folder</instruction> <instruction> Setlocal enableextensions</instruction> <instruction> </instruction> <instruction>:SetVars</instruction> <instruction> Call Set SavePath={dlgfolder|Create or select a subfolder to place the resized images in:|{sourcepath$}}</instruction> <instruction> Call Set SavePath=%SavePath:~,-1%</instruction> <instruction> Call Set Divider={dlgstring|Enter the divider to offset the image size with:|"-"}</instruction> <instruction> Call Set Width={dlgstring|Enter image width in pixels (aspect ratio will be preserved):}</instruction> <instruction> Call Set Height={dlgstring|Enter image height in pixels (aspect ratio will be preserved):}</instruction> <instruction> </instruction> <instruction>:Wait</instruction> <instruction> :: The if condition ensures folder is created before continuing.</instruction> <instruction> If NOT Exist "%SavePath%." (</instruction> <instruction> MD "%SavePath%" &gt;Nul</instruction> <instruction> Goto :Wait</instruction> <instruction> )</instruction> <instruction> </instruction> <instruction>:EachFile</instruction> <instruction> :: Opus will write the {file$} line below once for each selected file.</instruction> <instruction> :: Call :ProcessFile ensures each file is processed one-at-a-time.</instruction> <instruction> Call :ProcessFile ""{file$}""</instruction> <instruction> Goto :EOF</instruction> <instruction> </instruction> <instruction>:ProcessFile</instruction> <instruction> :: Append new file name with actual size dimensions.</instruction> <instruction> :: Image ADDSUFFIX/S uses : -thumb, -small, -medium, etc.</instruction> <instruction> Call Set FileName=%~1</instruction> <instruction> Call Set NewName=%~n1¬'¬%Divider%¬'¬%Width%x%Height%.%~x1</instruction> <instruction> Call Set NewName=%NewName:¬'¬=%</instruction> <instruction> Call Set NewName=%NewName:..=.%</instruction> <instruction> dopusrt /CMD Select NONE</instruction> <instruction> dopusrt /CMD Select "%FileName%"</instruction> <instruction> dopusrt /CMD Image CONVERT WIDTH=%Width% HEIGHT=%Height% PRESERVEASPECTRATIO TO="%SavePath%" AS="%NewName%"</instruction> <instruction> Goto :EOF</instruction> <instruction> </instruction> <instruction>:95-98-ME</instruction> <instruction> :: This script uses techniques unavailable in Windows 95/98/ME</instruction> <instruction> </instruction> <instruction> @Echo OFF</instruction> <instruction> Mode con: cols=35 lines=7</instruction> <instruction> Color 4E</instruction> <instruction> CLS</instruction> <instruction> Echo. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»a</instruction> <instruction> Echo. º º</instruction> <instruction> Echo. º Sorry, this button cannot º</instruction> <instruction> Echo. º support Windows 95/98/ME. º</instruction> <instruction> Echo. º º</instruction> <instruction> Echo. ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼa</instruction> <instruction> Ping -n 3 127.0.0.1 &gt; Nul</instruction> <instruction> Exit</instruction> <instruction> </instruction> <instruction> :: End of :95-98-ME</instruction> </function> </button>

[ol][li] Copy the code above.[/li]
[li] Right-click any toolbar, and select Customize.[/li]
[li] Right-click the target toolbar, and select Paste[/li][/ol]

That seems like overkill, at least if the sub-folder name is fixed ("128x128" in this case).

You can use the TO argument to specify a destination directory, and specify one relative to . (the current directory) to write the results to a sub-folder.

When using the TO argument you should remove the HERE argument, of course.

Also, the folder has to be created first. So here's the command:

CreateFolder "128x128" Image CONVERT ADDSUFFIX HEIGHT=128 WIDTH=128 PRESERVEASPECTRATIO TO=".\128x128"
(Switch the Command Editor to Advanced mode to allow you to enter a multi-line command.)

Hard coding everything would be much simpler, if I were doing exactly the same thing every time. But I don't.[ul][li] I do not use the same target folder path all the time. Sometimes my target folder is a subfolder under the current Source folder, sometimes it's a different path entirely on another drive.
[/li]
[li] I do not use the same image dimensions all the time.
[/li]
[li] I never want the words: thumbs, small, medium, large, et cetera, appended as the image size. I want the actual size dimensions appended.
[/li]
[li] I don't always use the same divider to offset the image size. Sometimes I'm formatting file names for the web, other times for my own consumption at home, "File Name - 256x256.jpg" versus "filename_256x256.jpg".[/li][/ul]
My script button allows me to accomplish a varied number of tasks, with a single button, in a very automated way—answer four questions on-the-fly, and then execute against all selected images.

True, I didn't mean that your script was pointless, just that it's overkill if the sub-folder name is fixed, which seems to be the case for atazur (but not everyone, of course).

Having a flexible output path does indeed require something more complex, at least until when/if Opus lets us define variables in commands.

Those are indeed what I was looking for. The script is great and the short commands are also helpful (I overlooked the option to write =".\relative_path" so thanks for the lead).

I usually use scripts with user inputs (like kenalcock wrote) together with pre-defined commands for the most common task.

UPDATE: I have tried the script kenalcock wrote and I have noticed that it only converts 1 image (even if I select few and then run the command). any suggestions of why?

The command nudel wrote, works beautifully. thanks!

Hmmm... Strange it's working flawlessly on my PC. Are you running Windows XP?

Try downloading the attached toolbar button, maybe the wrapped text above plays a role.

EDIT: You just drag the file to your toolbar in Customize mode.
Resize to Folder.dcf (4.06 KB)

[quote]CreateFolder "800x600"
Image CONVERT ADDSUFFIX HEIGHT=600 WIDTH=800 PRESERVEASPECTRATIO TO=".\800x600"[/quote]

How do i combine this with adding to zip folder? All in one go?

[quote]CreateFolder "800x600"
Image CONVERT ADDSUFFIX HEIGHT=600 WIDTH=800 PRESERVEASPECTRATIO TO=".\800x600"
Select "800x600"
Copy ZIP
[/quote]
That doesn't work

This will do it:

CreateFolder "800x600" Image CONVERT ADDSUFFIX HEIGHT=600 WIDTH=800 PRESERVEASPECTRATIO TO=".\800x600" Copy FILE="800x600" ZIP HERE

That Works. Thanks!

I guess there's no way to go directly to a zip file, without creating an intermediary folder.

And if i wanted to i guess i could delete the folder after the zips done
DELETE FILE="800x600"

BTW, the zip somehow fails if the images already exist in the folder... i.e. the image convert doesn't work automatically (it prompts to replace ...etc).

This is strange...I"ve made a button with Leo's suggested commands:

CreateFolder "128x128" Image CONVERT ADDSUFFIX HEIGHT=128 WIDTH=128 PRESERVEASPECTRATIO TO=".\128x128"

However, the button doesn't seem to work. It creates the new folder, but it doesn't convert the images and nothing is sent to the newly created folder (the folder remains empty). Any ideas why this isn't working?

Never mind, I just figured it out. I needed to add "READAUTO=no" to the button command like so:

CreateFolder "128x128" READAUTO=no Image CONVERT ADDSUFFIX HEIGHT=128 WIDTH=128 PRESERVEASPECTRATIO TO=".\128x128"

However, I'm not exactly sure why the previous code worked for others and why I need to add "READAUTO=no" to get it to work. Maybe it's something in the settings...

FWIW it seems to work okay for me in Opus 9.1.1.7.

Below is a screenshot of the button to compare against. Maybe something other than the command is different, e.g. the function type?

In case you're expecting it to do something different, the button works on the selected files. I don't think it'll work if you select a sub-folder for conversion, and you need to have something selected (i.e. it won't do everything in the current folder by default if nothing is selected).

It may also only work on BMP, GIF, JPEG and PNG files. It doesn't specify a type for the output files so it will use the same type as each input file, and those four types are the only ones Opus can output. If your input files are a different type, change CONVERT to CONVERT=jpg and see if that helps.

It's still a mystery...my button setup is exactly like your screen shot. I attempted to use the button on jpg files so that wasn't it. I'm not sure if this is related but in my preferences I have "Automatically sort new and modified files" unchecked. Could it be that the second "convert" command in the button can't execute because it can't read the newly created folder? Not sure but I'm glad I found a workaround :slight_smile:

I forgot to mention that when the original button didn't work, I thought of adding "READAUTO=yes", tried it, but it didn't work. Surprisingly though the "READAUTO=no" does work - I really don't see how that makes sense given that logically we should force DOpus to read the newly created folder automatically.

Just in case, perhaps you could show us a screenshot of your button config in case you're not seeing something.

Additionally, are you using the latest version of Opus ?

Here's the screen shot. I'm on Opus 9.1.1.7

This is the button that now works - the original that didn't work is exactly the same just with the "READAUTO=no" omitted.

Sorry about forgetting the READAUTO=no -- yes, you will need that if you've got Opus set to read the created folder automatically by default. (For the command to work it needs to stay in the current directory, else ".\Thumbnails" won't be the right path>)

You're not running the command in flat-view mode, or in something other than a normal directory, are you? Those are the only things I can think of that might break it (though it may work there too).

I haven't tried the button in flat view mode yet, but in all other views it works great. I'm not exactly sure though where the "read folders automatically" preference option is located. If you are referring to the "Automatically sort new and modified files" option, then I have that unchecked. I don't see another option though in the preferences to automatically read folders...if in fact this is a separate option than the one I mentioned above, could you point me to the location of it because I guess it affects DOpus globally and it would be helpful to know.

The auto read option is built into the CreateFolder dialog. Which you will see if you use the default toolbar's CreateFolder button.