Re: Generating thumbnails of images and videos
- Posted by DD Jul 25, 2009
- 1125 views
mic_ said...
Here's something I wrote a little more than a year ago to go through all JPG images in the current directory, generate thumbnails for each of them, save the thumbnails in a directory named "thumbs" and create a html file that displays all the tumbnails. It uses CxImage to load and save the images.
include cximage.ew include file.e include machine.e include get.e include misc.e constant INITIALDIR = current_dir() constant s = dir(INITIALDIR&"\\*.JPG") constant fn = open("thumbs\\index.html","wb") atom image -- Initialize the CXI library if not CXI_Init() then abort(0) end if puts(fn,"<html><head><title>Thumbs</title></head><body><table><tr>") for i=1 to length(s) do if length(s[i][D_NAME])>4 then -- Load an image from file image = CXI_LoadImage(INITIALDIR&"\\"&s[i][D_NAME], CXI_FORMAT_UNKNOWN, 0) -- Abort if the image couldn't be loaded if not image then abort(0) end if CXI_Resize(image, 240, 160, CXI_GOOD_RESIZE) CXI_SetJpegQuality(image,90) puts(fn,"<td><a href=\""&s[i][D_NAME]&"\"><img src=\""&s[i][D_NAME][1..length(s[i][D_NAME])-4]&"-tmb.jpg"&"\"></img></a></td>") if remainder(i,4)=0 then puts(fn,"</tr>\n<tr>") end if -- Save a copy of the image as JPEG if CXI_SaveImage(image, INITIALDIR&"\\thumbs\\"&s[i][D_NAME][1..length(s[i][D_NAME])-4]&"-tmb.jpg", CXI_FORMAT_JPG) then end if puts(1,s[i][D_NAME]&"\n") printf(1,"Image dimensions: %dx%d\n",{CXI_GetWidth(image),CXI_GetHeight(image)}) printf(1,"Bits per pixel: %d\n\n",CXI_GetBpp(image)) -- Destroy the resources allocated for the image CXI_FreeImage(image) end if end for puts(fn,"</tr></table></body></html>")
It appears that CxImage adds yet another DLL dependency to the project, and as such will not be suitable for the final app. Nonetheless, i need a prototype and do not have the time to recode the app in Visual C, so it will have to do for now to make the prototype release.
How then do i display the thumbnail in the GUI, which is built with win32lib?