• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

GDImage 5.02 utility (Gif2png)

Started by Patrice Terrier, May 27, 2009, 07:29:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

Gif2png is a GDImage 5.02+ utility that allows you to convert a transparent GIF animation into a 32-bit multi-frame PNG file, that is suitable to perform GDImage multi-state animation.

This is a command line application, you just pass the name of the GIF file, and the utility will create the PNG file using the same name and folder.

Source code (very short):


'+--------------------------------------------------------------------------+
'|                                                                          |
'|                                Gif2png                                   |
'|                                                                          |
'|     Convert a GIF animation into 24 or 32-bit multi-state PNG file.      |
'|        Each frame uses a square size suitable for image rotation.        |
'|                                                                          |
'+--------------------------------------------------------------------------+
'|                                                                          |
'|                         Author Patrice TERRIER                           |
'|                            copyright(c) 2009                             |
'|                           www.zapsolution.com                            |
'|                        pterrier@zapsolution.com                          |
'|                                                                          |
'+--------------------------------------------------------------------------+
'|                  Project started on : 05-27-2009 (MM-DD-YYYY)            |
'|                        Last revised : 05-27-2009 (MM-DD-YYYY)            |
'+--------------------------------------------------------------------------+

#COMPILE EXE "gif2png.exe"

%TRUE = 1

#INCLUDE "GDIMAGE.INC"

DECLARE FUNCTION MessageBox LIB "USER32.DLL" ALIAS "MessageBoxA" (BYVAL hWnd AS DWORD, lpText AS ASCIIZ, lpCaption AS ASCIIZ, BYVAL dwType AS DWORD) AS LONG

FUNCTION WinMain (BYVAL hInstance     AS LONG, _
                  BYVAL hPrevInstance AS LONG, _
                  BYVAL lpCmdLine     AS ASCIIZ PTR, _
                  BYVAL iCmdShow      AS LONG) AS LONG

    LOCAL So, nQuiet, nRet, imgW, imgH AS LONG, sFileToRead, sFileToSave AS STRING
'
    sFileToRead = LCASE$(command$)
    IF INSTR(sFileToRead, "/q") THEN sFileToRead = RTRIM$(REMOVE$(sFileToRead$, "/q")): nQuiet = -1

    So = INSTR(-1, sFileToRead, ".")
    sFileToSave = LEFT$(sFileToRead, So) + "png"

    IF RIGHT$(sFileToRead$, 4) = ".gif" THEN
       nRet = zSaveImageToFile((sFileToSave), ZI_CreateMultiFrameImage(zLoadImageFromFile((sFileToRead), imgW, imgH, 0), 32, %TRUE), 0)
       IF nRet = 0 AND nQuiet = 0 THEN ' Means no error
          CALL MessageBox(0, "Conversion done successfuly!", "Gif2png", 0)
       END IF
    END IF

END FUNCTION

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com