i have a png file. that will serve as a tile. this tile will be flipped. horizontally and vertically. to create a symmetric image. that will be larger than my display screen.
in other words. for 2x2 tile. first the original tile. then next to it horizontally. it is flipped horizontally. then the two tiles just below. are the same thing. but both flipped vertically. so that the 2x2 image is symmetrical. then this 2x2 image. is used to create another image. which is larger than the display screen.
the display screen is 1366x768. the png image will be much smaller than this. usually below 200 pixels in both dimensions. i round off on purpose to even numbers.
how do i crop this large image. so the display screen is symmetrical all around? horizontally as well as vertically?
i have this program. if i'm lucky. it falls into place like expected. but sometimes it doesn't do it right horizontally. or doesn't do it right vertically.
use your own png files. it's recommended they are smaller than 200x200. unless you have a much larger screen than mine.
originally the output of this program. was jpeg format. converted with imagemagick. because qb64 phoenix doesn't offer jpeg saving with compression.
hsiangch_ong-backflip-batch.zip (Size: 128.21 KB / Downloads: 32)
in other words. for 2x2 tile. first the original tile. then next to it horizontally. it is flipped horizontally. then the two tiles just below. are the same thing. but both flipped vertically. so that the 2x2 image is symmetrical. then this 2x2 image. is used to create another image. which is larger than the display screen.
the display screen is 1366x768. the png image will be much smaller than this. usually below 200 pixels in both dimensions. i round off on purpose to even numbers.
how do i crop this large image. so the display screen is symmetrical all around? horizontally as well as vertically?
i have this program. if i'm lucky. it falls into place like expected. but sometimes it doesn't do it right horizontally. or doesn't do it right vertically.
Code: (Select All)
'by hsiangch_ong 20-aug-2025
OPTION _EXPLICIT
DIM AS LONG scr, scrout, scr1, wd, ht, wd1, ht1, xx, yy, u, j, ll
DIM AS _BYTE flipx, flipy
DIM AS INTEGER doxflip
DIM afile$, bfile$, apath$
REDIM sf(1 TO 1) AS STRING
'change the following path to what you want in your system.
'especially if you're on macos. (i forgot which is the precise user home directory.)
'copy the provided png files to this directory.
'this program's output is the same directory.
$IF LINUX THEN
apath$ = ENVIRON$("HOME") + "/Pictures/backf"
$ELSE
apath$ = ENVIRON$("USERPROFILE") + "/Pictures/backf"
$END IF
afile$ = _FILES$(apath$)
DO UNTIL afile$ = ""
IF RIGHT$(afile$, 4) = ".png" THEN
ll = ll + 1
REDIM _PRESERVE sf(1 TO ll) AS STRING
sf(ll) = apath$ + "/" + afile$
END IF
afile$ = _FILES$
LOOP
FOR j = 1 TO ll
scr = _LOADIMAGE(sf(j), 32)
IF scr >= -1 THEN
_MESSAGEBOX "Backflip", "Failed to load image:" + CHR$(13) + sf(j), "error"
SYSTEM
END IF
wd = _WIDTH(scr)
ht = _HEIGHT(scr)
wd1 = wd
ht1 = ht
doxflip = 0
DO UNTIL wd1 >= 1366
doxflip = doxflip + 1
wd1 = wd1 + wd
LOOP
DO UNTIL ht1 >= 768: ht1 = ht1 + ht: LOOP
scr1 = _NEWIMAGE(wd1, ht1, 32)
scrout = _NEWIMAGE(1366, 768, 32)
IF scr1 >= -1 THEN
_FREEIMAGE scr
_MESSAGEBOX "Backflip", "There isn't enough memory for an image that large!", "error"
SYSTEM
END IF
IF scrout >= -1 THEN
_FREEIMAGE scr1
_FREEIMAGE scr
_MESSAGEBOX "Backflip", "There isn't enough memory for two images!", "error"
SYSTEM
END IF
u = INSTR(sf(j), ".")
afile$ = LEFT$(sf(j), u - 1) + "-neu.png"
_TITLE "Backflip - SAVING " + afile$
flipx = 0
flipy = 0
FOR yy = 0 TO ht1 STEP ht
FOR xx = 0 TO wd1 STEP wd
IF flipy THEN
IF flipx THEN
_PUTIMAGE (xx + wd - 1, yy + ht - 1)-(xx, yy), scr, scr1
ELSE
_PUTIMAGE (xx, yy + ht - 1)-(xx + wd - 1, yy), scr, scr1
END IF
ELSE
IF flipx THEN
_PUTIMAGE (xx + wd - 1, yy)-(xx, yy + ht - 1), scr, scr1
ELSE
_PUTIMAGE (xx, yy)-(xx + wd - 1, yy + ht - 1), scr, scr1
END IF
END IF
flipx = NOT flipx
NEXT
IF doxflip MOD 2 > 0 THEN flipx = NOT flipx
flipy = NOT flipy
NEXT
wd = (wd1 - 1366) \ 2
ht = (ht1 - 768) \ 2
_PUTIMAGE (0, 0)-(1365, 767), scr1, scrout, (wd, ht)-(wd + 1365, ht + 767)
_SAVEIMAGE afile$, scrout
_FREEIMAGE scrout
_FREEIMAGE scr1
_FREEIMAGE scr
PRINT "Saved: "; afile$
NEXT
PRINT "COMPLETED"
_TITLE "Backflip - COMPLETED"
_DELAY 3
SYSTEMoriginally the output of this program. was jpeg format. converted with imagemagick. because qb64 phoenix doesn't offer jpeg saving with compression.
hsiangch_ong-backflip-batch.zip (Size: 128.21 KB / Downloads: 32)

