I didn't read the help file about ftos(). ftos() can simplify the formula.
Added Thumbnail image support (:don't use it as a resizer).
Usage is:
.ImageConv(sFileFr, sFileTo, ThumbWidth, ThumbHeight)
The third and fourth parameters optional, if omitted, just a plain
converter. If only third parameter is specified, the longer side one
will take this value and the shorter side one will be calculated
appropriately to keep the ratio. E.g.,
.ImageConv(?"...\test.jpg", ?"...\test.png", 96, 96)
will extract and save a 96x96 thumbnail to test.png.
.ImageConv(?"...\test.jpg", ?"...\test.png", 96)
will save from 1024x768 test.jpg to 96x72 test.png thumbnail, &
will save from 768x1024 test.jpg to 72x96 test.png thumbnail.
---------------------- ImageConv.PowerPro ----------------------------
args sFileFr,sFileTo,nW,nH
local xFileFr,xFileTo,pToken,pImage,nCodecs,nSize,ci,si
dll.call("MultiByteToWideChar|ui ui s i s520 i";;+
,0,0,"sFileFr",-1,"xFileFr",260)
dll.call("MultiByteToWideChar|ui ui s i s520 i";;+
,0,0,"sFileTo",-1,"xFileTo",260)
si=dll.create_array(4,"i",1)
dll.call("gdiplus|GdiplusStartup|ui* a* ui","pToken",si,0)
dll.call("gdiplus|GdipLoadImageFromFile|s ui*","xFileFr","pImage")
if(nW)do
if(!nH)do
local mW,mH
dll.call("gdiplus|GdipGetImageWidth|ui ui*",pImage,"mW")
dll.call("gdiplus|GdipGetImageHeight|ui ui*",pImage,"mH")
nH=ftos(min(1,1.0*mH/mW)*nW,"%0.0f")
nW=ftos(min(1,1.0*mW/mH)*nW,"%0.0f")
endif
local pThumb
dll.call("gdiplus|GdipGetImageThumbnail|ui ui ui ui* ui ui";;+
,pImage,nW,nH,"pThumb",0,0)
dll.call("gdiplus|GdipDisposeImage|ui",pImage)
pImage=pThumb
endif
dll.call("gdiplus|GdipGetImageEncodersSize|ui* ui*","nCodecs","nSize")
ci=dll.create_array(nSize/4+1,"i")
dll.call("gdiplus|GdipGetImageEncoders|ui ui a* b",nCodecs,nSize,ci)
for(local i=0;i<nCodecs;i++)
dll.call("WideCharToMultiByte|ui ui i i s i ui ui";;+
,0,0,ci[19*i+12],-1,"nSize",272,0,0)
if(index(nSize,file.type(sFileTo)))
break
endfor
dll.call("gdiplus|GdipSaveImageToFile|ui s ui ui";;+
,pImage,"xFileTo",ci.get_pointer(19*i+1),0)
dll.call("gdiplus|GdipDisposeImage|ui",pImage)
dll.call("gdiplus|GdiplusShutdown|ui",pToken)
quit
----------------------------------------------------------------------
Sean
Attention: PowerPro's Web site has moved: http://www.ppro.org
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/power-pro/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/power-pro/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/