Skip to main content
leol30
Known Participant
July 4, 2021
Answered

Bridge (or Photoshop) script to check JPGs and move the JPGs with a white border to another folder

  • July 4, 2021
  • 2 replies
  • 4563 views

Hi

 

I often have 1000s of photos in a folder, some with white borders and some without. I'd like to be able to run a script that would check and move the bordered photos to another directory.

 

I've searched the community (and the interweb) but the results get clouded with methods for creating white borders so I've not had any luck finding a discussion that might help me. Has anyone seen a post or script that could help me.

 

Thanks in advance for any help/advice that can be given, Leo

This topic has been closed for replies.
Correct answer Kukurykus

Now I've had time to test the code on batches of JPGs I've realised that checking the corner pixels not only moves photos with white borders on four sides but also photos with white borders on two sides (see attachments below). I think, checking pixels at the mid point on each side would get round this issue. I tried dividing some of the variables by 2 to get a mid point but that didn't work. Not surprising as my understanding of how the code works is very limited. Is it possible to tweak your code to check pixels at the mid-point of the four sides?


In new, accelerated version change:

 

bd = new BitmapData(shft = fls.shift())
for(j = 0; j < (arr1 = [0, bd.height]).length; j++) {
	for(i = 0; i < (arr2 = [0, bd.width]).length; i++) {
		if (bd.getPixel(arr2[i], arr1[j]) - 16777215) continue lab
	}
}

 

to:

 

bd = new BitmapData(shft = fls.shift()), arr = [[0, hh = (h = bd.height)
/ 2], [wh = (w = bd.width) / 2, 0], [wh, h], [w, hh]]; while(arr.length) {
	if (bd.getPixel((cell = arr.shift())[0], cell[1]) - 16777215) continue lab
}

 

2 replies

Stephen Marsh
Community Expert
Community Expert
July 4, 2021

I believe that the Bridge script would need to use Photoshop to open and check the images, then return the result to Bridge for adding to a collection, or applying a label or keyword etc.

 

I just had a play in Photoshop, open an image, make a 1px aliased selection border from the canvas edges, copy selection content to new layer, check that the histogram of the active layer has a mean/median value of 255.

 

Or four colour samplers could be set at each corner to check if each value was 255.

 

I'd think that the easiest way would be to do this in Photoshop, then manually move the files in Bridge after sorting or filtering based on metadata added to the files from Photoshop.

 

Perhaps upper left and lower right check for white would be better than one corner, but faster than four corners?

 

Edit: I see that @Kukurykus has replied, so perhaps it is possible to check for white in Bridge without having to go to Photoshop.

 

leol30
leol30Author
Known Participant
July 4, 2021

Thanks for you reply. I'm testing the Bridge script that Kukurykus has supplied.

Stephen Marsh
Community Expert
Community Expert
July 4, 2021

Yes, we posted 1 minute apart, there was no reply when I started my reply, then there was! I'm glad that Kukurykus sorted you out, my approach would have taken more work. 

Kukurykus
Legend
July 4, 2021

With Bridge script you might check colour of top left pixel. If it is white a .jpg is going to be moved out.

leol30
leol30Author
Known Participant
July 4, 2021

 

Thanks for the reply. Yes, I was thinking that the script would need to check a pixel in four places - top left & right and bottom left & right, if all the pixels are white the photo would be moved. But my scripting skills are limited. I don't know the code for identifying a specific pixel or how to check the colour of a pixel. Any help would be appreciated.

Kukurykus
Legend
July 4, 2021

Originally I wanted to suggest exactly 4 corners as well, but then realised maybe it's not needed if the rest of images wouldn't be white in first corner. The below code save in .jsx format to: C:\Program Files\Common Files\Adobe\Startup Scripts CC\Adobe Bridge 2021

 

fourWhiteCorners = new MenuElement('command', 'White Corners',
'at the end of Thumbnail'), fourWhiteCorners.onSelect = function() {
	Folder(fldr = (pp = app.document.presentationPath) + '/wht/' ).create()
	fls = [].slice.call(File(pp).getFiles('*.jpg')); lab: while(fls.length) {

		bd = new BitmapData(shft = fls.shift())
		for(j = 0; j < (arr1 = [0, bd.height]).length; j++) {
			for(i = 0; i < (arr2 = [0, bd.width]).length; i++) {
				if (bd.getPixel(arr2[i], arr1[j]) - 16777215) continue lab
			}
		}

		shft.rename(fldr + shft.name)
	}
}

 

After you relaunch Bridge (and prehaps confirm loading of new script) go to folder with your jpg files. Then right click at Content space or specific thumbnail of its area and select last item.