Page 1 sur 1

[R] Comment récupérer la taille en pixel d'une image donnée

Posté : ven. 24 oct. 2008 17:54
par Yogui
je m'explique,

j'ai fait un petit script qui réduit une image (mais sans s'occuper de sa taille d'origine) mon appareil photo prend des photos toujours à la même taille... mais problème les photo en portrait se retrouvent en paysage il me faut donc connaitre la taille d'origine pour réduire sans changer le format.

j'espère voir été claire

Merci pour votre aide

Re: [..] Comment récupérer la taille en pixel d'une image donnée

Posté : ven. 24 oct. 2008 18:53
par Linox
avec quoi tu réduit ton image ?

Re: [..] Comment récupérer la taille en pixel d'une image donnée

Posté : ven. 24 oct. 2008 19:09
par jbnh
J'ai trouvé un udf sympa:
► Afficher le texte
Il marche uniquement pour des JPG par contre...

Re: [..] Comment récupérer la taille en pixel d'une image donnée

Posté : ven. 24 oct. 2008 22:24
par Yogui
super merci

Dommage pour les autre format mais c'est déjà un super début merci

Pour redimensionner les images j'utilise une fonction trouvée sur le forum anglais qui fonctionne très bien :

Code : Tout sélectionner

Func _ImageResize($sInImage, $sOutImage, $iW, $iH)
    Local $hWnd, $hDC, $hBMP, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0
    
    ;OutFile path, to use later on.
    Local $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))
    
    ;OutFile name, to use later on.
    Local $sOF = StringMid($sOutImage, StringInStr($sOutImage, "\", 0, -1) + 1)
    
    ;OutFile extension , to use for the encoder later on.
    Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1))
    
    ; Win api to create blank bitmap at the width and height to put your resized image on.
    $hWnd = _WinAPI_GetDesktopWindow()
    $hDC = _WinAPI_GetDC($hWnd)
    $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    
    ;Start GDIPlus
    _GDIPlus_Startup()
    
    ;Get the handle of blank bitmap you created above as an image
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBMP)
    
    ;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, $iW)
    
    ;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 & $i & "_" & $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($hBMP)
    _GDIPlus_Shutdown()
EndFunc

Re: [..] Comment récupérer la taille en pixel d'une image donnée

Posté : lun. 03 nov. 2008 13:16
par tolf
_GDIPlus_ImageGetHeight pour la hauteur de l'image et _GDIPlus_ImageGetWidth pour sa largeur

Re: [..] Comment récupérer la taille en pixel d'une image donnée

Posté : jeu. 06 nov. 2008 21:14
par Yogui
Il n'est pas fini mais voilà le code que j'ai fait, et récupérer pour redimentionner des images dans un dossier pour les mettre dans un dossier photos dans mes doc les image sont trier par date de création. c'est un premier jet je pense encore l'améliorer
► Afficher le texte

Re: [..] Comment récupérer la taille en pixel d'une image donnée

Posté : ven. 07 nov. 2008 13:29
par Linox
Yogui a écrit :Pour redimensionner les images j'utilise une fonction trouvée sur le forum anglais qui fonctionne très bien :
Pourrais tu me donner le lien direct ?

J'ai fait un générateur de galerie photos en autoit et pour redimensionner mes images j'utilise image magick

Re: [..] Comment récupérer la taille en pixel d'une image donnée

Posté : ven. 07 nov. 2008 13:41
par Yogui