ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

Batch-edit images (remove frames)

<< < (2/3) > >>

tomos:
[..] some pictures are in 'standing mode' while others ''lie down'' (not sure how to put that in english, hoping you still understand what  I mean).-n8wachT (November 29, 2015, 01:35 PM)
--- End quote ---

nice way of putting it (and very understandable) -- 'Portrait' and 'Landscape' would be the terms used
('Hoch' and 'quer' auf deutsch if that's any help).


Are your images different sizes?
Are the frames/margins always the same width?
-tomos
--- End quote ---

Sadly there aren't a lot of constant factors. The only thing we can see as an certainty is that the white frame is always located at the bottom of the picture. But it can vary in width cause some pictures are in 'standing mode' while others ''lie down'' (not sure how to put that in english, hoping you still understand what  I mean).

And.. besides those differences the pictures are also in various sizes as an whole. So I already figured that wasnt the best outcome for an coding adventure... right?
-n8wachT (November 29, 2015, 01:35 PM)
--- End quote ---

it might possibly be of help that the margins are all white -- but I wouldn't know as I dont know anything about coding myself...
But the IrfanView route would not work AFAIK if frame width varies a lot.

kunkel321:
I was also going to suggest IrfanView.  Also, RealWorld Icon Editor has some advanced batch capabilities. 


Edit:  Very cool AutoHotkey script down there!!!

Lintalist:
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

Jibz:
Using mogrify from ImageMagick (overwrites original), removing borders that are within 3% of the corner colors:


--- ---mogrify -trim -fuzz 3% demo.png

4wd:
XnView - Batch processing using Auto crop

Batch-edit images (remove frames)

Before:
Batch-edit images (remove frames)

After:
Batch-edit images (remove frames)

If you want to do it from the command line, you can use nconvert which is part of XnView, this is for a single folder:


--- Code: Text ---for /f "usebackq" %a in (`dir K:\ /b *.jpg`) do ("C:\Program Files (x86)\XnView\nconvert.exe" -autocrop 70 245 245 245 %a)
This will recurse a whole directory tree:


--- Code: Text ---for /r K:\ %a in (*.jpg) do ("C:\Program Files (x86)\XnView\nconvert.exe" -autocrop 70 245 245 245 %a)
nconvert is non-destructive by default, the original images will not be replaced, you'll end up with <name>_<number>.jpg in the same folder as the original.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version