//FFSubmenu=Tools
//FFName=Autocrop matched jpgs
DEBUG = false;
var CrLf = "\r\n";
var fso = new ActiveXObject("Scripting.FileSystemObject");
DoWork();
function DoWork()
{
// Namenszusatz für die zu speichernde Datei
var namenszusatz = ".fforig";
var tmp,hist,exi;
var imagenum = FF_GetImageCount();
if (imagenum == 0) {
FF_MessageBox("Keine Bilder ausgewählt",0);
return;
}
//** Start Dialog AutocropMatchedJPEGs **
FF_AddDialog("AutocropMatchedJPEGs",226,157);
FF_AddControl("AutocropMatchedJPEGs","ARJProgress","PROGRESS",2,143,223,12);
FF_AddControl("AutocropMatchedJPEGs","ARJImage","IMAGE",16,12,89,122);
FF_AddControl("AutocropMatchedJPEGs","ARJOutputName","STATIC",113,12,110,15);
FF_AddControl("AutocropMatchedJPEGs","ARJOutputMessage","EDIT",113,34,109,101);
//** End Dialog AutocropMatchedJPEGs **
FF_SetControlStyle("AutocropMatchedJPEGs","ARJOutputMessage",2048);
FF_OpenDialog("AutocropMatchedJPEGs");
FF_SetControl("AutocropMatchedJPEGs","ARJOutputMessage","");
// Alle Bilder müssen die gleiche Größe haben
var xsize, ysize, bc = 0;
// Bestimmung der Vereinigung der schwarzen Ränder => an alle 4 Seiten den größen schwarzen Rand finden
var topbarwidth = 0, bottombarwidth = 0, leftbarwidth = 0, rightbarwidth = 0;
for(var i = 0; i<imagenum ;i++) {
var path = FF_GetImageName(i);
var splitPath = SplitPath(path);
// Überspringen, was nicht nach Raw aussieht
if(splitPath.ext.toLowerCase() != ".jpg" &&
splitPath.ext.toLowerCase() != ".bmp" &&
splitPath.ext.toLowerCase() != ".png") {
continue;
}
if (i == 0) {
xsize = FF_GetImageWidth();
ysize = FF_GetImageHeight();
} else {
if ((xsize != FF_GetImageWidth()) || (ysize != FF_GetImageHeight())) {
FF_MessageBox("Bilder haben verschiedene Größe!",0);
return;
}
}
if (!FF_LoadImage(path)) continue;
// Bestimmung der Randdicke: vom Rand ins Zentrum laufen, bis pixel != schwarz
// Aber nicht in den ecken loslaufen! Da kann alles schwarz sein... Daher in der Mitte starten
var leftbar = 0, rightbar = 0, topbar = 0, bottombar = 0;
// left
while ((FF_GetPixel(leftbar, ysize/2) == bc) && leftbar<xsize)
{
leftbar++;
}
// right
while ((FF_GetPixel(xsize-rightbar, ysize/2) == bc) && rightbar<xsize)
{
rightbar++;
}
// top
while ((FF_GetPixel(xsize/2, topbar) == bc) && topbar<ysize)
{
topbar++;
}
// bottom
while ((FF_GetPixel(xsize/2, ysize-bottombar) == bc) && bottombar<ysize)
{
bottombar++;
}
if (DEBUG) FF_MessageBox("Links: "+leftbar+", Rechts: "+rightbar+", Oben: "+topbar+", Unten: "+bottombar, 0);
if ((leftbar == xsize-1) || (rightbar == xsize-1) || (topbar == ysize-1) || (bottombar == ysize-1)) {
// irgendwas stimmt nicht... ränder sind so groß wie das bild?
FF_MessageBox("Ränder könnten nicht bestimmt werden!" + CrLf + "Links: "+leftbar+", Rechts: "+rightbar+", Oben: "+topbar+", Unten: "+bottombar,0);
return;
}
if (leftbar > leftbarwidth) {
leftbarwidth = leftbar;
}
if (rightbar > rightbarwidth) {
rightbarwidth = rightbar;
}
if (topbar > topbarwidth) {
topbarwidth = topbar;
}
if (bottombar > bottombarwidth) {
bottombarwidth = bottombar;
}
}
if (DEBUG) FF_MessageBox("Ränder:" + CrLf + "Links: "+leftbarwidth+", Rechts: "+rightbarwidth+", Oben: "+topbarwidth+", Unten: "+bottombarwidth,0);
FF_SetControl("AutocropMatchedJPEGs","ARJOutputMessage",
"Breite: "+xsize+", Höhe: "+ysize +CrLf+CrLf+
"Ränder über alle Bilder:" + CrLf +
"Links: "+leftbarwidth+", Rechts: "+rightbarwidth +CrLf+
"Oben: "+topbarwidth+", Unten: "+bottombarwidth);
// Schleife über alle markierten Bilder
for(var i = 0; i<imagenum ;i++) {
var path = FF_GetImageName(i);
var splitPath = SplitPath(path);
// Überspringen, was nicht nach Raw aussieht
if(splitPath.ext.toLowerCase() != ".jpg" &&
splitPath.ext.toLowerCase() != ".bmp" &&
splitPath.ext.toLowerCase() != ".png") {
continue;
}
// Bildname im Fortschrittsbalken anzeigen
FF_SetProgressText(i, imagenum, splitPath.file);
if (DEBUG) FF_MessageBox(splitPath.file, 0);
if (!FF_LoadImage(path)) continue;
FF_SetControl("AutocropMatchedJPEGs","ARJImage",0);
FF_SetControl("AutocropMatchedJPEGs","ARJOutputName",splitPath.file);
FF_SetControl("AutocropMatchedJPEGs","ARJProgress",i+1/imagenum*100);
//***************************************************
// Bearbeitungen im 8-Bit-Modus
//***************************************************
// crop image
FF_Crop(leftbarwidth, topbarwidth, xsize-leftbarwidth-rightbarwidth, ysize-topbarwidth-bottombarwidth);
if (DEBUG) FF_MessageBox("Das Bild ist gecropped",0);
// continue;
//***** Ende der 8-Bit-Bearbeitung*************************
// sicherungskopie 1:1 speichern
var outName = splitPath.dir + splitPath.file + namenszusatz + splitPath.ext;
fso.CopyFile(path,outName);
// jetzt wird das JPG gespeichert mit der original-qualität
if (!FF_SaveImage(path, 98)) continue;
if (DEBUG) FF_MessageBox("Nach FF_SaveImage(path, 98)", 0);
// bearbeitungshistorie als usercomment im exif
tmp = FF_GetHistory();
tmp == "" ? "" : tmp += CrLf;
hist = SavedDate() + tmp;
exi = FF_GetExifTag("UserComment")
if (exi != "") exi += CrLf; //Wenn nicht leer
if (DEBUG) FF_MessageBox(exi + hist, 0);
FF_SetExifTag("UserComment", exi + hist);
FF_SetExifTag("Software", GetFixFotoInfo());
FF_SaveExif(path);
if (DEBUG) FF_MessageBox("Nach FF_SaveExif(path)", 0);
// datei datum aus exif datum setzen
if (!FF_SetExifDate(path)) continue;
if (DEBUG) FF_MessageBox("Nach FF_SetExifDate(path)", 0);
// exif vorschau restaurieren
FF_RestoreExifThumb(path);
if (DEBUG) FF_MessageBox("Nach FF_RestoreExifThumb(path)", 0);
FF_Reload();
// das ist unbearbeitet
FF_setDirty(false);
// Fortschritt melden
FF_SetProgress(i+1, imagenum)
}
FF_CloseDialog("AutocropMatchedJPEGs");
}
// Zerteilt einen Bild-Dateinamen in sein Pfadbestandteile
function SplitPath(path) {
var result = new Object();
result.dir = fso.GetParentFolderName(path) + "\\";
result.file = fso.GetBaseName(path);
result.ext = "." + fso.GetExtensionName(path);
return result;
}
function GetFixFotoInfo()
{
var s = "FixFoto Version ";
s += FF_GetMajor() + ".";
s += FF_GetMinor() + ".";
s += FF_GetBuild();
return(s);
}
function NumToString(n)
{
var s = n < 10 ? "0" : "";
return (s += n.toString(10));
}
function SavedDate()
{
var s = "Bearbeitet: ";
var d = new Date(); //System-Datum
s += d.getDate() + ".";
s += (d.getMonth() + 1) + ".";
s += d.getFullYear() + " ";
s += NumToString(d.getHours()) + ":";
s += NumToString(d.getMinutes()) + ":";
s += NumToString(d.getSeconds());
return (s + CrLf);
}