Batch Combine Large and Small Version of same image? - RealWorld forums

Log-in or register.

Batch Combine Large and Small Version of same image?

Icon Editor Question
kunkel321
on October 27th 2012

Hi Vlastimil,
I'm the one you were helping over on the DC forums...
http://www.donationcoder.com/forum/index.php?topic=32545.0
Thanks again for the help--Normalize Icon v2 works great!

Another Batch Question: Is there a script (or any other way) that makes it possible to combine separate PNGs of the same name into ICOs?

For example, given the following folders and contents:

Folder_of_16_x_16s/star.png
Folder_of_16_x_16s/arrow.png
Folder_of_16_x_16s/shield.png

Folder_of_32_x_32s/star.png
Folder_of_32_x_32s/arrow.png
Folder_of_32_x_32s/shield.png

I could drag both folders into the RW batch tool and RW would create
star.ico
arrow.ico
shield.ico

With the different sized combined correctly.
What do you think?

Vlasta
on October 28th 2012

Hi,

well, I suppose it would be possible to create script for this, let me think about it for a while.

If you did not need the batch functionality, the editor is able to assemble a single icon from multiple image files. When you create a new icon with no images and then drag and drop images (one by one or more at once) to the initially empty list of images, they will be added to that icon. If you don't have too many icons, it may be faster to do it this way. It would be also faster if you had images belonging to one icon in one folder and not in multiple folders categorized by size.

kunkel321
on October 28th 2012

Hi Vlastimil,
Thanks for the reply. Really it's the batchwork I'm interested in. Over the years I have refined my icon creating process. My current method is to use DrawPlus (similar to Photoshop) to create the actual images, mostly with vector parts. I line them up and combine-and-export as one large PNG. For example if I have 100 icons and I want to make 32x32 icons, I'd "group" them, then crop them to h=32pix/w=3200pix and export as a PNG. Then I'd use the cool little program TileMage to chop the PNG into 100 pieces. In the past I've used IcoFX to bulk-convert them into ICOs... Real World Icon Editor has now taken the place of IcoFX though. So my thought is that I'd start making high- and low-rez versions of the icons in DrawPlus, then I'd export both (e.g. a 32x3200 one and a 16x1600 one) and combine them. Of course in reality They wouldn't be named "star, arrow, shield," it would be more like "img01, img02, img03." And also I usually make my images 128x128, then let the icon editor reduce them.
I guess maybe having RW compare names in order to find matches would require some extra indexing (?), so it might be easier to require (from the user) that all the images be in the same folder and in the order:
img01_16.png
img01_32.png
img02_16.png
img02_32.png
img03_16.png
img03_32.png
RW could maybe use everything before the underscore as the name of the file, and everything after as indicator for the sub image…
Don’t stress yourself out trying to make a script for this… It was really a “what if…” idea as much as anything. However if you do try to script this, consider allowing the user to include many versions of the same icon (not just two). E.g. “img01_16, img01_32, img01_64, img01_256.”
I should point out that I'm not a professional designer, I just like to make sets and share them. FYI here is a set that you can use or post if you want. https://docs.google.com/file/d/0BwtnO53TpftPLTlvQmk2enZlb1U/edit
They were actually made to match a custom skin I made for xplorer2 (read about my custom skin here http://netez.com/bbs/viewtopic.php?t=8827 ). The skin was never particularly popular, so the above icons are not particularly associated with xplorer2. Still though, I did get permission from Nikos, over there, before sharing with other sites. They are all ones made by me, though a few are either converted images or replications of standard Windows icons.

Vlasta
on October 28th 2012

OK, I think I understand the problem better now. You want to design multiple images for a single icon to separately optimize for large and small resolutions. That makes sense, I should probably change the editor to deal with this scenario out of the box.

But let's take a step back. The scenario may look like this: you design image#1 and image#2 for a single icon and you want to generate 256x256, 128x128, 48x48, 32x32 images from image#1 and 24x24 and 16x16 images from image#2 and put it all in a single .ico file, right?

I am thinking about what will be the best approach. Maybe it would be best to first create partial .ico files with larger and smaller images using the current batch operations and then merge the .ico files with a custom batch operation. What would you think about that? Using folders or underscore in names is more or less the same from programming perspective.

Your icons are very good and there is a lot of them - I should probably implement batch uploading to the icon gallery on this web via a .zip file - uploading them one by one would be a nightmare.

Anonymous
on October 29th 2012

Yes, that's correct. Though probably it would more common for people to generate 256x256, 128x128, 48x48, 32x32 and 24x24 images for image#1 and only 16x16 for image#2, then combine.

I have, however, also seen work where there are three or four different versions. Usually the 48+ ones are the full detail ones; the 24 and 32s have fewer details and relatively thicker lines, but still are 3D in the sense of 3-point linear perspective; then the 16 is flat (non-3D).

Converting to ICO files, then combining as a separate operation makes sense to me!

RE out of box: It would definitely make sense to also have this (combining) ability in the dialog for "Create From Image." You already allow the user to define separate settings for the different sizes
http://i.imgur.com/A48qh.png
but currently this con only be done for separate versions of the same image.

kunkel321
on October 31st 2012

As it turns out, I found a perfect candidate for "combining."
Check out this set http://www.fatcow.com/free-icons The good people at fatcow.com made the set free to use. They offer 16x16 and 32x32 versions (as PNGs) but they don't offer a combined ICO version... I wonder if it is because there was no tool on the market to batch combine them? (there are 3000 images...

Vlasta
on November 2nd 2012

OK, here is the script: combine-icons.rwbatchop

It is somewhat atypical, because you need to set the destination folder in the configuration. The reason for this is that the script cannot use the standard Save to destination folder step, because it needs to access the files in the destination folder while processing (to be able to combine the current .ico file with the new images). If you want to use the default destination folder, you need to find the address of your temp folder and append RWIE to it. The quickest way to do that is to open My Computer and type "%TEMP%\RWIE" into the address bar and then copy the real path from the address bar. For me, on Win7, it is C:\Users\Vlasta\AppData\Local\Temp\RWIE.

The other parameter of the script is a list of separator characters. By default, it is set to _ (underscore). All files that have the same file name up to first separator character will be combined into a single icon. So, if you leave this field on default value and throw files icon1_16.png, icon2_16.png and icon1_32.png on it, it will create 2 icons: icon1.ico (from icon1_16.png and icon1_32.png) and icon2.ico from icon2_16.png). If the images to be combined have the same names and are in different folders, this field can be left empty.

Note that the script will accept both image files and icon files already containing multiple images. E.g. you can freely combine .png, .ico, .jpg, .bmp, ... If the icon in the destination folder already contains image of the same size as the image being added in the current step, it will be overwritten.

Anonymous
on November 4th 2012

Hey thanks! So far all of these scripts you've put together seem to work flawlessly! I want to experiment some more, but also wanted to post a response... I've tried it on Vista and on Win 7, feeding both PNGs and ICOs into it. On both computers, it will happily use C:\TEMP, if I don't specify another folder. I'm surprised how fast it is. I experimented with the above-mentioned Fatcow set, and RWIE is able to zip through the set even faster than Windows is able to move, delete, or copy-n-paste the set of 3000!

My goal now is to re-make my set as low-detail 16x16s.... I'm actually finding it harder to do than I anticipated! I might just use old-fashioned raster-style drawing, rather than trying to rework all my vector pieces.... Will post more later.

Thanks again Vlastimil! :-)

kunkel321
on February 12th 2019

Hi Vlasta,
It's been a long time since you wrote this batch operation. I don't know if you're even still around, but if you are, can you help with this error?

I have the images:
blue-1_16.png
blue-1_32.png
blue-2_16.png
blue-2_32.png
and so on.
They are in the same folder. If I run the batch operation, I get "Object doesn't support this property of method."
screenshot
https://i.imgur.com/P6hEyWS.png

For reference, I'll paste the code below.
I'm using Windows 10 and RWIE 2016.1.
Any ideas? -Steve

// place your custom JavaScript code here
var path = Configuration.path;
if (path.charAt(path.length-1) != "\\")
	path += "\\";
var separators = Configuration.separators+".";

// obtain .ico filename
var basename = Document.Name;
for (var i = 0; i < basename.length; ++i)
{
	var stop = false;
	for (var j = 0; !stop && j < separators.length; ++j)
		stop = basename.charAt(i) == separators.charAt(j);
	if (stop)
	{
		basename = basename.substring(0, i);
		break;
	}
}

// open the previous icon or create a new icon
var prev = Application.OpenDocument(path+basename+".ico");
var prevIcon = null;
if (prev) prevIcon = prev.Icon;
if (prevIcon == null)
{
	var newIco = Application.CreateWizard("1EA02660-391E-484F-B1E0-3154F28C28BD");
	newIco.Type = 0; // no initial images
	prev = Application.CreateDocument(newIco);
	prevIcon = prev.Icon;
}

if (Document.SupportsFeature("RasterImage"))
{
	var image = Document.RasterImage;
	if (image.SizeX > 256 || image.SizeY > 256)
	{
		Context.ErrorMessage = "Invalid image size";
		Context.StopProcessing(false);
	}
	var newFormat = prevIcon.CreateFormatID(image.SizeX, image.SizeY, 32);
	prevIcon.InsertImage(newFormat);
 	var newImage = prevIcon.GetImage(newFormat);
	Blender.Compose(newImage, 0, 0, image.SizeX, image.SizeY, image, 0, 0, 0, Blender.OpSrc);
}

if (Document.SupportsFeature("Icon"))
{
	var icon = Document.Icon;
	var formats = icon.FormatIDs;
	for (var i = 0; i < formats.length; ++i)
	{
		var format = formats[i];
		prevIcon.InsertImage(format);
		var newImage = prevIcon.GetImage(format);
		var image = icon.GetImage(format);
		Blender.Compose(newImage, 0, 0, format.SizeX, format.SizeY, image, 0, 0, 0, Blender.OpSrc);
	}
}

prev.SaveCopyAs(path+basename+".ico");

EDIT: Forgot to mention, I tried it starting with PNGs and also tried starting with ICOs. Each had the same error.

EDIT 2: I guess that it would also be excellent if the batch operation could instruct RWIE to remove/crop the blank pixels from around the large images. My (above) post suggest 32x32 images, but I'm actually using 128x128.

Vlasta
on February 12th 2019

Do you have an "Assemble icon" in your list of batch operations?

If not it should have this code:

var path = Context.GetState("OutputFolder");
if (path.charAt(path.length-1) != "\\")
	path += "\\";
var separators = Configuration.separators+".";

// obtain .ico filename
var basename = Document.Name;
for (var i = 0; i < basename.length; ++i)
{
	var stop = false;
	for (var j = 0; !stop && j < separators.length; ++j)
		stop = basename.charAt(i) == separators.charAt(j);
	if (stop)
	{
		basename = basename.substring(0, i);
		break;
	}
}

// open the previous icon or create a new icon
var prev = Application.OpenDocument(path+basename+".ico");
var prevIcon = null;
if (prev) prevIcon = prev.Icon;
if (prevIcon == null)
{
	var newIco = Application.CreateWizard("1EA02660-391E-484F-B1E0-3154F28C28BD");
	//newIco.Type = 0; // no initial images
	prev = Application.CreateDocument(newIco);
	prevIcon = prev.Icon;
	var fmts = prevIcon.FormatIDs;
	for (var i = 0; i < fmts.length; ++i)
		prevIcon.DeleteImage(fmts[i]);
}

if (Document.SupportsFeature("RasterImage"))
{
	var image = Document.RasterImage;
	if (image.SizeX > 256 || image.SizeY > 256)
	{
		Context.ErrorMessage = "Invalid image size";
		Context.StopProcessing(false);
	}
	var newFormat = prevIcon.CreateFormatID(image.SizeX, image.SizeY, prevIcon.RGB22A8);
	prevIcon.InsertImage(newFormat, image);
}

if (Document.SupportsFeature("Icon"))
{
	var icon = Document.Icon;
	var formats = icon.FormatIDs;
	for (var i = 0; i < formats.length; ++i)
	{
		var format = formats[i];
		prevIcon.InsertImage(format, icon.GetImage(format));
	}
}

prev.SaveCopyAs(path+basename+".ico");
kunkel321
on February 13th 2019

Thank you kind Sir!
Yes, there is already a batch operation, "Assemble icon."
Hmmm... It wasn't working for me earlier, but I just re-tried it, and it worked... User error I guess. Sorry about that!

Page views: 5391       Posts: 11      
You cannot reply to this topic.
Vista & Win 7 icons
I wish there were...
Select background