graphic function ttg_resize()

If you want to change the size of an image, use this function. The parameters should be self-explanatory. The original image will not be changed by this procedure.
The resizing is done by the library CXIMAGE which is included in homercx.dll
please find the image-file-extensions we checked and use in ttg_resize in the help for is_cximage().
We do recommend to keep the format (=extension) when resizing images. (errors converting .gif or .png to other formats - if you try, check the result carefully!). The only exception recommended is to convert .bmp to .jpg because of the massive reduction of file size. (Caution: in case you use markers in the images you must stay with .bmp files! Jpg is a lossy compression and the images might not include identical marker pixels in different browsers!
Parameters:
1. fullpath of input image2. fullpath of output image
3. faktor to enlarge (>1) or shrink (<1)
4. modify image:
***************************** | |
* Tool&Task example program * | |
* ttg_resize() * | |
* last compile: 12.07.2022 * | |
***************************** |
* program to generate images.dbf is included | |
* in help for topic 'adir' | |
LOCAL lfile, lfily, lxy, lfak, l_ok_count, lbmp2jpg, l_small_edge, l_large_edge | |
LOCAL loriname | |
tt_use_table("IMAGES", "TEMP\") | |
lbmp2jpg = .t. |
&& convert bmp to jpg |
l_small_edge = 160 |
&& exactly 160 Pixels |
l_large_edge = 1000 |
&& or smaller (if original is smaller) |
takt = RECCOUNT() /100 |
&& English for Takt is 'cycle' |
taktg = takt |
&& next step for progression bar |
takth = 0 |
&& record counter |
DO act_therm WITH "resizing images ... " |
&& open progression bar |
DO WHILE NOT EOF() | |
IF images.done < 2 | |
l_ok_count = 0 |
&& when we get at 2 done is set to 2 |
lfile = ALLTRIM(images.dirname) + ALLTRIM(images.filename) | |
* do we have an original (caution lfile has no extension yet) | |
IF NOT EMPTY(images.ext) |
&& does it have a _t_o marker? |
loriname = lfile + "_t_o" + ALLTRIM(images.ext) | |
IF NOT tt_file(loriname) |
&& if not, it has no marker yet |
RENAME (lfile+ALLTRIM(images.ext)) TO (loriname) | |
ENDIF | |
IF tt_file(loriname) |
&& otherwise there was no original |
lorimax = MAX(images.owidth, images.oheight) | |
IF 0 == images.swidth |
&& no small file there |
lfak = l_small_edge / lorimax | |
* if the image was smaller, it will be upsized! | |
* keep the graphic type! (Errors converting gif to jpg) | |
* exeption if lbmp2jpg is .t. convert .bmp | |
IF ALLTRIM(images.ext) == ".bmp" AND lbmp2jpg | |
lfily = lfile + ".jpg" | |
else | |
lfily = lfile + ALLTRIM(images.ext) | |
endif | |
lxy = ttg_resize(loriname, lfily, lfak, 0) | |
IF NOT EMPTY(lxy) | |
replace images.swidth WITH get_x(lxy) IN images | |
replace images.sheight WITH get_y(lxy) IN images | |
l_ok_count = l_ok_count + 1 | |
ENDIF | |
ELSE | |
l_ok_count = l_ok_count + 1 | |
ENDIF | |
IF 0 == images.xwidth |
&& no large file there |
IF lorimax <= l_large_edge | |
* if the max edge of original is smaller or equal | |
* to l_large_edge: copy to filename including marker | |
* if lbmp2jpg is set, no bmp please | |
IF ALLTRIM(images.ext) == ".bmp" AND lbmp2jpg | |
ttg_resize(loriname, lfile + "_t_l.jpg", 1, 0) | |
else | |
tt_copy(loriname, lfile + "_t_l" + ALLTRIM(images.ext)) | |
endif | |
replace images.xwidth WITH images.owidth IN images | |
replace images.xheight WITH images.oheight IN images | |
l_ok_count = l_ok_count + 1 | |
ELSE | |
lfak = l_large_edge / lorimax | |
* keep the graphic type! (Errors converting png to jpg) | |
* exeption if lbmp2jpg is .t. convert .bmp to .jpg | |
* bmp to jpg is no problem! (CAUTION: bmp-marker) | |
IF ALLTRIM(images.ext) == ".bmp" AND lbmp2jpg | |
lfily = lfile + "_t_l.jpg" | |
else | |
lfily = lfile + "_t_l" + ALLTRIM(images.ext) | |
endif | |
lxy = ttg_resize(loriname, lfily, lfak, 0) | |
IF NOT EMPTY(lxy) |
&& file is ok |
* keep the values for the large file | |
replace images.xwidth WITH get_x(lxy) IN images | |
replace images.xheight WITH get_y(lxy) IN images | |
l_ok_count = l_ok_count + 1 | |
endif | |
ENDIF | |
ELSE | |
l_ok_count = l_ok_count + 1 | |
endif | |
replace images.done WITH l_ok_count IN images | |
ENDIF | |
endif | |
ENDIF | |
SKIP | |
takth = takth + 1 |
&& this counts records |
DO WHILE takth > taktg |
&& 1 record could be more than 1 takt! |
taktg = taktg + takt |
&& takt = reccount()/100 |
DO upd_therm WITH taktg/takt |
&& 100 steps |
enddo | |
enddo | |
tt_release_table("IMAGES") | |
DO deact_therm |
&& close progression bar |
return |