No la he probado. Ahí va una función de nuestros amigos de habla inglesa. Para ser exactos de smashly:
Código: Seleccionar todo
; #FUNCTION# =========================================================================================
; Name...........: _ImageResize
; Description....: Resize an image and optionally convert it to the format you want.
; Syntax.........: _ImageResize($sInImage, $sOutImage, $iW, $iH)
; Parameters ....: $sInImage - Full path to the image to resize / convert.
; In types: *.bmp, *.gif, *.ico, *.jpg, *.jpeg, *.png, *.tif, *.tiff
; $sOutImage - Full path where to save the resized / converted image.
; Out types: *.bmp, *.gif, *.jpg, *.jpeg, *.png, *.tif, *.tiff
; $iW - Width to resize image to.
; $iH - Height to resize image to.
; Return values .: Success - Return 1 and @error 0
; Failure - Return 0 and @error 1~5
; @error 1 = In File does not exist
; @error 2 = In File format not supported
; @error 3 = Out File path does not exist
; @error 4 = Out file format not supported
; @error 5 = Resize Width or Height not an integer
; Author ........: smashly
; ====================================================================================================
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)
;Start GDIPlus
_GDIPlus_Startup()
;Load the image you want to resize.
$hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)
$iOriginalHeight = _GDIPlus_ImageGetHeight($hImage2)
$iOriginalWidth = _GDIPlus_ImageGetWidth($hImage2)
;create a blank DIBSection
If $iOriginalHeight > $iOriginalWidth then
$hBitmap = _WinAPI_CreateCompatibleBitmapSection($iW,$iH)
Else
$hBitmap = _WinAPI_CreateCompatibleBitmapSection($iH,$iW)
EndIf
$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
;Get the graphic context of the blank bitmap
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)
;Draw the loaded image onto the blank bitmap at the new size
If $iOriginalHeight > $iOriginalWidth then
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH)
Else
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iH, $iW)
EndIf
;see if the image needs to be saved rotated
$Rotate = 0
If $iW < $iH and $iOriginalHeight < $iOriginalWidth then $Rotate = 1
If $iW > $iH and $iOriginalHeight > $iOriginalWidth then $Rotate = 1
;Get the encoder of to save the resized image in the format you want.
$CLSID = _GDIPlus_EncodersGetCLSID($Ext)
If $Rotate = 1 then
; Set up parameters for 90 degree rotation
$tData = DllStructCreate("int Data")
DllStructSetData($tData, "Data", $GDIP_EVTTRANSFORMROTATE90)
$tParams = _GDIPlus_ParamInit (1)
_GDIPlus_ParamAdd ($tParams, $GDIP_EPGTRANSFORMATION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Data"))
EndIf
;Save the new resized image.
If $Rotate = 1 then
Msgbox(0,"Save Rotated",_GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID, DllStructGetPtr($tParams)) )
Else
Msgbox(0,"Save",_GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID))
EndIf
;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
Espero que te sirva. Ya nos contarás como va y su funcionalidad.
Saludos.