|
Post by vovchik on Aug 7, 2020 10:39:04 GMT 1
Dear Alex,
I have to revise that "divisible by 2" check. It's in the wrong place, since it is reporting a warning at every invocation. I have to find the right spot for it. If you already have, please let me know.
With kind regards, vovchik
|
|
|
Post by alexfish on Aug 8, 2020 0:04:57 GMT 1
My appolls
should have been
new_w, new_h
how ever, still think this is wrong so now looking further.
how about if 'odd'
BR Alex
|
|
|
Post by alexfish on Aug 8, 2020 1:17:15 GMT 1
Agh , now see what you mean by auto aspect ,
how ever
code reveals
SUB PROCESS_DATA() ' -----------
LOCAL ckw,ckh TYPE int zoom_quality = (int)GDK_INTERP_HYPER IF old_file_type$ = "svg" THEN im2 = gdk_pixbuf_new_from_file(org_file$, NULL) gdk_pixbuf_save(im2, "/tmp/picscale.png", "png", 0,NULL, NULL, NULL) im2 = gdk_pixbuf_new_from_file("/tmp/picscale.png", NULL) ELSE im2 = gdk_pixbuf_new_from_file(org_file$, NULL) END IF w = gdk_pixbuf_get_width(im2)
h = gdk_pixbuf_get_height(im2) r_x = t_width / w r_y = t_height / h IF t_height EQ t_width THEN new_w = t_width new_h = t_height ELSE IF r_x <=r_y THEN new_w = t_width new_h = h * r_x + 1 ELSE new_w = w * r_y + 1 new_h = t_height END IF END IF im = gdk_pixbuf_scale_simple(im2, new_w, new_h, zoom_quality) ckw = gdk_pixbuf_get_width(im) ckh = gdk_pixbuf_get_height(im) PRINT ckw PRINT ckh IF ( ODD(new_w) ) THEN PRINT "Warning: width result not divisible by 2 : ", ckw , ":" , new_w
END IF
IF ( ( ODD(new_h) ) ) THEN PRINT "Warning: height result not divisible by 2 : ", ckh , ":" , new_h
END IF
SELECT new_file_type$ CASE "png" gdk_pixbuf_save(im, new_file$, new_file_type$, NULL, "compression", new_quality$, NULL) CASE "jpeg" new_quality$ = quality$ gdk_pixbuf_save(im, new_file$, new_file_type$, NULL, "quality", new_quality$, NULL) CASE "tiff" new_quality$ = quality$ gdk_pixbuf_save(im, new_file$, new_file_type$, NULL, "compression", new_quality$, NULL) CASE "ico" new_quality$ = quality$ gdk_pixbuf_save(im, new_file$, new_file_type$, NULL, "depth", new_quality$, NULL) DEFAULT gdk_pixbuf_save(im, new_file$, new_file_type$, NULL, NULL, NULL, NULL) END SELECT ' warn of w or h is not divisible by 2
g_object_unref(im) g_object_unref(im2) END SUB
and this is the results of the new image bacon eyes call
./picscale -i eyes.png -o new.png 217 201 1 202 201 Warning: height result not divisible by 2 : 201:201 File new.png created. Original image: eyes.png New dimensions (w x h): 217 x 201 Quality of new image: 1
what i get from request 217*201 is an image of 202 * 201
how ever
SUB PROCESS_DATA() ' -----------
LOCAL ckw,ckh TYPE int zoom_quality = (int)GDK_INTERP_HYPER IF old_file_type$ = "svg" THEN im2 = gdk_pixbuf_new_from_file(org_file$, NULL) gdk_pixbuf_save(im2, "/tmp/picscale.png", "png", 0,NULL, NULL, NULL) im2 = gdk_pixbuf_new_from_file("/tmp/picscale.png", NULL) ELSE im2 = gdk_pixbuf_new_from_file(org_file$, NULL) END IF
im = gdk_pixbuf_scale_simple(im2, t_width, t_height, zoom_quality) ckw = gdk_pixbuf_get_width(im) ckh = gdk_pixbuf_get_height(im) PRINT ckw PRINT ckh IF ( ODD(ckw) ) THEN PRINT "Warning: width result not divisible by 2 : ", ckw
END IF
IF ( ( ODD(ckh) ) ) THEN PRINT "Warning: height result not divisible by 2 : ", ckh
END IF
SELECT new_file_type$ CASE "png" gdk_pixbuf_save(im, new_file$, new_file_type$, NULL, "compression", new_quality$, NULL) CASE "jpeg" new_quality$ = quality$ gdk_pixbuf_save(im, new_file$, new_file_type$, NULL, "quality", new_quality$, NULL) CASE "tiff" new_quality$ = quality$ gdk_pixbuf_save(im, new_file$, new_file_type$, NULL, "compression", new_quality$, NULL) CASE "ico" new_quality$ = quality$ gdk_pixbuf_save(im, new_file$, new_file_type$, NULL, "depth", new_quality$, NULL) DEFAULT gdk_pixbuf_save(im, new_file$, new_file_type$, NULL, NULL, NULL, NULL) END SELECT ' warn of w or h is not divisible by 2
g_object_unref(im) g_object_unref(im2) END SUB
gives what I request::
how about a flag for both
1 for preserve aspect & 0 not to preserve
BR Alex
|
|
|
Post by vovchik on Aug 8, 2020 12:09:00 GMT 1
Dear Alex,
I think the flag idea is good, but there are a few ways we can implement that. For example, we could use a -1 for the new height dimension and let the program preserve the aspect ratio and calculate the new height; if the height dimension is not -1, then stretch or shrink the image as per both dimensions supplied on the command line.
what do you think?
With kind regards, vovchik
|
|
|
Post by alexfish on Aug 10, 2020 0:11:25 GMT 1
Hi Vovchik
sounds good to me.
Looking forward to the new bits,
since wanting to make a ui terminal using xcb cairo & libptytty as a first demo, where by one can see the results of in png format
BR Alex
|
|