View Full Version : Alternative way to get images from a folder
ADLANCAS
18th March 2006, 02:21
Hi,
Iīm trying to make a script to get images that can be in portrait or landscape orientation.
Here it is:
c1=Photo("Portrait.jpg")
c2=Photo("Landscape.jpg")
last=c1+c2
ImageWriter("C:\Photos\", start = 0, type = "jpg", info = true)
function Photo(string image)
{
t = ImageSource(image, end = 0, use_DevIL=true)
x = t.width
y = t.height
z = y * 4 / 3 # if z > x we need borders (orientation portrait)
a = (z < x) ? 0 : (z - x) / 2 # a = width of border
t = t.AddBorders(a, 0, a, 0, $000000)
t = t.ConvertToRGB32().LanczosResize(640,480)
return t
}
It works, but it needs to add one line for each image.
I used something like:
ImageSource("image%05d.bmp", 5, 105)
, but it canīt be used with different resolution.
Is there another way to get all images from a folder without acessing each one individually?
Thanks,
Alexandre
ADLANCAS
21st March 2006, 02:20
I've made some changes in script.
Now, it can open images with even or odd resolution, adding black borders to keep aspect 4:3.
This can be useful if you get photos from a scanner.
c1=Photo("Portrait.jpg")
c2=Photo("Landscape.jpg")
last=c1+c2
ImageWriter("C:\Photos\", start = 0, type = "jpg", info = true)
function Photo(string image)
{
t = ImageSource(image, end = 0, use_DevIL=true)
x = t.width
y = t.height
x = t.width
m = x / 2 * 2
t = (x == m) ? t : t.Addborders(0, 0, 1, 0, 0)
x = (x == m) ? x : t.width
m = x / 4 * 4
t = (x == m) ? t : t.Addborders(1, 0, 1, 0, 0)
x = (x == m) ? x : t.width
m = x / 8 * 8
t = (x == m) ? t : t.Addborders(2, 0, 2, 0, 0)
x = (x == m) ? x : t.width
m = x / 16 * 16
t = (x == m) ? t : t.Addborders(4, 0, 4, 0, 0)
y = t.height
n = y / 2 * 2
t = (y == n) ? t : t.Addborders(0, 0, 0, 1, 0)
y = (y == n) ? y : t.height
n = y / 4 * 4
t = (y == n) ? t : t.Addborders(0, 1, 0, 1, 0)
y = (y == n) ? y : t.height
n = y / 8 * 8
t = (y == n) ? t : t.Addborders(0, 2, 0, 2, 0)
y = (y == n) ? y : t.height
n = y / 16 * 16
t = (y == n) ? t : t.Addborders(0, 4, 0, 4, 0)
z = y * 4 / 3 # if z > x we need borders (orientation portrait)
a = (z < x) ? 0 : (z - x) / 2 # a = width of border
t = t.AddBorders(a, 0, a, 0, $000000)
t = t.ConvertToRGB32().LanczosResize(640,480)
return t
}
Unfortunatelly, I have no idea to get all images from a folder:(
Mug Funky
21st March 2006, 03:50
try a batch file. something like (but not):
FOR %%A IN (*.jpg) DO ECHO imagesource("%%~A", end = 0, use_DevIL=true)>> myscript.avs
ADLANCAS
22nd March 2006, 01:55
very nice!:thanks:
Now, everything is easy, except...
I tried to think how to adjust this batch file to create a complete script, but my knowledge is not enough.
Could you help me something more ?
Let's suppose that there are photos in a folder, and I need a batch file to create this script:
c1=Photo("name.jpg")
c2=Photo("name.jpg")
c3=Photo("name.jpg")
c4=Photo("name.jpg")
Do you know how to do that ? (using a variable in a batch, that increases in a loop)
(Moderator, I think that this notes are important to this area, but if not, please tell me if I need to change to another area)
Mug Funky
22nd March 2006, 02:04
well, with the FOR %%A in (*.jpg) syntax, you can use the name of the picture as a variable name in avisynth. these are all unique, so there's no problems with doing it this way. means you wont get "c1, c2, c3" etc, but rather "picture1, picture2, picture3" assuming your directory has "picture1.jpg, picture2.jpg" etc in it.
try (just for the lines you want):
FOR %%A in (*.jpg) DO ECHO %%~nA=Photo("%%~A")>> myscript.avs
ADLANCAS
22nd March 2006, 03:17
Sorry, maybe I was not so clear.
I need to have some variables in order to join all clips.
Let me try to explain with an example with 4 photos.
Here is a script created "automatically":c1=Photo("name.jpg")
c2=Photo("name.jpg")
c3=Photo("name.jpg")
c4=Photo("name.jpg")
x1=c1+c2+c3+c4+c5+c6+c7+c8+c9+c10
x2=c11+c12+c13+c14+c15+c16+c17+c18+c19+c20
last=x1+x2If lines x1= and x2= are fixes in the batch file, I need to do is only open script and put a # in the right place .
Script becomes:c1=Photo("name.jpg")
c2=Photo("name.jpg")
c3=Photo("name.jpg")
c4=Photo("name.jpg")
x1=c1+c2+c3+c4#+c5+c6+c7+c8+c9+c10
#x2=c11+c12+c13+c14+c15+c16+c17+c18+c19+c20
last=x1#+x2
That's why I need to use a batch with a variable, to create c1, c2, ...
Rockas
25th March 2006, 13:37
So... the result of the batch posted by Mug Funky is:
Picture1=Photo("Picture1.jpg")
Picture2=Photo("Picture2.jpg")
Picture3=Photo("Picture3.jpg")
Picture4=Photo("Picture4.jpg")
that means that if you rename your pictures to c1.jpg c2.jpg c3.jpg c4.jpg you'll have:
c1=Photo("c1.jpg")
c2=Photo("c2.jpg")
c3=Photo("c3.jpg")
c4=Photo("c4.jpg")
Will it do it?;)
edit: spelling
ADLANCAS
28th March 2006, 22:06
Rockas,
To do this kind of thing, I wouldn't ask to make a batch file, because I could prepare a general script like this:c1=Photo("1.jpg")
c2=Photo("2.jpg")
c3=Photo("3.jpg")
#c4=Photo("4.jpg")
...
#c100=Photo("100.jpg")
x1=c1+c2+c3#+c4+c5+c6+c7+c8+c9+c10
...
#x9=c91+c92+c93+c94+c95+c96+c97+c98+c99+c100
last=x1#+x2+x3+x4+x5+x6+x7+x8+x9
and i'd need only to change the name of photos, like you said. But I used this general script before, and I'd like to do automatically :)
Thanks anyway.
Today I have created a batch that works:) :
for %%x in (*.jpg) do (
echo.temp = Photo^("%%x"^)
echo.c = c + temp
) >> "script.avs"
this batch creates:temp = Photo("1Water lilies.jpg")
c = c + temp
temp = Photo("3Sunset.jpg")
c = c + temp
I need now only to include some lines in this batch to get it complete.
I've made some tests to order photos by name, but it doesn't works on Win2000 and it works on XP. I do'n't know why that. Anyway, I'll use XP and so I don't need it.
Thanks for all sugestion,
Alexandre
Edit: Order by names works on WinXP.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.