Log in

View Full Version : Avisynth w/ GScript and ImageReader - open a series of images


Pages : 1 [2]

wiseant
29th August 2012, 05:26
Hi

I have taken the code for automatic Image Sizing and made an hta file [html application] that uses Microsoft HTML Application Host - requires Avisynth to be installed . . .

Just download then extract ImageSizer1 folder and run the hta

http://www.mediafire.com/?c64a5s5t7865qjb

ImageSizer1.z contains ImageSizer1.hta, GScript.dll, RT_Stats.dll, VirtualDub.exe

should work on all versions of Windows

ImageSource will fail on some psd images - otherwise it will flip psd images horizontally . . .

StainlessS
29th August 2012, 12:23
Took me two goes to realize that I needed to click the ENTER buttons after editing
the frame size, but worked fine second go.


This is the last script I was working on, have to leave it for now, got other things to do.
Need RT_Stats v1.03, just updated.


# EDIT To Suit

VID = False # True == Video : False == Pics, see IN_FILES directories/wildcards

IN_FILES = (VID) ? "D:\VID\*.AVI|MPG|MPEG" : "D:\Pics\*.BMP|JPG|JPEG|PNG" # Added '|' Pipe separator for multiple Wildcard in Extensions ONLY.
AUTOCROP = True # Crop off black borders.
SHOWBORDER = True # True Show replaced border in Red, else Black. (Test AUTOCROP)
AUTOLEVEL_STRENGTH = 0.666 # AutoLevel Strength 0.0 -> 1.0
SHOWAUTOLEVEL = True # Right Hand Side Only AutoLeveled
#
FAR = 4.0/3.0 # Required Frame Aspect Ratio
SzLimit = 1024
DEBUG = True # Debug
# ---------------------
BORDER = (SHOWBORDER) ? $FF0000: (VID) ? $101010 : $000000 # Color for replaced borders.
SUBS = True # Subtitles on clips/images
DEBUG_QBC = True # Debug QueryBorderCrop
DEBUG_QLMM = True # Debug QueryLumaMinMax
FPS = (VID) ? 30000.0/1001.0 : 1.0 # Whatever.
OUT_FILE = "FILE.List" # Dont need to change really, just a name.
#--------------------------------------------------------------------------------
GScript("""
picclip = 0 # dummy for now
result=RT_WriteFileList(IN_FILES,OUT_FILE) # Create a listing file of Pic files
Assert((result!=0), "No files found")
FILELIST=RT_ReadTxtFromFile(OUT_FILE) # Get list of files
FILES=RT_TxtQueryLines(FILELIST) # Query Number of lines in String ie number of files.
if(DEBUG){RT_Debug("Found files = " + String(FILES))}
# Prescan to ascertain max wid/hit of all files, also Autocrop & Auto Levels
MAXH=0 MAXW=0 # init max wid and hit
CROPCOORDS=""
AUTOLEVELS=""
AUTOLEVEL=(AUTOLEVEL_STRENGTH>0.0) # Adjust using Levels.
For(i=0,FILES-1) {
FN=RT_TxtGetLine(FILELIST,i) # Filename of avi file i
if(DEBUG){RT_Debug(String(i)+") Getting File dimensions",FN)}
if(VID) {
k=DirectshowSource(FN)
k=k.ConvertToYUY2().Trim(0,0)
} else {
k=ImageReader(FN,end=0).ConvertToRGB32() # With Bmap, some come up as RGB24 bit some RGB32.
}
OrgH=k.height OrgW=k.width
if(DEBUG){RT_Debug ("Orig Width =",String(orgW),"Orig Height =",String(OrgH))}
if (AUTOCROP) {
QBC = k.QueryBorderCrop(samples=24,laced=VID,debug=(DEBUG&&DEBUG_QLMM))
QBC = RT_TxtGetLine(QBC,2) # CropMore
CROPCOORDS=RT_TxtAddStr(CROPCOORDS,QBC) # Avisynth Bugfix, same as CROPCOORDS = CROPCOORDS + QBC + Chr(10)
Eval(QBC)
k=k.Crop(QBCropXM,QBCropYM,QBCropWM,QBCropHM)
}
if (AUTOLEVEL) {
QLMM = k.QueryLumaMinMax(debug=(DEBUG&&DEBUG_QLMM))
Eval(QLMM)
AUTOLEVELS=RT_TxtAddStr(AUTOLEVELS,QLMM) # Avisynth Bugfix, same as AUTOLEVELS = AUTOLEVELS + QLMM + Chr(10)
}
H=k.height W=k.width
If(MAXH<H) {MAXH=H}
If(MAXW<W) {MAXW=W}
if(DEBUG){RT_Debug("MAX Width So Far =",String(MAXW),"MAX Height So Far =",String(MAXH))}
if(DEBUG){RT_Debug(" ----------------------------- ")} # line separator
}
maxFAR = MAXW / MAXH

if(FAR >= maxFAR) {
canvasheight = (MAXH > SzLimit) ? SzLimit : MAXH
canvasheight = ((canvasheight + 1) / 2) * 2
canvaswidth = Int((canvasheight * FAR + 2) / 4) * 4
} else {
canvaswidth = (MAXW > SzLimit) ? SzLimit : MAXW
canvaswidth = ((canvaswidth + 2) / 4) * 4
canvaswidth = (canvaswidth > SzLimit) ? SzLimit : canvaswidth
canvasheight = Int((canvaswidth * FAR + 1) / 2) * 2
}

if(DEBUG){RT_Debug("SETTING CanvasWidth =",String(canvaswidth)," CanvasWeight =",String(canvasheight))}
if(DEBUG){RT_Debug(" ----------------------------- ")} # line separator
For(i=0,FILES-1) {
FN=RT_TxtGetLine(FILELIST,i) # Filename of avi file i
if(DEBUG){RT_Debug(string(i)+ ")","Processing File",FN)}
if(VID) {
k=DirectshowSource(FN).ConvertToYUY2().Trim(0,0)
} else {
k=ImageReader(FN,end=0).ConvertToRGB32() # With Bmap, RGB24 problems with addborders
}
OrgH=k.height OrgW=k.width
if (AUTOLEVEL) {
# We do AUTOLEVELS before crop, because of SHOWAUTOLEVEL
QAT = RT_TxtGetLine(AUTOLEVELS,i)
Eval(QAT)
if(k.IsYUV()) {
CSMin = 16
CSMax = 235
} else {
CSMin = 0
CSMax = 255
}
TMP_K=k
ALMin = Int(CSMin - ((CSMin - QLMMMin) * AUTOLEVEL_STRENGTH) + 0.5) # Round Up
ALMax = Int(CSMax - ((CSMax - QLMMMax) * AUTOLEVEL_STRENGTH)) # Round down
k = k.Levels(ALMin,1.0,ALMax,CSMin,CSMax,Coring=False) # DONT USE Coring
if(SHOWAUTOLEVEL) {
tmpw=int((k.width/4)*2)
Left = TMP_K.Crop(0,0,tmpw,-0)
Right= k.Crop(tmpw,0,-0,-0)
k=StackHorizontal(Left,Right)
}
}

if (AUTOCROP) {
QBC = RT_TxtGetLine(CROPCOORDS,i)
Eval(QBC)
k=k.Crop(QBCropXM,QBCropYM,QBCropWM,QBCropHM)
}

iWidth=k.Width() iHeight=k.Height()

cFAR = float(canvaswidth) / canvasheight
iFar = float(iWidth) / iHeight
Left=0 Top=0 Right=0 Bot=0

if(iFAR >= cFAR) {
oWid = canvaswidth
oHit = (oWid*iHeight/iWidth/4)*4
Top = (canvasheight-oHit) / 2
Bot = canvasheight - oHit - Top
} else {
oHit = canvasheight
oWid = (oHit*iWidth/iHeight/4)*4
Left = (canvaswidth-oWid) / 2
Right = canvaswidth - oWid - Left
}

RT_Debug("Resize","oWid="+String(oWid),"oHit="+String(oHit),"Left="+String(Left),"Top="+String(Top),"Rgt="+String(Right),"Bot="+String(Bot))
k = k.Spline36Resize(oWid,oHit).addborders(Left,Top,Right,Bot,BORDER).assumefps(fps)

if(SUBS) {
k=k.subtitle(String(i) + "/"+String(FILES-1) +" " + FN)
k=k.subtitle("Orig width=" + string(orgW) +" " + "Orig height=" + string(orgH) +" FAR="+String(Float(orgW) /orgH, "%.2f"),20,20)
if (AUTOCROP) {k=k.subtitle("Crop width=" + string(iWidth) +" " + "Crop height=" + string(iHeight) +" FAR="+String(Float(iWidth) /iHeight, "%.2f"),20,40)
} else {k=k.subtitle("NO AUTOCROP",20,40)}
k=k.subtitle("New width=" + string(oWid) +" " + "New height=" + string(oHit)+" FAR="+String(Float(oWid)/oHit,"%.2f"),20,60)
k=k.subtitle("Out width=" + string(k.Width) +" " + "Out height=" + string(k.Height)+" FAR="+String(Float(k.Width)/k.Height,"%.2f"),20,80)
if(AUTOLEVEL) {
k=k.subtitle("Auto Levels(" + String(ALMin) + ",1.0," + String(ALMAx) + "," + String(CSMin) + "," + String(CSMax) + ")",20,100)
k=k.subtitle("QLMMMin = " + String(QLMMMin) + " QLMMMax = " +String(QLMMMAx),20,120)
k=k.subtitle("AUTOLEVEL @ " + String(AUTOLEVEL_STRENGTH*100.0,"%.0f") + "%",20,140)
} else {k=k.subtitle("NO AUTOLEVEL",20,100)}
}
picclip = (IsClip(picclip)) ? picclip ++ k : k # Append to clip so far
if(!VID){k=k.ConvertToRGB24()}
if(DEBUG){RT_Debug(" ")} # line separator
if(DEBUG){RT_Debug(" ----------------------------- ")} # line separator
}
""")
PicClip

wiseant
29th August 2012, 21:21
@StainlessS

Will take your new script for a test drive
Got your new RT_Stats v1.03 - you've been busy
I'll have to test out all those new string functions - should be able to do some error checking and output log files
Will post an update to ImageSizer1.hta later today

wiseant
30th August 2012, 01:01
Hi,

New version -> ImageResizer1a.7z
http://www.mediafire.com/?4gttx5cw9wpl2bd

I simplified the code a bit and added a VirtualDub filter -> DFN.VDF along with DFN.vcf
If the user wants to use DFN filter - Use VirtualDub/Video/Filters/Add - then once it is loaded - File/Load processing settings/ and open dfn.vcf
The user can select Noise Card - and scroll thru the Images - remember to turn of Noise Card if you want to encode the file or Export an Image Sequence

Once the avs file is loaded in VirtualDub - the user can select File\Export\Image sequence...

StainlessS
1st September 2012, 00:22
You guys might like this:
http://forum.doom9.org/showthread.php?t=165775

EDIT: Post #6

wiseant
1st September 2012, 21:03
@StainlessS

Finally tried your script from post #52 - there's a lot of stuff going on . . .

Got a couple of questions re your syntax:

1. I did a fair amount of searching, but I couldn't find any reference to the use of "?", and ":" i.e.

BORDER = (SHOWBORDER) ? $FF0000: (VID) ? $101010 : $000000

where could I find some documentation on these

2. re another use of "?" and ":"


if(FAR >= maxFAR) {
canvasheight = (MAXH > SzLimit) ? SzLimit : MAXH
canvasheight = ((canvasheight + 1) / 2) * 2
canvaswidth = Int((canvasheight * FAR + 2) / 4) * 4
} else {
canvaswidth = (MAXW > SzLimit) ? SzLimit : MAXW
canvaswidth = ((canvaswidth + 2) / 4) * 4
canvaswidth = (canvaswidth > SzLimit) ? SzLimit : canvaswidth
canvasheight = Int((canvaswidth * FAR + 1) / 2) * 2
}


I like how you simplified the code in #2

my use of ImageResizer is mainly for output as video clip for BD, DVD, as well as any-sized avi/mp4 - so the maxheight/maxwidth is implemented differently

I can see your logic re MAXW/MAXH - perhaps a way to maximum quality is to find the median or average height/width

Wilbert
1st September 2012, 22:02
1. I did a fair amount of searching, but I couldn't find any reference to the use of "?", and ":" i.e.

BORDER = (SHOWBORDER) ? $FF0000: (VID) ? $101010 : $000000

where could I find some documentation on these
http://avisynth.org/mediawiki/Operators

wiseant
2nd September 2012, 00:17
@Wilbert

Thank you

StainlessS
2nd September 2012, 00:31
perhaps a way to maximum quality is to find the median or average height/width

My guess is that the best way is NOT to resize at all (Just crop).

EDIT: below link to handy resize method,
http://forum.doom9.org/showthread.php?p=1589538#post1589538

See resizing in the TEMPLATE file, with SIZEX and SIZEY,
where:
0,0, crop only
only 1 of them 0, then zero dim is resized to keep 1:1 pixel aspect ratio
both non 0, explicit resize to dims and let MeGUI set the DAR for you.

StainlessS
4th September 2012, 17:40
Is there a way to call jpegexiforient and get the stdout to a variable in avisynth?


See RT_Call in new version RT_Stats, then can use RT_ReadTxtFromFile.

EDIT: Example usage with MediaInfo (CLI) here:
http://forum.doom9.org/showthread.php?p=1589747#post1589747

StainlessS
5th December 2012, 12:01
Modified script from post #52 to allow choosing crop mode. (Only use CropExact[0] if RGB)


# PicVidShow.avs # https://forum.doom9.org/showthread.php?p=1604043#post1604043

# EDIT To Suit

VID = False # True == Video : False == Pics, see IN_FILES directories/wildcards

IN_FILES = (VID) ? "D:\VID\*.AVI|MPG|MPEG" : "D:\PIC\*.BMP|JPG|JPEG|PNG" # Added '|' Pipe separator for multiple Wildcard in Extensions ONLY.
AUTOCROP = True # Crop off black borders.
AUTOCROP_THRESH = 0.0 # Default 0.0 allows QueryBorderCop to auto set super sensitive mode for single images, use default 0.0 normally
SHOWBORDER = True # True Show replaced border in Red, else Black. (Test AUTOCROP)
AUTOLEVEL_STRENGTH = 1.0 # AutoLevel Strength 0.0 -> 1.0
SHOWAUTOLEVEL = True # Right Hand Side Only AutoLeveled
#
FAR = 4.0/3.0 # Required Frame Aspect Ratio
SzLimit = 1024
DEBUG = True # Debug
CROPMODE = 2 # 0=CropExact(RGB Only), 1=CropLess, 2=CropMore, 3=CropPlus
# ---------------------
BORDER = (SHOWBORDER) ? $FF0000: (VID) ? $101010 : $000000 # Color for replaced borders.
SUBS = True # Subtitles on clips/images
DEBUG_QBC = True # Debug QueryBorderCrop
DEBUG_QLMM = True # Debug QueryLumaMinMax
FPS = (VID) ? 30000.0/1001.0 : 1.0 # Whatever.
OUT_FILE = "FILE.List" # Dont need to change really, just a name.
#--------------------------------------------------------------------------------
GScript("""
picclip = 0 # dummy for now
result=RT_WriteFileList(IN_FILES,OUT_FILE) # Create a listing file of Pic files
Assert((result!=0), "No files found")
FILELIST=RT_ReadTxtFromFile(OUT_FILE) # Get list of files
FILES=RT_TxtQueryLines(FILELIST) # Query Number of lines in String ie number of files.
if(DEBUG){RT_Debug("Found files = " + String(FILES))}
# Prescan to ascertain max wid/hit of all files, also Autocrop & Auto Levels
MAXH=0 MAXW=0 # init max wid and hit
CROPCOORDS=""
AUTOLEVELS=""
AUTOLEVEL=(AUTOLEVEL_STRENGTH>0.0) # Adjust using Levels.
For(i=0,FILES-1) {
FN=RT_TxtGetLine(FILELIST,i) # Filename of avi file i
if(DEBUG){RT_Debug(String(i)+") Getting File dimensions",FN)}
if(VID) {
k=DirectshowSource(FN)
k=k.ConvertToYUY2().Trim(0,0)
} else {
k=ImageReader(FN,end=0).ConvertToRGB32() # With Bmap, some come up as RGB24 bit some RGB32.
}
OrgH=k.height OrgW=k.width
if(DEBUG){RT_Debug ("Orig Width =",String(orgW),"Orig Height =",String(OrgH))}
if (AUTOCROP) {
if(AUTOCROP_THRESH == 0.0) { # Call without Thresh arg, allows use of auto super sensitive setting for single frame iamges
QBC = k.QueryBorderCrop(samples=24,laced=VID,debug=(DEBUG&&DEBUG_QLMM))
} else { # Will prevent auto super sensitive from working
QBC = k.QueryBorderCrop(samples=24,Thresh=AUTOCROP_THRESH,laced=VID,debug=(DEBUG&&DEBUG_QLMM))
}
Eval(QBC)
k=k.Crop(QBCropXM,QBCropYM,QBCropWM,QBCropHM)
QBC = RT_TxtGetLine(QBC,CROPMODE) # remember required mode, CropMore etc
CROPCOORDS=RT_TxtAddStr(CROPCOORDS,QBC) # Avisynth Bugfix, same as CROPCOORDS = CROPCOORDS + QBC + Chr(10)
}
if (AUTOLEVEL) {
QLMM = k.QueryLumaMinMax(debug=(DEBUG&&DEBUG_QLMM))
Eval(QLMM)
AUTOLEVELS=RT_TxtAddStr(AUTOLEVELS,QLMM) # Avisynth Bugfix, same as AUTOLEVELS = AUTOLEVELS + QLMM + Chr(10)
}
H=k.height W=k.width
If(MAXH<H) {MAXH=H}
If(MAXW<W) {MAXW=W}
if(DEBUG){RT_Debug("MAX Width So Far =",String(MAXW),"MAX Height So Far =",String(MAXH))}
if(DEBUG){RT_Debug(" ----------------------------- ")} # line separator
}
maxFAR = MAXW / MAXH

if(FAR >= maxFAR) {
canvasheight = (MAXH > SzLimit) ? SzLimit : MAXH
canvasheight = ((canvasheight + 1) / 2) * 2
canvaswidth = Int((canvasheight * FAR + 2) / 4) * 4
} else {
canvaswidth = (MAXW > SzLimit) ? SzLimit : MAXW
canvaswidth = ((canvaswidth + 2) / 4) * 4
canvaswidth = (canvaswidth > SzLimit) ? SzLimit : canvaswidth
canvasheight = Int((canvaswidth * FAR + 1) / 2) * 2
}

if(DEBUG){RT_Debug("SETTING CanvasWidth =",String(canvaswidth)," CanvasWeight =",String(canvasheight))}
if(DEBUG){RT_Debug(" ----------------------------- ")} # line separator
For(i=0,FILES-1) {
FN=RT_TxtGetLine(FILELIST,i) # Filename of avi file i
if(DEBUG){RT_Debug(string(i)+ ")","Processing File",FN)}
if(VID) {
k=DirectshowSource(FN).ConvertToYUY2().Trim(0,0)
} else {
k=ImageReader(FN,end=0).ConvertToRGB32() # With Bmap, RGB24 problems with addborders
}
OrgH=k.height OrgW=k.width
if (AUTOLEVEL) {
# We do AUTOLEVELS before crop, because of SHOWAUTOLEVEL
QAT = RT_TxtGetLine(AUTOLEVELS,i)
Eval(QAT)
if(k.IsYUV()) {
CSMin = 16
CSMax = 235
} else {
CSMin = 0
CSMax = 255
}
TMP_K=k
ALMin = Int(CSMin - ((CSMin - QLMMMin) * AUTOLEVEL_STRENGTH) + 0.5) # Round Up
ALMax = Int(CSMax - ((CSMax - QLMMMax) * AUTOLEVEL_STRENGTH)) # Round down
k = k.Levels(ALMin,1.0,ALMax,CSMin,CSMax,Coring=False) # DONT USE Coring
if(SHOWAUTOLEVEL) {
tmpw=int((k.width/4)*2)
Left = TMP_K.Crop(0,0,tmpw,-0)
Right= k.Crop(tmpw,0,-0,-0)
k=StackHorizontal(Left,Right)
}
}

if (AUTOCROP) {
QBC = RT_TxtGetLine(CROPCOORDS,i)
QBCTrailer=Select(CROPMODE,"=","L=","M=","P=")
QBC1=StrReplace(QBC,QBCTrailer,"=") # Change all to style without a trailer eg QBCropXM to QBCropX.
QBC2=StrReplace(QBC1,"QBC","C") # Change all style QBCropX to CropX
Eval(QBC2) # Set variables in Avisynth, ie CropX etc
k=k.Crop(CropX,CropY,CropW,CropH)
}

iWidth=k.Width() iHeight=k.Height()

cFAR = float(canvaswidth) / canvasheight
iFar = float(iWidth) / iHeight
Left=0 Top=0 Right=0 Bot=0

if(iFAR >= cFAR) {
oWid = canvaswidth
oHit = (oWid*iHeight/iWidth/4)*4
Top = (canvasheight-oHit) / 2
Bot = canvasheight - oHit - Top
} else {
oHit = canvasheight
oWid = (oHit*iWidth/iHeight/4)*4
Left = (canvaswidth-oWid) / 2
Right = canvaswidth - oWid - Left
}

RT_Debug("Resize","oWid="+String(oWid),"oHit="+String(oHit),"Left="+String(Left),"Top="+String(Top),"Rgt="+String(Right),"Bot="+String(Bot))
k = k.Spline36Resize(oWid,oHit).addborders(Left,Top,Right,Bot,BORDER).assumefps(fps)

if(SUBS) {
k=k.subtitle(String(i) + "/"+String(FILES-1) +" " + FN)
k=k.subtitle("Orig width=" + string(orgW) +" " + "Orig height=" + string(orgH) +" FAR="+String(Float(orgW) /orgH, "%.2f"),20,20)
if (AUTOCROP) {k=k.subtitle("Crop width=" + string(iWidth) +" " + "Crop height=" + string(iHeight) +" FAR="+String(Float(iWidth) /iHeight, "%.2f"),20,40)
} else {k=k.subtitle("NO AUTOCROP",20,40)}
k=k.subtitle("New width=" + string(oWid) +" " + "New height=" + string(oHit)+" FAR="+String(Float(oWid)/oHit,"%.2f"),20,60)
k=k.subtitle("Out width=" + string(k.Width) +" " + "Out height=" + string(k.Height)+" FAR="+String(Float(k.Width)/k.Height,"%.2f"),20,80)
if(AUTOLEVEL) {
k=k.subtitle("Auto Levels(" + String(ALMin) + ",1.0," + String(ALMAx) + "," + String(CSMin) + "," + String(CSMax) + ")",20,100)
k=k.subtitle("QLMMMin = " + String(QLMMMin) + " QLMMMax = " +String(QLMMMAx),20,120)
k=k.subtitle("AUTOLEVEL @ " + String(AUTOLEVEL_STRENGTH*100.0,"%.0f") + "%",20,140)
} else {k=k.subtitle("NO AUTOLEVEL",20,100)}
}
picclip = (IsClip(picclip)) ? picclip ++ k : k # Append to clip so far
if(!VID){k=k.ConvertToRGB24()}
if(DEBUG){RT_Debug(" ")} # line separator
if(DEBUG){RT_Debug(" ----------------------------- ")} # line separator
}
""")
PicClip
return Last


Function StrReplace(string s,string find,string replace) # Repeated, string replacements
# Original:- http://forum.doom9.org/showthread.php?p=1540504#post1540504 By Vampiredom, Gavino, IanB
#{i=s.FindStr(find)return(i==0?s: s.LeftStr(i-1)+replace+s.MidStr(Strlen(find)+i).StrReplace(find,replace))}
# Converted to use RT_Stats RT_StrAddStr() to avoid 2.58/2.6a3 string concatenation bug:-
{i=s.FindStr(find) return(i==0?s:RT_StrAddStr(s.LeftStr(i-1),replace,s.MidStr(Strlen(find)+i).StrReplace(find,replace)))}

Function StrReplaceDeep(string s,string find,string replace) # DEEP Repeated, string replacements
# When replacing eg pairs of SPACE characters by single SPACE, StrReplace can leave some pairs non replaced.
# Assumes that you want to rescan where replaced string could constitute part of a new find substring,
# Length of replace must be shorter than length of find, else will call StrReplace instead.
# Based On:- http://forum.doom9.org/showthread.php?p=1540504#post1540504 By Vampiredom, Gavino, IanB
# {i=s.FindStr(find)return i==0?s:s.LeftStr(i-1)+( strlen(replace)<strlen(find)? \
# StrReplaceDeep(replace+s.MidStr(Strlen(find)+i),find,replace) : replace+StrReplace(s.MidStr(Strlen(find)+i),find,replace))}
# Converted to use RT_Stats RT_StrAddStr() to avoid 2.58/2.6a3 string concatenation bug:-
{i=s.FindStr(find)return i==0?s:RT_StrAddStr(s.LeftStr(i-1),( strlen(replace)<strlen(find)? \
StrReplaceDeep(RT_StrAddStr(replace,s.MidStr(Strlen(find)+i)),find,replace) : \
RT_StrAddStr(replace,StrReplace(s.MidStr(Strlen(find)+i),find,replace))))}


EDITED: Added CROPMODE and AUTOCROP_THRESH removed.

EDIT: Put back AUTOCROP_THRESH again, Dang !

EDIT: For much better image splicer see ImageSplicer.avs included with RT_Stats here:
http://forum.doom9.org/showthread.php?t=165479