• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Participant ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

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

TOPICS
Batch , How to , Scripting

Views

983

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

LEGEND , Jul 04, 2021 Jul 04, 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(
...

Votes

Translate

Translate
LEGEND , Jul 05, 2021 Jul 05, 2021

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
}

 

Votes

Translate

Translate
LEGEND ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

 

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

Thanks for the script. I think I have followed your instructions correctly but I am getting an error message.

White Border Error Message.jpg

 I would like to check all fours corners as I only want to move photos with a white border on all four sides.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

I have tried the script in this folder with the same error message: C:\Program Files\Common Files\Adobe\Startup Scripts CC\Adobe Bridge 2021

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

I corrected script again as I found there little mistake, that sometimes code worked wrongly.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

Previously I updated post to let you run script described way, but forgot the code. Check now.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

Thanks, I am still getting the error message with the "new" code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

The error message is appearing as soon as I run Bridge so it's stopping the script from running.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

What error now? Maybe remove the script from Startup Scripts folder, launch Bridge, exit it, then save to StartupScripts folder (the path I provided to) the new one, but with other name.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

Our posts crossed. It's working now. Thanks for the script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

Apologies. The script is working now. I retraced my steps to make sure I was using the newest code. Thankyou very much for the script. Much apreciated.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

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
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

Thanks for the new mid-point code. It works really well. Another issue I hadn't thought about is that some of the borders are not perfect 255/255/255 white. The RGB seems to range from 250 to 255 in various combinations. But I'm very pleased that I can now move the majority to a new folder. Thanks again for your time and invaluable code. It will be used on a regular basis.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

For minimum 3 x 250 change:

- 16777215

to:

< 16448250

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

Thanks, very useful. A few rogue ones are getting moved so I'll play around with the decimal number to see what gives the best result.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2021 Jul 06, 2021

Copy link to clipboard

Copied

Likely the JPEG compression has added random minor colour value variations to the originally pure/clean white border.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 06, 2021 Jul 06, 2021

Copy link to clipboard

Copied

LATEST

I don't know the history of the photos. When I pixel poke they all look pure white with no obvious compression issues. However, even with a different colour on the border there is a chance that one white pixel has crept into the midpoint amongst the coloured pixels. I'm delighted with the script that Kukurykus has written and developed for me. It saves time and eye stress.  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 04, 2021 Jul 04, 2021

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

Although there is a correct answer, I'm still somewhat interested in hacking away at my original proposal. I think I'm almost there, however, I need the histogram to be reported based on the pixels in the current selection, not based on the entire image.

 

app.activeDocument.histogram;

 

So, how to get the histo value of the active selection?

 

Or perhaps the active layer, I don't believe that the following works?

 

app.activeDocument.activeLayer.histogram;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

I can't help with the histogram valve. Did you see my latest comment about checking the corner pixels. This method finds borders on 4 sides AND 2 sides (see photos). I think checking the mid-point pixel in the top row, bottom row, left column and right column may eliminate the 2 sided bordered photos.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines