I don't know if you are familiar with AutoHotkey -
http://autohotkey.com - but you can read and edit images using GDI+
Luckily there is a library for that which makes things a lot easier.
I'm not very familiar with it but this is a proof of concept, still flawed, but should get you going.
You need:
- AutoHotkey, you can download it at
http://autohotkey.com - it is a familiar program to many Donationcoders.
- You also need the GDI+ library, you can get at the links in the script below
- I also had to add the missing crop function, luckily Learning One made one so I copied it below
The demo script below almost works. I'll explain what it does:
- It reads/opens the image
- It gets the dimensions of the image, we need to know its height
- Then it reads the color of the pixels starting at the bottom of the image, that is why we needed the height
- If the pixel is white, move one pixel up, get the color and so on
- Once we find the first non-white pixel: bingo we now know how many pixel to crop from the bottom
- Crop the number of pixels from the bottom
- Save it to a new image
At the moment it looks for pixels that are 100% white. As you will notice that isn't a 100% accurate because it will "stop" reading pixels at a nearly white pixel. So there are things that would need to be fixed: a) it is probably better to look for a black pixel - if there is always a black border that is, and b) also take into account some variations of the color values of the pixel just to be sure.
Once you've got it working for one image, it is just matter of wrapping it in a loop, run the script, grab some coffee and lean back :-)
As you can see it stopped a bit to early as the pixel it found wasn't 100% white.
Batch-edit images (remove frames); get http://autohotkey.com
; https://www.dropbox.com/s/0e9gdfetbfa8v0o/Gdip_All.ahk if you have 64bit/unicode ahk
; or https://autohotkey.com/boards/viewtopic.php?t=6517 for others
; 4294967295 = 0xFFFFFFFF = white
pToken := Gdip_Startup()
pBitmap := Gdip_CreateBitmapFromFile("demo.jpg")
Gdip_GetImageDimensions(pBitmap,width,height)
Loop, % height
{
If (Gdip_GetPixel(pBitmap, 1, height-A_Index) <> 4294967295)
{
down:=A_Index
break
}
}
MsgBox % down
pBitmap2:=Gdip_CropBitmap(pBitmap, 0, 0, 0, down)
newfile:=A_ScriptDir "\demo2.png"
Gdip_SaveBitmapToFile(pBitmap2, newfile)
Gdip_Shutdown(pToken)
MsgBox Done
#include Gdip_All.ahk
; https://autohotkey.com/board/topic/29449-gdi-standard-library-145-by-tic/page-58
Gdip_CropBitmap(pBitmap, left, right, up, down, Dispose=1) { ; returns cropped bitmap. Specify how many pixels you want to crop (omit) from each side of bitmap rectangle. By Learning one.
Gdip_GetImageDimensions(pBitmap, origW, origH)
NewWidth := origW-left-right, NewHeight := origH-up-down
pBitmap2 := Gdip_CreateBitmap(NewWidth, NewHeight)
G2 := Gdip_GraphicsFromImage(pBitmap2), Gdip_SetSmoothingMode(G2, 4), Gdip_SetInterpolationMode(G2, 7)
Gdip_DrawImage(G2, pBitmap, 0, 0, NewWidth, NewHeight, left, up, NewWidth, NewHeight)
Gdip_DeleteGraphics(G2)
if Dispose
Gdip_DisposeImage(pBitmap)
return pBitmap2
}
/*
;Examples:
pCroppedBitmap := Gdip_CropBitmap(pBitmap, 10, 10, 10, 10) ; crops 10 pixels from each side of bitmap rectangle. Disposes of pBitmap.
pCroppedBitmap := Gdip_CropBitmap(pBitmap, 50, 50, 0, 0) ; crops 50 pixels from left and right side of bitmap rectangle. Disposes of pBitmap.
pCroppedBitmap := Gdip_CropBitmap(pBitmap, 0, 0, 77, 77, 0) ; crops 77 pixels from upper and lower side of bitmap rectangle. Does not dispose of pBitmap.
*/
esc::ExitApp