Convert image to png
Aug 3, 2020 10:27:34 GMT 1
Post by alexfish on Aug 3, 2020 10:27:34 GMT 1
Hi All
I needed to convert images from one format to png format for direct use in cairo.
Think there used to be an image converter or scale image on the web site;
could not find it, hence the below ' BaCon convert2png 'image2png' depends lib-gdk-pixbuf-2.0
Have Fun
+
BR
Alex
I needed to convert images from one format to png format for direct use in cairo.
Think there used to be an image converter or scale image on the web site;
could not find it, hence the below ' BaCon convert2png 'image2png' depends lib-gdk-pixbuf-2.0
Have Fun
+
BR
Alex
'BaCon convert2png 'image2png' depends lib-gdk-pixbuf-2.0
'
' Synop cairo can only import png as a surface
' cairo_surface_t * pixy =cairo_image_surface_create_from_png(myimage.png);
' cairo_set_source_surface (cr2,pixy,xpos,ypos);
' cairo_paint(cr2);
' cairo_surface_destroy (pixy);
'
' but also a handy little tool;
' licence any *nix **** , if it breaks you keep both bits 'FREE';
' alexfish@basic-converter.org
OPTION PARSE FALSE
'Compiler Flags
PRAGMA LDFLAGS `pkg-config --libs gdk-pixbuf-2.0`
PRAGMA OPTIONS `pkg-config --cflags gdk-pixbuf-2.0`
PRAGMA INCLUDE <gdk-pixbuf/gdk-pixbuf.h>
' IO VARS
DECLARE INFILE$ TYPE STRING
DECLARE OUTFILE$ TYPE STRING
DECLARE NB$ TYPE STRING
DECLARE RES$ TYPE STRING
DECLARE pixbuf TYPE GdkPixbuf *
IF argc == 3 THEN
INFILE$= CHOP$(argv[1])
OUTFILE$=CHOP$(argv[2])
IF FILEEXISTS(INFILE$) THEN
PRINT " FILE OK"
RES$ = EXEC$ ("file " & INFILE$)
ck = INSTR(RES$,"image")
IF (ck > 1) THEN
PRINT "File is image"
ELSE
PRINT "Not Image"
IF (INSTR(INFILE$,".svg")) THEN
PRINT "Trying to convert svg file"
ELSE
PRINT "File wrong type"
END
END IF
END IF
ELSE
PRINT " File NOT EXIST"
END
END IF
PRINT INFILE$
PRINT OUTFILE$
NB$ = RIGHT$(OUTFILE$,4)
IF NB$ = ".png" THEN
PRINT "Converting " , INFILE$ , " 2 " ,OUTFILE$
ELSE
PRINT "out file must be <file>.png"
END
END IF
pixbuf = gdk_pixbuf_new_from_file (INFILE$,0)
g_object_ref(pixbuf)
gdk_pixbuf_save (pixbuf, OUTFILE$, "png", 0,NULL, NULL, NULL)
g_object_unref(pixbuf)
END
END IF
PRINT " convert2png image-file.* outfile.png\n convert2png img.jpg img.png\n convert2png tiger.svg tiger.png"