Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list all images in a folder and resize if wider than xx pixels.

Status
Not open for further replies.

tamakre

Programmer
Sep 29, 2007
8
0
0
US
I want to give the user an image assets page... where the user (who is using an home-brew CMS solution to manage content for a site) is able to click to view 'all available images' that they can insert into the content they are posting...

I would like to have this based on all images within a specific folder (all will be jpegs)... so on the simple one-page that lists them all out for the user, Im trying to figure out how to

a) list them all out vertically

b) for images that are TALLER than xx pixels, I want to determine the width and height then divide both those by 2 (to resize the down to a smaller version)


Is this do-able?

here is the code Im using successfully to show all the images in a folder...

Code:
Dim oFilesys, oFolder, oFile
Set oFilesys= CreateObject("Scripting.FileSystemObject")
Set oFolder= oFilesys.GetFolder(Server.MapPath("../../images"))
For Each oFile in oFolder.Files
'Response.write "<img src=../../images/"&oFile.Name&">"
'Response.write "<hr />"

thisimg="../../images/"&oFile.Name
%>
<img src="<%=thisimg%>"  /><br />
<%Next

Set oFolder=Nothing
Set oFilesys=Nothing


is there a way to integrate the ability to determine and where needed, re-define the height / width parameters of each image listed???
 
I would do this in css..

eg. nested css

One will be the "frame" (outer one) and might be 120px x 90 px.

The inner css will contain the <img>
You can use JS to resize porportional.. eg...

120 x 90 = wanted size
640 x 480 = current size 1
640 / 120 = scalefactor 1 = 5,33

width1: 120px
height1: 480px / scalefactor 1 (5.33) = ~~90

800 x 300 = current size 2
800 / 120 = scalefactor 2 = 6.66

width2: 120px
height2: 300 / scalefactor 2 (6.66) = ~~45

You use CSS and bgcolors, so it will behave like windows previews... eg. always same widths, but height might differ (padding). Resize porportional, also remember to round the results!

Olav Alexander Mjelde
Admin & Webmaster
 
That's a good solution Alexander, but I think you are basing it on an assumption that the sizes of the images are all the same aren't you?

If each image is a different size the results with CSS will look good in some instances and very wonky in others.

The advantage of imagemagick is that you can crop an image to keep it proportional if it the nominated height caused the width to be too far out of whack.

Steve
- I have fun with telemarketers
 
Microbe:
The JS (javascript) could resize the images porportionally..

It would have 2 weaknesses:
1) long load-time
2) needs js support

:p

Olav Alexander Mjelde
Admin & Webmaster
 
Aleander: True, and one of the great things about imagemagick (and I have only used it one one site) is that it is a permanent solution in that it doesn't do the change on the fly, it actually creates a new file with the attributes you want.

So load times aren't affected and you could have it run as a cron job.

Steve
- I have fun with telemarketers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top