Image size

Post

Posted
Rating:
#1 (In Topic #1576)
Avatar
Guru
cogier is in the usergroup ‘Guru’
Is there a way in Gambas to reduce the file size of an image/picture without shelling?
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
Save as jpeg not png

Or use picture.save compression/quality settings.
Read wiki on how the quality option works as it different for different file types.

I found a long time ago that saving a screenshot for the mailing list as png will not send as there's a file size limit. Save as jpeg though and all is okay <EMOJI seq="1f60a" tseq="1f60a">😊</EMOJI>
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
 Like this perhaps…
Picture.Load(sPath).Save(sPath, 0)

Re quality settings: for jpeg it affects quality for png it affects compression.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Expert
Poly is in the usergroup ‘Expert’
Wow , thanks cogier for the question and thanks @Bruce for your knowledge ;)

I didn't know about this, and happy to learn something "new"  :D

/comp/gb.qt4/image/save - Gambas Documentation
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Guru
cogier is in the usergroup ‘Guru’
Thanks Bruce. I have discovered that saving 101 images as .png is SLOW!!. I got much better results with .jpg files. This is the code I used for testing: -

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3. Dim pPict As Picture = Picture.Load(Application.Path &/ "TestJPG.jpg")
  4. Dim sPath As String = User.Home &/ "tmp"
  5.  
  6. For iLoop As Integer = 0 To 100
  7.   pPict.Save(sPath &/ "Test" & Format(iLoop, "000") & ".jpg", iLoop)
  8.  

Interestingly, just saving a 6.2MB .png as a .jpg reduced the file size to 1.5MB.

The Quality part of Sub Save ( Path As String [ , Quality As Integer ] ) seems to be logarithmic. The image below shows the value (Quality) used, the new file size in kb and the percentage of the original picture.

<IMG src="https://www.cogier.com/gambas/PictCompression.png"> </IMG>
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Guru
cogier is in the usergroup ‘Guru’
It makes no sense. I tried the above code with a 2.4MB .jpg file and this time I finished with a file size of 5.7MB, which is over twice as large as the original!

<IMG src="https://www.cogier.com/gambas/PictCompression2.png"> </IMG>
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’
 i looked up jpeg quality and from what i can tell "medium" quality is considered between 80%-90%
so higher must be adding data.

I remember having this issue once when i was loading and saving an image.

png may be slower but png is "lossless" so possibly the best way to get the smallest file with no loss of quality.
Online now: No Back to the top
1 guest and 0 members have just viewed this.