Very simple Icon maker example

Post

Posted
Rating:
#1 (In Topic #462)
Banned
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.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
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?
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
cogier is in the usergroup ‘GambOS Contributor’
 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?!)

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#4
Banned

PJBlack said

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

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
Online now: No Back to the top

Post

Posted
Rating:
#5
Banned

cogier said

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
Online now: No Back to the top

Post

Posted
Rating:
#6
Banned
So now it has stretch or crop mode…

Stretch..
(attachment removed)

Or Crop…
(attachment removed)
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
 you're absolutly crazy …

big thanks for that …
Online now: No Back to the top

Post

Posted
Rating:
#8
Banned

PJBlack said

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.
:)
Online now: No Back to the top

Post

Posted
Rating:
#9
Banned
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

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

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 :)
Online now: No Back to the top

Post

Posted
Rating:
#10
Banned
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
Online now: No Back to the top
1 guest and 0 members have just viewed this.