DEFLNG a-z $INCLUDE "e:\bme\cgi\PBCGI.INC" $INCLUDE "e:\bme2\engine\iam\iam.inc" $INCLUDE "e:\bme2\engine\iam\multpart.inc" 'IAMGC.BAS - Image conversion tool (really quick'n'dirty) 'Note for those looking at this sourcecode for education/entertainment: ' PBCGI.INC is an include for for accessing IIS/CGI data. ToPut$ is also used, which URI-encodes a string. ' MULTPART.INC is a small CGI add-on for parsing multi-part form data. It's a bit brute force. ' IAM.INC contains the output routine (WriteError) used to contain most of the forms. It also contains some directory names, etc. 'The imaging library used is from SMALLER ANIMALS. 'Local DECLARE FUNCTION SuckIn$ (theFile$) ' Quickly pull in file 'Windows DECLARE FUNCTION GlobalUnlock LIB "KERNEL32.DLL" ALIAS "GlobalUnlock" (BYVAL hMem AS LONG) AS LONG DECLARE FUNCTION GlobalLock LIB "KERNEL32.DLL" ALIAS "GlobalLock" (BYVAL hMem AS LONG) AS LONG DECLARE FUNCTION GlobalFree LIB "KERNEL32.DLL" ALIAS "GlobalFree" (BYVAL hMem AS LONG) AS LONG DECLARE FUNCTION GlobalAlloc LIB "KERNEL32.DLL" ALIAS "GlobalAlloc" (BYVAL wFlags AS DWORD, BYVAL dwBytes AS DWORD) 'Isource DECLARE SUB ISInitialize LIB "_ISource22.DLL" ALIAS "_ISInitialize" (BYVAL pKey$) DECLARE FUNCTION ISOpenFileSource LIB "_ISource22.dll" ALIAS "_ISOpenFileSource" (BYVAL pFileName AS STRING) AS LONG DECLARE FUNCTION ISReadPSD LIB "_ISource22.dll" ALIAS "_ISReadPSD" (BYVAL hSource AS LONG, BYREF puWidth AS LONG, BYREF puHeight AS LONG, BYVAL uColorType AS LONG, BYVAL fGammaVal AS DOUBLE) AS LONG DECLARE FUNCTION ISReadTIFF LIB "_ISource22.dll" ALIAS "_ISReadTIFF" (BYVAL hSource AS LONG, BYREF puWidth AS LONG, BYREF puHeight AS LONG, BYVAL uColorType AS LONG, BYVAL fGammaVal AS DOUBLE, BYREF uFrameIndex AS LONG) AS LONG DECLARE FUNCTION ISCloseSource LIB "_ISource22.dll" ALIAS "_ISCloseSource" (BYVAL hSource AS LONG) AS LONG DECLARE FUNCTION ISResizeFilterImage LIB "_ISource22.dll" ALIAS "_ISResizeFilterImage" (BYVAL pRGB, BYVAL uSrcWidth, BYVAL uSrcHeight, BYVAL pRGBOut, BYVAL uDestWidth, BYVAL uDestHeight, BYVAL uBytesPerPixel, BYVAL uFilter) 'IMGDLL DECLARE SUB ImgDLLInitDLL LIB "IMGDLL.DLL" ALIAS "ImgDLLInitDLL" (BYVAL InitVal AS LONG) DECLARE FUNCTION ImgDLLReadRGBFromBMP LIB "IMGDLL.DLL" ALIAS "ImgDLLReadRGBFromBMP" (FileName AS ASCIIZ, iWidth AS LONG, iHeight AS LONG) AS LONG DECLARE FUNCTION ImgDLLReadRGBFromJPG LIB "IMGDLL.DLL" ALIAS "ImgDLLReadRGBFromJPG" (FileName AS ASCIIZ, iWidth AS LONG, iHeight AS LONG) AS LONG DECLARE FUNCTION ImgDLLReadRGBFromGIF LIB "IMGDLL.DLL" ALIAS "ImgDLLReadRGBFromGIF" (FileName AS ASCIIZ, iWidth AS LONG, iHeight AS LONG, pTransColor AS LONG) AS LONG DECLARE FUNCTION ImgDLLReadRGBFromPNG LIB "IMGDLL.DLL" ALIAS "ImgDLLReadRGBFromPNG" (FileName AS ASCIIZ, iWidth AS LONG, iHeight AS LONG) AS LONG DECLARE FUNCTION ImgDLLReadRGBFromTIFF LIB "IMGDLL.DLL" ALIAS "ImgDLLReadRGBFromTIFF"(FileName AS ASCIIZ, iWidth AS LONG, iHeight AS LONG) AS LONG DECLARE FUNCTION ImgDLLSaveRGBToJPG LIB "IMGDLL.DLL" ALIAS "ImgDLLSaveRGBToJPG" (FileName AS ASCIIZ, BYVAL pBuf AS LONG PTR, BYVAL iWidth AS LONG, BYVAL iHeight AS LONG, BYVAL iQuality AS LONG, BYVAL bColor AS LONG, BYVAL bProgressive AS LONG) AS LONG %MAXGCIMGSIZE = 5000 'maximum image size FUNCTION PBMAIN() ON ERROR GOTO fail RANDOMIZE TIMER Inn$=cgiRead() cmd$ = GrabCGI$(inn$, "cmd") IF cmd$ = "" OR cmd$ = "full" THEN 'Write main form frm$ = "This tool allows you to convert various graphic files into web-suitable JPG images. You can try using this if your scanning software forces you to use BMP or TIFF files, or your digital camera makes giant images that you need to reduce.
" frm$ = frm$ & "
" IF cmd$ = "" THEN frm$ = frm$ & "Want more control over the options? Click here
TIFF FILE NOTE: The following 8-bit and 24-bit TIFF variations are supported: uncompressed, jpeg compressed, and ZIP compressed. LZW compression is not supported for licensing reasons, sorry." ELSE thenote$ = "" END IF WriteError "Image error", "We were not able to decode your image file. Make sure it's one of our supported format, and try selecting the format manually. If that doesn't work, you're probably SOL with this tool. Sorry!" & thenote$, "" GOTO deletetemp END IF IF iWidth > %MAXGCIMGSIZE OR iHeight > %MAXGCIMGSIZE THEN WriteError "Image error", "Whoa! That picture is ginormous. We can't process stuff that big, sorry...", "" GOTO deletetemp END IF GlobalUnlock hRGB pBuf = GlobalLock(hRGB) 'Scale if needed IF thisScale > 0 AND iWidth > thisScale THEN scaleAmt# = thisScale / iWidth iWidth2 = scaleAmt# * iWidth iHeight2 = scaleAmt# * iHeight pResized = GlobalAlloc(&H0, 3 * iWidth2 * iHeight2) res = ISResizeFilterImage (pBuf, iWidth, iHeight, pResized, iWidth2, iHeight2, 3, 8) IF res = 0 THEN WriteError "Image error", "An error occured while trying to convert your image (scaling problem). Please let me (glider) know about this, assuming your file is valid.", "" GOTO deletetemp END IF GlobalFree pBuf pBuf = pEffect iWidth = iWidth2 iHeight = iHeight2 ELSE hResized = hRGB pResized = GlobalLock (hResized) END IF 'Resave file, clear variables, and output image data res = ImgDLLSaveRGBToJPG (zFile, pResized, iWidth, iHeight, thisQuality, 1, 0) IF res = 0 THEN WriteError "Image error", "An error occured while trying to convert your image (saving problem). Please let me (glider) know about this, assuming your file is valid.", "" GOTO deletetemp END IF x$ = SuckIn$(thisFile$) STDOUT "Content-type: image/jpeg" IF username$ <> "" THEN STDOUT "URI: " & $IAMBASEURL & "scratch/" & toPut$(username$) & ".jpg" & $CRLF ELSE STDOUT $CRLF & x$; END IF 'Delete temp filename deletetemp: IF thisFormat$ = "tif" OR thisFormat$ = "psd" THEN res = ISCloseSource(sres) END IF IF username$ = "" AND DIR$(thisFile$) <> "" THEN KILL thisFile$ END IF GlobalUnlock hRGB GlobalFree hRGB GlobalUnlock hResized GlobalFree hResized EXIT FUNCTION fail: WriteCGI "
" WriteCGI "ERROR: Code# " & FORMAT$(ERR) & "
" EXIT FUNCTION END FUNCTION FUNCTION SuckIn$ (theFile$) ' Quickly pull in file x$ = DIR$(theFile$) IF x$ = "" THEN SuckIn$ = "" EXIT FUNCTION END IF ff = FREEFILE OPEN theFile$ FOR BINARY LOCK SHARED AS #ff GET$ #ff, LOF(ff), Buffer$ CLOSE #ff SuckIn$ = Buffer$ EXIT FUNCTION END FUNCTION