Mass Photo Shrink
Blitz3D Forums/Blitz3D Beginners Area/Mass Photo Shrink
| ||
Does anyone know of a program to shrink the file-size of photos. I have 27 4MB photos that are being loaded as sprites, and it goes really slow. |
| ||
Compress them, perhaps another format such as JPG or PNG or resize the images themselves? Cooolsoft's Advanced Batch Converter can convert, resize/rescale and much much more. Why do many sprites? Perhaps it might be easier to change your program a bit to manage the loading better, Do you really NEED ALL 27.4Mb worth in memory at the same time? |
| ||
If you convert/compress in another format ( PNG is best for lossless compression ) then they will take less disk space but they will still take up the same memory as a BMP equivalent. Best to resize them all. Stevie |
| ||
If you convert/compress in another format ( PNG is best for lossless compression ) then they will take less disk space but they will still take up the same memory as a BMP equivalent. Good point, yes. You can easily resize the actual images yourself with a couple of Blitz functions: Just call: ProcessImageBatch("DIRECTORY PATH") and the program should resize all valid image files within that directory folder. Const MaxWidth=800 Const MaxHeight=600 Function ProcessImageBatch(Directory$="") If (Directory$="") Directory$=CurrentDir$() End If If (Right$(Directory$,1)<>"\") Directory$=Directory$+"\" End If If (Not(FileType(Directory$)=2)) RuntimeError Directory$+" is not a valid directory" End If Local ScanDir%=ReadDir(Directory$) Local FullPath$ Local Extension$ Local Temporary% Local CountProcessed%=0 Local ImageFile$=NextFile$(ScanDir) While (ImageFile$<>"") FullPath$=Lower$((Directory$+ImageFile$)) If (FileType(FullPath$)=1) And (Right$(ImageFile$,1)<>".") Extension$=GetExtension$(ImageFile$) ;Edit these extensions as necessary If ((Extension$="bmp")+(Extension$="jpg")+(Extension$="jpeg")+(Extension$="png")) DebugLog "Processing: "+ImageFile$ Temporary%=LoadImage(FullPath$) ScaleImageToProportion(Temporary) SaveBuffer(ImageBuffer(Temporary),Left$(FullPath$,Len(FullPath$)-(Len(Extension$)+1))+".bmp") CountProcessed%=CountProcessed%+1 End If End If ImageFile$=NextFile$(ScanDir) Wend RuntimeError Str$(CountProcessed%)+" Images Processed." End Function Function GetExtension$(FileName$) If ((Not(Instr(FileName$,"."))) Or (FileName$="")) Return "" End If Local nCount For nCount = Len(FileName$) To 1 Step -1 If (Mid$(FileName$,nCount)=".") Return Right$(Lower$(FileName$),Len(FileName$)-(nCount+1)) End If Next Return "" End Function Function ScaleImageToProportion(Image%) Local Width%=ImageWidth(Image) Local Height%=ImageHeight(Image) Local ImageFormat=(Width>=Height) Local RatioWidth#=Float(Float(Width) / Float(MaxWidth)) Local RatioHeight#=Float(Float(Height) / Float(MaxHeight)) If (Width>=Height) RatioHeight#=RatioWidth# Else RatioWidth#=RatioHeight# End If Local NewWidth#=Float(Float(Width)/RatioWidth#) Local Newheight#=Float(Float(Height)/RatioHeight#) DebugLog Str$(Width%)+" x "+Str$(Height%) DebugLog "Resized to:" DebugLog Str$(Int(NewWidth))+" x "+Str$(Int(Newheight)) DebugLog "--------------" ResizeImage Image,NewWidth#,Newheight# End Function If you intend to use this, I recommend testing it on a couple of copies of images first, just in case. I dont want to be responsible for ruiining your holiday snaps or anything :D |
| ||
OK, I'm trying that out now. Yes, I need all 27 sprites at once, but I want an easy way to shrink the photo size (width and height) to save space and load time. EDIT: Didn't work |
| ||
In case you were wondering, This is what is was doing, and I single-handedly (OK, I used 2 to type) used more RAM than FireFox. By shrinking the photos by hand, It now takes less RAM than FireFox :) Notice how it uses my much enjoyes 3D Movement Keys UserLib :) LOL |
| ||
EDIT: Didn't work That's not very informative... Did it give an error on runtime or not compile? Did you put in the correct directory path into the function, I assume something like ( WHATEVERDIRECTORY YOUR APP IS IN + "ph\" ) and check the "Maxwidth" ansd "MaxHeight" values to suit your needs? I defaulted them to 800x600 but that may still be too big. |
| ||
It just said 0 converted. Don't need it anymore, did it by hand, but thanks so much for your help. If I ever need it again, I'll dig this back out and try it again. Thanks Again, AJ00200 |
| ||
I found another time to use it, and it still doesn't work. It just keeps givinge same error, 0 Images converted. I checked the width and height values, I have a full path C:\..., and I did a bit of troubleshooting myself, but it just won't work. PS, I'm using *.JPG Files if that matters. |
| ||
I'm sure blitz only saves .bmp files, so you'd need to use a lib like freeimage, to save them as .jpg's |
| ||
Oh, Ok. That helps alot. Thanks Ross. |
| ||
Or you could use something like irfanview which has batch image processing ability. |