JL35
Nombre de messages : 7112 Localisation : 77 Date d'inscription : 29/11/2007
| Sujet: Impression d'une planche de photos sur A4 Dim 9 Mai 2010 - 16:56 | |
| Pour imprimer des séries de photos sur des feuilles A4 (de 1 à 60 photos par page, avec légende éventuelle). Ressources externes nécessaires: - IrfanView, pour la manipulation des images - WinTextPrint, l' excellent programme de Klaus (à télécharger sur son site), qui permet toutes les acrobaties en impression de textes et d'images: on peut considérer que c'est le moteur de ce programme-ci. J'ai essayé avec sa dll (KGF.dll) qui est encore plus puissante, mais je ne la maîtrise pas bien encore, alors le code figure, mais en attente (inutilisé), de toute façon WinTextPrint suffit largement. Les noms et emplacements des fichiers de manoeuvre et programmes externes sont comme d'habitude à modifier en fonction des conditions locales. Ils figurent tous en tête du programme, après la dernière directive LABEL. - Code:
-
' ******** PhotA4.bas impression de planches de photos sur feuille A4 ******** DIM w0, h0, t1, l1, w1, h1 DIM xmm, yd, xd, eh, ev, wi, hi, hr, wr, tp%, lp%, ty%, x, y DIM oo, nc, nr, nbt, ppic, dpic, npic, i%, j%, k%, r% DIM mg, md, mh, mb, lu, hu, legd DIM Type, ori(10), col(10), ran(10), ecv(10), ech(10), ww(10), hh(10) DIM img$(80), ima$(80), wim%(80), him%(80), dt$(80), wir%(80), hir%(80), lgn$(80) DIM wtp$, kgf$, iview$, f$, s$, sr$, rep$, fm$, tx$, nimp$ DIM fj$, fr$, fprn$, a$, w%, h%, dat$, nob, tob, hob, lob DIM Fonte$, szf% DIM phnd%, chnd%
LABEL Fin, Dimpic, Despic, Dir, Opt, Leg, Prepa, Jpgdim LABEL Chrep, Chimp, Prn, Prn1, dlof, Aide
wtp$ = "C:\Util\WinTextPrint.exe " iview$ = "C:\Progra~1\Irfanv~1\i_view32.exe " fm$ = "Z:\Dir.tmp" fprn$ = "Z:\Fprn.txt" kgf$ = "C:\Langages\Panoramic\KGF.dll" fj$ = fm$ Fonte$ = "Arial": ' Pour l'impression des légendes szf% = 10: ' taille fonte
mg = 2.5: md = 3.5: mh = 3: mb = 10: ' marges non imprimables sur A4 lu = 210 - mg - md: ' largeur utile sur la page A4, en millimètres hu = 297 - mh - mb: ' hauteur utile sur la page A4, en millimètres ' En fonction du Type: orientation (0: horizontal, 1: vertical), nb de colonnes, ' nb de rangées, écart vertical, écart horizontal, largeur image, hauteur image. ori(1) = 1: col(1) = 1: ran(1) = 1: ecv(1) = 4: ech(1) = 8: ww(1) = 204: hh(1) = 204*4/3 ori(2) = 0: col(2) = 1: ran(2) = 2: ecv(2) = 4: ech(2) = 8: ww(2) = 180: hh(2) = 135 ori(3) = 1: col(3) = 2: ran(3) = 2: ecv(3) = 4: ech(3) = 8: ww(3) = 100: hh(3) = 133 oo = 1: nc = 3: nr = 3: ev = 4: eh = 10: GOSUB Dimpic ori(4) = oo: col(4) = nc: ran(4) = nr: ecv(4) = ev: ech(4) = eh: ww(4) = wi: hh(4) = hi oo = 0: nc = 3: nr = 5: ev = 4: eh = 8: GOSUB Dimpic ori(5) = oo: col(5) = nc: ran(5) = nr: ecv(5) = ev: ech(5) = eh: ww(5) = wi: hh(5) = hi oo = 0: nc = 4: nr = 7: ev = 4: eh = 5: GOSUB Dimpic ori(6) = oo: col(6) = nc: ran(6) = nr: ecv(6) = ev: ech(6) = eh: ww(6) = wi: hh(6) = hi oo = 0: nc = 5: nr = 9: ev = 4: eh = 4: GOSUB Dimpic ori(7) = oo: col(7) = nc: ran(7) = nr: ecv(7) = ev: ech(7) = eh: ww(7) = wi: hh(7) = hi oo = 0: nc = 6: nr = 10: ev = 3: eh = 5: GOSUB Dimpic ori(8) = oo: col(8) = nc: ran(8) = nr: ecv(8) = ev: ech(8) = eh: ww(8) = wi: hh(8) = hi
w0 = 1024: h0 = 1024 WIDTH 0, w0: HEIGHT 0, h0 h1 = h0-80: w1 = h1*210/297: t1 = 20: l1 = w0-w1-40 PICTURE 99: TOP 99, t1+10: LEFT 99, l1+10: WIDTH 99, w1: HEIGHT 99, h1 COLOR 99, 160,160,160 PICTURE 100: TOP 100, t1: LEFT 100, l1: WIDTH 100, w1: HEIGHT 100, h1 2D_TARGET_IS 100: 2D_PEN_COLOR 160,160,160: 2D_RECTANGLE 0, 0, w1, h1 xmm = w1/210: ' 1 mm = xmm pixels
ppic = 101: dpic = ppic - 1 rep$ = ""
' Choix du format (rangées, colonnes) CONTAINER_OPTION 10: TOP 10, 70: LEFT 10, 20: WIDTH 10, 130: HEIGHT 10, 185 CAPTION 10, "NOMBRE D'IMAGES:" Option 11: Parent 11, 10: Top 11, 20: Left 11, 10: Caption 11, "1" Option 12: Parent 12, 10: Top 12, 40: Left 12, 10: Caption 12, "1 x 2" Option 13: Parent 13, 10: Top 13, 60: Left 13, 10: Caption 13, "2 x 2" Option 14: Parent 14, 10: Top 14, 80: Left 14, 10: Caption 14, "3 x 3" Option 15: Parent 15, 10: Top 15, 100: Left 15, 10: Caption 15, "3 x 5" Option 16: Parent 16, 10: Top 16, 120: Left 16, 10: Caption 16, "4 x 7" Option 17: Parent 17, 10: Top 17, 140: Left 17, 10: Caption 17, "5 x 9" Option 18: Parent 18, 10: Top 18, 160: Left 18, 10: Caption 18, "6 x 10" ON_CLICK 11, Opt ON_CLICK 12, Opt ON_CLICK 13, Opt ON_CLICK 14, Opt ON_CLICK 15, Opt ON_CLICK 16, Opt ON_CLICK 17, Opt ON_CLICK 18, Opt
' Choix de la légende éventuelle CONTAINER_OPTION 20: TOP 20, 70: LEFT 20, 160: WIDTH 20, 140: HEIGHT 20, 165 CAPTION 20, " LÉGENDES " OPTION 21: PARENT 21, 20: TOP 21, 20: LEFT 21, 10: CAPTION 21, "Aucune" OPTION 22: PARENT 22, 20: TOP 22, 40: LEFT 22, 10: CAPTION 22, "Nom" OPTION 23: PARENT 23, 20: TOP 23, 60: LEFT 23, 10: CAPTION 23, "Nom + Date" OPTION 24: PARENT 24, 20: TOP 24, 80: LEFT 24, 10: CAPTION 24, "Nom + Dimensions" ON_CLICK 21, Leg ON_CLICK 22, Leg ON_CLICK 23, Leg ON_CLICK 24, Leg
BUTTON 2: Top 2, 10: Left 2, 20: Width 2, 140 Caption 2, "Choix du répertoire": On_Click 2, Chrep BUTTON 3: Top 3, 10: Left 3, 160: Width 3, 140 Caption 3, "Imprimer": On_Click 3, Prn BUTTON 4: Top 4, 40: Left 4, 20: Width 4, 80 Caption 4, "Aide": On_Click 4, Aide BUTTON 5: Top 5, 40: Left 5, 220: Width 5, 80 Caption 5, "Quitter": On_Click 5, Fin
ALPHA 30: TOP 30, 260: LEFT 30, 20: CAPTION 30, "RÉPERTOIRE: " + rep$ LIST 31: TOP 31, 280: LEFT 31, 20: WIDTH 31, 280: HEIGHT 31, 680 FONT_NAME 31, "Arial": FONT_SIZE 31, 10 ON_CLICK 31, Prepa ALPHA 40: TOP 40, 3: LEFT 40, l1+w1/3: CAPTION 40, "IMPRESSION DE PLANCHES DE PHOTOS SUR A4" Type = 3: MARK_ON Type+10 legd = 2: MARK_ON legd+20
GOSUB Despic END
Fin: TERMINATE
' ============================== SOUS-PROGRAMMES =============================== Chrep: ' Choix du répertoire des images OPEN_DIALOG 98 f$ = FILE_NAME$(98) IF f$ = "_" THEN GOTO Fin FOR i% = LEN(f$) TO 1 STEP -1 IF MID$(f$, i%, 1) = "\" THEN EXIT_FOR NEXT i% rep$ = LEFT$(f$, i%) CAPTION 30, "Répertoire: " + rep$ GOSUB Dir FILE_LOAD 31, fm$: FILE_DELETE fm$ DELETE 98 RETURN
Chimp: DLL_ON kgf$: ' charge la dll de Klaus nimp$ = STRING$(255," ") r% = DLL_CALL2("SelectWindowsPrinter",ADR(nimp$),LEN(nimp$)) DLL_OFF RETURN
Prn: GOTO Prn1 ' Ci-dessous, partie utilisant la dll de Klaus, pas au point, inutilisée. ' ****** 210 mm = 4958 pixels, 297 mm = 7016 pixels (1mm ~ 23,62 pixels) ****** DLL_ON kgf$: ' charge la dll de Klaus nimp$ = STRING$(255," ") r% = DLL_CALL2("SelectWindowsPrinter",ADR(nimp$),LEN(nimp$)): ' choix imprimante IF r% = 0 THEN GOTO dlof ELSE PRINT "AAA" ' -> nimp$ = nom de l'imprimante choisie par l'opérateur s$ = "Impression": ' titre pour le queue manager de Windows r% = DLL_CALL4("PrinterManager",6,ADR(phnd%),ADR(s$),LEN(s$)) IF r% <> 1 THEN STOP ELSE PRINT "BBB" r% = DLL_CALL4("PrinterManager",1,ADR(phnd%),ADR(chnd%),0): ' début d'impression IF r% <> 1 THEN STOP ELSE PRINT "CCC" r% = DLL_CALL6("PrinterFunction",5,ADR(phnd%),ADR(chnd%),ADR(Fonte$),255,szf%) IF r% <> 1 THEN STOP ELSE PRINT "DDD" FOR j% = 1 TO nr ty% = (j%-1) * (hi+eh): ' position y FOR i% = 1 TO nc lp% = (i%-1) * (wi + ev): ' position x k% = (j%-1)*nc + i% r% = DLL_CALL4("PrinterFunction",4,0,ty%,lp%): ' posit absolu image IF r% <> 1 THEN STOP ELSE PRINT "EEE" a$ = ima$(k%) r% = DLL_CALL4("PrinterFunction",7,ADR(a$),wir%(k%),hir%(k%)) IF r% <> 1 THEN STOP ELSE PRINT "FFF" IF legd > 1 tp% = ty% + hir%(k%) r% = DLL_CALL4("PrinterFunction",4,0,tp%,lp%): ' posit absolu texte IF r% <> 1 THEN STOP ELSE PRINT "GGG" a$ = lgn$(k%) r% = DLL_CALL4("PrinterFunction",1,ADR(a$),LEN(a$),0) IF r% <> 1 THEN STOP ELSE PRINT "HHH" END_IF NEXT i% NEXT j% r% = DLL_CALL4("PrinterManager",3,ADR(phnd%),ADR(chnd%),0): ' Fin d'impression IF r% <> 1 THEN STOP ELSE PRINT"III" dlof: DLL_OFF RETURN
Prn1: ' Création du fichier d'impression, et lancement de WinTextPrint IF rep$ = "" OR img$(1) = "" THEN RETURN: ' pas d'images choisies File_Open_Write 1, Fprn$ FILE_WRITELN 1, "<#font=" + Fonte$ + "#><#fontsize=" + STR$(szf%) + "#>" FOR j% = 1 TO nr tp% = (j%-1) * (hi+eh) FOR i% = 1 TO nc lp% = (i%-1) * (wi + ev) k% = (j%-1)*nc + i% a$ = "<#image=" + ima$(k%) + "," + STR$(lp%) + "," + STR$(tp%) a$ = a$ + "," + STR$(wir%(k%)) + "," + STR$(hir%(k%)) + "#>" FILE_WRITELN 1, a$ IF legd > 1 a$ = "<#posabs=" + STR$(lp%) + "," + STR$(tp% + hir%(k%)) + "#>" a$ = a$ + lgn$(k%) FILE_WRITELN 1, a$ END_IF NEXT i% NEXT j% FILE_CLOSE 1 ' GOSUB Chimp: ' choix de l'imprimante (sinon, imprimante Windows implicite) a$ = "/file=" + fprn$ ' a$ = a$ + " /printer=" + CHR$(34) + nimp$ + CHR$(34) ' a$ = a$ + " /orientation=Portrait" a$ = a$ + " /noshow": ' mode silencieux EXECUTE wtp$ + a$ RETURN
Dimpic: ' dimensions de chaque vignette wi = INT((lu + ev*(1-nc))/nc) IF oo = 0 hi = INT(3*wi/4): ' images horizontales sur la page ELSE hi = INT(4*wi/3): ' images verticales sur la page END_IF RETURN
DesPic: ' Affichage des images dans chaque vignette nc = col(Type): nr = ran(Type): ev = ecv(Type): eh = ech(Type) wi = ww(Type): hi = hh(Type): nbt = nc*nr yd = t1 + xmm*mh: xd = l1 + xmm*mg IF (dpic-ppic) >= 0 FOR i% = ppic to dpic: DELETE i%: NEXT i% END_IF 2D_CLEAR: 2D_FILL_COLOR 255, 255, 255: 2D_RECTANGLE 0, 0, w1, h1 npic = ppic FOR j% = 1 TO nr tp% = yd + (j%-1)*(xmm*hi + xmm*eh) FOR i% = 1 TO nc lp% = xd + (i%-1)*(xmm*wi + xmm*ev) PICTURE npic: TOP npic, tp%: LEFT npic, lp% WIDTH npic, xmm*wi: HEIGHT npic, xmm*hi COLOR npic, 200, 255, 255 dpic = npic: npic = npic + 1 NEXT i% NEXT j% RETURN
Dir: ' Liste des images du répertoire choisi dans fm$ sr$ = DIR_CURRENT$ DIR_CHANGE rep$ FILE_OPEN_WRITE 1, fm$ f$ = FILE_FIND_FIRST$ WHILE f$ <> "_" s$ = UPPER$(RIGHT$(f$, 4)) IF s$ = ".JPG" OR s$ = ".BMP" THEN FILE_WRITELN 1, f$ f$ = FILE_FIND_NEXT$ END_WHILE FILE_FIND_CLOSE FILE_CLOSE 1 DIR_CHANGE sr$ RETURN
Opt: ' Clic sur une option de format FOR i% = 11 TO 18 IF CLICKED(i%) = 1 THEN EXIT_FOR NEXT i% Type = i% - 10: GOSUB Despic RETURN
Leg: ' Clic sur une option de légende FOR i% = 21 TO 24 IF CLICKED(i%) = 1 THEN EXIT_FOR NEXT i% legd = i% - 20: GOSUB Despic RETURN
Prepa: ' Préparation des images à partir du fichier image cliqué et suivants PRINT_TARGET_IS 0: FONT_NAME 0, "Arial": FONT_SIZE 0, 10 IF Type > 5 THEN FONT_SIZE 0, 8 j% = ITEM_INDEX(31): ' élément cliqué FOR i% = 1 TO nc*nr IF (j% + i% - 1) > COUNT(31) THEN EXIT_FOR s$ = ITEM_READ$(31, j% + i% - 1) f$ = rep$ + s$ img$(i%) = f$ GOSUB Jpgdim wim%(i%) = w%: him%(i%) = h%: dt$(i%) = dat$ ima$(i%) = f$: wr = w%: hr = h% wir%(i%) = wi: hir%(i%) = hi IF (w% > h% AND ori(Type) = 1) OR (w% <= h% AND ori(Type) = 0) fr$ = "Z:\Image"+STR$(i%)+".jpg" EXECUTE_WAIT iview$ + f$ + " /rotate_l /convert=" + fr$ ima$(i%) = fr$ k% = w%: w% = h%: h% = k% END_IF nob = ppic + i% - 1 wr = wi: hr = hi IF (w%/h%) > (wi/hi) hr = wi*h%/w%: HEIGHT nob, xmm*hr ELSE IF (w%/h%) < (wi/hi) wr = hi*w%/h%: WIDTH nob, xmm*wr END_IF END_IF IF wr <> wi OR hr <> hi THEN wir%(i%) = wr: hir%(i%) = hr FILE_LOAD nob, ima$(i%): STRETCH_ON nob tob = TOP(nob): lob = LEFT(nob): hob = HEIGHT(nob) lgn$(i%) = "" IF legd > 1 tx$ = s$ IF legd = 3 tx$ = s$ + " " + dat$ ELSE IF legd = 4 tx$ = s$ + " ("+STR$(wim%(i%))+"x"+STR$(him%(i%))+")" END_IF END_IF lgn$(i%) = tx$ PRINT_LOCATE lob, tob+hob: PRINT tx$ end_if NEXT i% RETURN
Jpgdim: ' caractéristiques du fichier jpg f$: w%, h%, dat$ (appel fonction d'IrfanView) EXECUTE_WAIT iview$ + f$ + " /info=" + fj$ FILE_OPEN_READ 80, fj$ REPEAT FILE_READLN 80, a$ UNTIL LEFT$(a$, 16) = "Image dimensions" a$ = MID$(a$, 20, LEN(a$)-19) k% = INSTR(a$, " "): w% = VAL(LEFT$(a$, k%-1)) a$ = MID$(a$, k% + 3, LEN(a$) - k% - 2) k% = INSTR(a$, " ") : h% = VAL(LEFT$(a$, k%-1)) REPEAT FILE_READLN 80, a$ UNTIL LEFT$(a$, 9) = "File date" dat$ = MID$(a$, 18, 10): dat$ = dat$ + MID$(a$, 30, 6) FILE_CLOSE 80: FILE_DELETE fj$ RETURN
Aide: a$ = "** IMPRESSION D'UNE PLANCHE DE PHOTOS SUR UNE PAGE A4 **" a$ = a$ + chr$(10)+chr$(10) a$ = a$ + "- Choisir le format d'impression (nombre d'images sur la page):" a$ = a$ + chr$(10) + chr$(9)+"Cliquer l'option choisie (de 1 à 60 images par page)." a$ = a$ + chr$(10)+chr$(10) a$ = a$ + "- Choisir le répertoire contenant les images à imprimer:"+chr$(10) a$ = a$ + chr$(9)+"- Cliquer sur 'Choix du répertoire', parcourir les répertoires," a$ = a$ + chr$(10) + chr$(9)+" et cliquer sur une image quelconque du répertoire." a$ = a$ + chr$(10) + chr$(9)+"- Puis, cliquer dans la liste affichée sur le nom de" a$ = a$ + chr$(10) + chr$(9)+" l'image qui sera la première de la série à imprimer." a$ = a$ + chr$(10) + chr$(10) a$ = a$ + "- Choisir le type de légende éventuel de chaque image." a$ = a$ + chr$(10)+chr$(10) a$ = a$ + " (on peut modifier les options avant impression)." a$ = a$ + chr$(10) + chr$(10) a$ = a$ + "- Imprimer: cliquer sur le bouton 'Imprimer':" a$ = a$ + chr$(10) + chr$(9) + " -> impression sur l'imprimante implicite Windows." MESSAGE a$ RETURN | |
|