
J'utilise ce script pour Mettre en ligne des images avec phpWebgallery.
J'attend vos avis, corrections ... et encouragement

► Afficher le texte
Code : Tout sélectionner
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#Include <File.au3>
#include <array.au3>
#Region Variables
Global $destinationdefaut = @MyDocumentsDir&"\Photos"
Global $DestinationUsers
Global $sourceImages
Global $Tridemande
Global $chemin
Global $longeur,$largeur,$ratio,$file
dim $Tridemande = "date"
#EndRegion
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Imagesredim", 310, 550, 193, 125)
$Group1 = GUICtrlCreateGroup("Tailles des Images après traitement :", 8, 24, 289, 145)
$Label1 = GUICtrlCreateLabel("Taille de L'image : ", 32, 56, 116, 17)
$Label2 = GUICtrlCreateLabel("Taille de la Mignature : ", 32, 96, 122, 17)
$IMP_imgred = GUICtrlCreateInput("", 160, 56, 65, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$IMP_imgmin = GUICtrlCreateInput("", 160, 96, 65, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$Label3 = GUICtrlCreateLabel("Ex : 600", 232, 56, 43, 17)
$Label4 = GUICtrlCreateLabel("Ex : 250", 232, 96, 43, 17)
$Les = GUICtrlCreateLabel("Les Proportions des images seront concervés ", 40, 128, 221, 17)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Rangement des Images :", 8, 183, 291, 145)
$RBdate = GUICtrlCreateRadio("Rangement des images par date :", 32, 217, 241, 17)
GUICtrlSetState($RBdate, $GUI_CHECKED)
$RBAlpha = GUICtrlCreateRadio("Rangement des images par ordre alphabétique", 32, 249, 241, 17)
$RBVRAC = GUICtrlCreateRadio("Rangement des Images sans arboressance", 32, 281, 249, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("Selections des Dossiers : :", 8, 346, 289, 145)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$BTNSource = GUICtrlCreateButton("Repertoire Source", 168, 386, 115, 25, 0)
$Btndest = GUICtrlCreateButton("Repertoire Destination", 168, 426, 115, 25, 0)
$LBSources = GUICtrlCreateLabel("", 24, 386, 124, 28)
$LBdesti = GUICtrlCreateLabel("", 24, 426, 124, 28)
$BtnGo = GUICtrlCreateButton("Executer", 144, 509, 75, 25, 0)
$BTNQuitter = GUICtrlCreateButton("Quitter", 224, 509, 75, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
$tab=StringSplit(@MyDocumentsDir,"\")
GUICtrlSetData($LBdesti,$tab[$tab[0]]&"\Photos")
#EndRegion ### END Koda GUI section ###
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $BTNQuitter
Exit
case $BTNSource
$dossier = FileSelectFolder("Choisir un dossier ? (Merci de sélectionnez le dossier) ", " ")
$sourceImages = $dossier
$tab=StringSplit($dossier,"\")
if $dossier <> @HomeDrive&"\" then
GUICtrlSetData($LBSources,$tab[$tab[0]])
Else
GUICtrlSetData($LBSources,@HomeDrive&"\")
endif
case $Btndest
$dossier = FileSelectFolder("Choisir un dossier ? (Merci de sélectionnez le dossier) ", " ")
$DestinationUsers = $dossier
$tab=StringSplit($dossier,"\")
if $dossier <> @HomeDrive&"\" then
GUICtrlSetData($LBdesti,$tab[$tab[0]])
Else
GUICtrlSetData($LBdesti,@HomeDrive&"\")
endif
Case $RBdate
$Tridemande = "date"
Case $RBAlpha
$Tridemande = "Alpha"
Case $RBVRAC
$Tridemande = "Vrac"
Case $BtnGo
if $sourceImages <> "" then
if GUICtrlRead($IMP_imgred) <> "" then
if GUICtrlRead($IMP_imgmin) <> "" then
_Verifpresencefichier()
Else
MsgBox(0,"Attention","Un entier est demandé en taille de mignature")
EndIf
Else
MsgBox(0,"Attention","Un entier est demandé en taille d'image")
EndIf
Else
MsgBox(0,"Attention","Merci de séléctionner un repertoire contenant des images .JPG")
endif
EndSwitch
WEnd
Func _Verifpresencefichier()
SplashTextOn("","Créations de l'arboressance puis des images, merci de patienter", 600, 80, -1, -1, 33, "Verdana", 12)
$listeFichiers = _FileListToArray($sourceImages,"*.jpg",1)
if @error = 4 Then
SplashOff()
MsgBox(0,"erreur","Aucune image .JPG n'a trouvé dans le repertoire source")
Else
$file = $sourceImages&"\"&$listeFichiers
For $i=1 to $listeFichiers[0]
TrayTip("Information","Traitement en cours pour l'image : "&$listeFichiers[$i],1)
$file = $sourceImages&"\"&$listeFichiers[$i]
If $Tridemande = "date" Then
$t = FileGetTime($file , 1)
$chemin= $DestinationUsers&"\photos\"&$t[0]&$t[1]&$t[2]
_appel($file,$chemin)
EndIf
If $Tridemande = "Alpha" then
$res = StringSplit($file,"\")
$t = StringLeft($res[$res[0]], 1)
$chemin= $DestinationUsers&"\photos\"&$t
_appel($file,$chemin)
EndIf
If $Tridemande = "Vrac" then
$chemin= $DestinationUsers
_appel($file,$chemin)
EndIf
Next
endif
SplashOff()
EndFunc
Func _appel($file,$chemin)
DirCreate($chemin)
if @error = 1 Then
MsgBox(0,"erreur","impossible de créer le repertoire : " &$chemin)
Exit
EndIf
DirCreate($chemin&"\thumbnail")
if @error = 1 Then
MsgBox(0,"erreur","impossible de créer le repertoire :" &$chemin&"\thumbnail")
Exit
EndIf
$tableau = StringSplit($file,"\")
$x = $tableau[0]
$nomimage = $tableau[$x]
$aSize = _GetJpegSize($file)
if @error then Exit
$longeur = $aSize[0]
$largeur = $aSize[1]
$dim = GUICtrlRead($IMP_imgred)
_nouvellesdimention($dim)
_ImageResize($file, $chemin &"\"&$nomimage,$longeur, $largeur)
if @error = 1 Then
MsgBox(0,'Erreur',"Le fichier cible n'existe pas")
ElseIf @error = 2 Then
MsgBox(0,"Erreur","le format du fichier n'est pas valide")
ElseIf @error = 3 Then
MsgBox(0,"Erreur","Le fichier de sortie n'existe pas")
ElseIf @error = 4 Then
MsgBox(0,"Erreur","Le format du fichier de sortie n'est pas valide")
ElseIf @error = 5 Then
MsgBox(0,"Erreur","La taille indiqué pour le fichier sortie n'est pas valide")
EndIf
$dim = GUICtrlRead($IMP_imgmin)
_nouvellesdimention($dim)
_ImageResize($file, $chemin&"\thumbnail" &"\TN-"&$nomimage,$longeur, $largeur)
if @error = 1 Then
MsgBox(0,'Erreur',"Le fichier cible n'existe pas")
ElseIf @error = 2 Then
MsgBox(0,"Erreur","le format du fichier n'est pas valide")
ElseIf @error = 3 Then
MsgBox(0,"Erreur","Le fichier de sortie n'existe pas")
ElseIf @error = 4 Then
MsgBox(0,"Erreur","Le format du fichier de sortie n'est pas valide")
ElseIf @error = 5 Then
MsgBox(0,"Erreur","La taille indiqué pour le fichier sortie n'est pas valide")
EndIf
EndFunc
;******************************** _GetJpegSize *******************************
Func _GetJpegSize($file)
Local $size[2]
Local $fs, $pos = 3
if not (_FileReadAtOffsetHEX ($file, 1, 2) = "FFD8") then
SetError(1); Not Jpeg
Return("")
endif
$fs = FileGetSize($file)
While $pos < $fs
$data = _FileReadAtOffsetHEX ($file, $pos, 4)
if StringLeft($data, 2) = "FF" then; Valid segment start
if StringInStr("C0 C2 CA C1 C3 C5 C6 C7 C9 CB CD CE CF", StringMid($data, 3, 2)) then; Segment with size data
$seg = _FileReadAtOffsetHEX ($file, $pos+5, 4)
$size[1] = Dec(StringLeft($seg, 4))
$size[0] = Dec(StringRight($seg, 4))
Return($size)
else
$pos = $pos + Dec(StringRight($data, 4)) + 2
endif
else
exitloop
endif
Wend
SetError(2); Segment not found
Return("")
EndFunc
Func _FileReadAtOffsetHEX ($file, $offset, $bytes)
Local $tfile = FileOpen($file, 0)
Local $tstr = ""
FileRead($tfile, $offset-1)
For $i = $offset To $offset + $bytes - 1
$tstr = $tstr & Hex(Asc(FileRead($tfile, 1)), 2)
Next
FileClose($tfile)
Return ($tstr)
Endfunc
Func _ImageResize($sInImage, $sOutImage, $iW, $iH)
Local $sOP, $sOF, $sInExt, $Ext, $hBitmap, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0
Local $sType = "BMP|GIF|ICO|JPG|JPEG|PNG|TIF|TIFF"
If Not FileExists($sInImage) Then Return SetError(1, 0, 0)
$sInExt = StringUpper(StringTrimLeft($sInImage, StringInStr($sInImage, ".", 0, -1)))
If Not StringRegExp($sInExt, "\A(" & $sType & ")\z", 0) Then Return SetError(2, 0, 0)
;OutFile path, to use later on.
$sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))
If Not FileExists($sOP) Then Return SetError(3, 0, 0)
;OutFile name, to use later on.
$sOF = StringTrimLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))
;OutFile extension , to use for the encoder later on.
$Ext = StringUpper(StringTrimLeft($sOutImage, StringInStr($sOutImage, ".", 0, -1)))
If Not StringRegExp($Ext, "\A(" & $sType & ")\z", 0) Or $Ext = "ICO" Then Return SetError(4, 0, 0)
If Not IsInt($iW) And Not IsInt($iH) Then Return SetError(5, 0, 0)
$hBitmap = _WinAPI_CreateCompatibleBitmapSection($iW,$iH)
;Start GDIPlus
_GDIPlus_Startup()
;Get the handle of blank bitmap you created above as an image
$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
;Load the image you want to resize.
$hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)
;Get the graphic context of the blank bitmap
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)
;Draw the loaded image onto the blank bitmap at the size you want
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH)
;Get the encoder of to save the resized image in the format you want.
$CLSID = _GDIPlus_EncodersGetCLSID($Ext)
;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image.
Do
$i += 1
Until (Not FileExists($sOP & $i & "_" & $sOF))
;Prefix the number to the begining of the output filename
$sOutImage = $sOP & $sOF
;Save the new resized image.
_GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID)
;Clean up and shutdown GDIPlus.
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_GraphicsDispose($hGraphic)
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_Shutdown()
Return SetError(0, 0, 1)
EndFunc ;==>_ImageResize
Func _WinAPI_CreateCompatibleBitmapSection($iWidth,$iHeight,$iBitCount=24)
$tBMI = DllStructCreate($tagBITMAPINFO)
DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
DllStructSetData($tBMI, "Width", $iWidth)
DllStructSetData($tBMI, "Height", $iHeight)
DllStructSetData($tBMI, "Planes", 1)
DllStructSetData($tBMI, "BitCount", $iBitCount)
$aDIB = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', _
'ptr', 0, _
'ptr', DllStructGetPtr($tBMI), _
'uint', 1, _
'ptr*', 0, _
'ptr', 0, _
'uint', 0)
Return $aDib[0]
EndFunc
func _nouvellesdimention($dim)
if $longeur > $largeur Then
$ratio = $largeur / $longeur
$longeur = $dim
$largeur = $dim * $ratio
Else
$ratio = $longeur / $largeur
$largeur = $dim
$longeur = $dim * $ratio
EndIf
$largeur =Int($largeur)
$longeur =Int($longeur)
EndFunc