Very simple Icon maker example

So you have written that new, must have program. Let us see it here.
Post Reply
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Very simple Icon maker example

Post by BruceSteers »

A very very simple tool to make Icon files from any supported image.
Hardly any code.
Browse image folders with the FileChooser in preview mode,
Select an image, see an icon preview.
Set size from 16x16 to 128x128
Save as an icon file.
Shimples
:)

Simply uses image object to stretch image and save as icon by simply using the .ico ext
Commented code for beginners.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
PJBlack
Posts: 184
Joined: Tuesday 9th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: Very simple Icon maker example

Post by PJBlack »

another really nice one ... and works fine :D but if the original format is not a square then the result is maybe not soooooooooo nice ... is there a possibility to clip the original?
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Very simple Icon maker example

Post by cogier »

Interesting work. I can see a use for this. I found the layout not very good on Mint. So I had to tweak it! (An icon tool with no icon?!)
Attachments
IconifyCO-1.0.1.tar.gz
(94.63 KiB) Downloaded 324 times
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Very simple Icon maker example

Post by BruceSteers »

PJBlack wrote: Friday 18th September 2020 2:31am another really nice one ... and works fine :D but if the original format is not a square then the result is maybe not soooooooooo nice ... is there a possibility to clip the original?
Cheers.
This was less an official App and more a bit of fun/practice and a good project for an example for beginners.
I'll look into cropping, if the code won't be too complicated as it'll ruin my "simple" example if it is ;)

Aaaaaaand it's done ;)
It now crops.
wasn't too complicated a code change now i don't just make the iconbox's picture the picturebox picture i do this...
IconBox.Picture = MakeIconBox()

Code: Select all

Public Sub MakeIconBox() As Picture
Dim p As Picture, SmallSide, DifferenceHalved As Integer

If Not PictureBox1.Picture Then Return  ' no picture loaded so nothing to do
' If not in cropping mode or picture width and height are the same just return the picturebox picture
If (Not CropToggle.Value) Or (PictureBox1.Picture.Width = PictureBox1.Picture.Height) Then
  Return PictureBox1.Picture
Endif

' Find out the smallest dimention
SmallSide = Min(PictureBox1.Picture.Width, PictureBox1.Picture.Height)

If SmallSide = PictureBox1.Picture.Width Then
' width is smaller so we adjust height, a balanced/even sided crop wil be the difference divided by 2
DifferenceHalved = (PictureBox1.Picture.Height - SmallSide) / 2
p = PictureBox1.Picture.Image.Copy(0, DifferenceHalved, SmallSide, SmallSide).Picture
Else
' height is smaller so we crop width
DifferenceHalved = (PictureBox1.Picture.Width - SmallSide) / 2
p = PictureBox1.Picture.Image.Copy(DifferenceHalved, 0, SmallSide, SmallSide).Picture
Endif
Return p
End
Last edited by BruceSteers on Saturday 19th September 2020 11:06pm, edited 5 times in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Very simple Icon maker example

Post by BruceSteers »

cogier wrote: Friday 18th September 2020 3:51pm Interesting work. I can see a use for this. I found the layout not very good on Mint. So I had to tweak it! (An icon tool with no icon?!)
Fair enough. it's open source after all, do with it what you want m8, have your own version. :lol:
To be honest i didn't see much difference , still not right, just not right differently lol ;)

I also made some changes to the layout. took away the HSplit as was not needed
made the textarea do the stretching while the other objects remain the right size.
I prefer it like this.

I've also added a "Crop" mode to trim edges as requested,
Sorry moving the crop is not possible (yet), it will just crop edges off evenly either side of image (or top/bottom).
And found a funky icon
Last edited by BruceSteers on Friday 18th September 2020 7:42pm, edited 1 time in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Very simple Icon maker example

Post by BruceSteers »

So now it has stretch or crop mode...

Stretch..
Iconify stretch.png
Or Crop...
Iconify crop.png
Last edited by BruceSteers on Friday 18th September 2020 10:24pm, edited 1 time in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
PJBlack
Posts: 184
Joined: Tuesday 9th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: Very simple Icon maker example

Post by PJBlack »

you're absolutly crazy ...

big thanks for that ...
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Very simple Icon maker example

Post by BruceSteers »

PJBlack wrote: Friday 18th September 2020 9:43pm you're absolutly crazy ...

big thanks for that ...
haha well when you're on it you're on it :)

I've now added an offset slider to adjust/move the cropping :)
I also found HUGE images would work slowly with moving the crop/updating the image so if it loads an image with a width above 2048px it shrinks it down to a single multiple 1024 for speed.
:)
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Very simple Icon maker example

Post by BruceSteers »

Some final tweaking on this.
Have cleaned the code up a bit and added more comments to the new code.

for example calls like this...

Code: Select all

Dim i as ImageStat
i = ImageStat(CurrentFile)
If InStr(i.Type, "image/") = 0 Then
Blash Blah
Has been shrunk down and removed the need for defining an ImageStat variable like this...

Code: Select all

If InStr(ImageStat(CurrentFile).Type, "image/") Then
Blah Blah
I found a few little clean ups like that.

I also took Charlies good advice/tip on making the top image use "Contain" to show the true image dimensions and not stretch it to fit (good call m8 :) )

I also made it auto shrink all images loaded into PictureBox1 to between 512 and 1024px on load for speed.
(I figured with an ultimate max size of 128x128px it might as well)
It could be reduced further but i found it's fast enough like this.
Compiled it on the latest 3.15 with backward compatibility to 3.8 for best results.
Gonna get back to my other projects now :)
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Very simple Icon maker example

Post by BruceSteers »

added a couple of things..

Changed the save button to a menu button and added Save as other filetype option.
got a couple of defaults (png bmp) or you can type one manually. Supports any type the Image.Save() function does.

Also added my MakeIcon.module to make a desktop launcher/menu item
Download it here (don't want to keep adding files to the gambas one server and waste their storage)

http://bws.org.uk/Iconify.zip
If at first you don't succeed , try doing something differently.
BruceS
Post Reply