I recently had a folder full of jpg and png images that I wanted to reduce in size (the file sizes, not the image dimensions). There were about 850 images totaling about 56MB. I did a quick Google search and found OS X Preview could change the image dimensions pretty easily and maybe even save the files in a different format, but not if they were different formats to start with.
But silly me, this is the perfect thing for Xojo. And in fact, it only took 10 lines of code. I just created a new desktop project and dragged a button onto the Window. In its Action event I added this simple code:
// Prompt for folder containing pictures Dim f As FolderItem = SelectFolder If f Is Nil Then Return // Create new folder to create resized pictures Dim newFolder As FolderItem = f.Parent.Child("ResizedPictures") newFolder.CreateAsFolder // Go through each original picture, resize it // and save it to the new folder For i As Integer = 1 To f.Count Dim newPicFile As FolderItem = newFolder.Child(f.Item(i).Name.Replace(".png", ".jpg")) Dim p As Picture = Picture.Open(f.Item(i)) p.Save(newPicFile, Picture.SaveAsJPEG, Picture.QualityHigh) Next MsgBox("Pictures converted to high-quality JPEG.")
If you don’t count the comments, that’s just 10 lines. This code simply loops through the folder and opens each file as a Picture and then re-saves it to a new folder as a high-quality jpg. There’s no error handling, so the original folder better only contain pictures, but in my case I only needed to do this one time and I knew the folder only had pictures.
Running this code on the folder took a couple seconds and the folder size dropped to 25MB with no noticeable loss in the quality of the images (they were all pretty small) and also removed a few duplicates as well.
Making this Xojo app took me less time than I spent than searching Google and the App Store!
Watch the 2-minute video to see how easy it is: