ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

IDEA: Find pics in required orientation on PC for digital frame

<< < (4/4)

agentsteal:
The program is now hosted at http://agentsteal.dcmembers.com/imagefinder.zip

skrommel:
 :) Here's your AutoHotkey script, IconBoy!

Just edit the first few lines.

Skrommel


--- ---;IntoFrame.ahk
; Copies landscape or portrait images
;Skrommel @ 2009

source=%A_MyDocuments%
target=C:\To
types=jpg,jpeg,jpe,png,gif,tif
subdirs=1
landscape=0
portrait=1

#NoEnv
#SingleInstance,Force
SetWorkingDir,%A_ScriptDir%
SetBatchLines,-1

applicationname=IntoFrame

FileCreateDir,%target%
Loop,Parse,types,`,
{
  type:=A_LoopField
  Loop,%source%\*.%type%,0,%subdirs%
  {
    SplitPath,A_LoopFileLongPath,name,dir,ext,name_no_ext,drive
    ImageData_Load(imagedata,A_LoopFileLongPath)
    ImageData_GetSize(imagedata,width,height)
    If ((width>=height And landscape=1) Or (width<=height And portrait=1))
    {
        FileCopy,%A_LoopFileLongPath%,%target%\%name%
        TrayTip,%applicationname%,%target%\%name%
    }
  }
}
Return


;Stolen from Lexicos at http://www.autohotkey.com/forum/topic28334.html
ImageData_Load(ByRef ImageData, ImageFile)
{
    static PixelFormat32bppARGB = 0x26200a
         , ImageLockModeRead = 0x1
         , ImageLockModeUserInputBuf = 0x4
   
    ; Initialize GDI+. Doing this here rather than at script
    ; startup is more convenient, at the cost of ~15ms.
    VarSetCapacity(GdiplusStartupInput, 16, 0), NumPut(1, GdiplusStartupInput)
    GdiplusModule := DllCall("LoadLibrary", "str", "Gdiplus")
    if GdiplusModule = 0
        return false, ErrorLevel:="GDIPLUS NOT FOUND"
    r := DllCall("Gdiplus\GdiplusStartup", "uint*", GdipToken, "uint", &GdiplusStartupInput, "uint", 0)
    if r != 0
        return false, ErrorLevel:=r
   
    ; Convert the filename to a unicode string.
    VarSetCapacity(wImageFile, StrLen(ImageFile)*2+1)
    DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "str", ImageFile, "int", -1, "uint", &wImageFile, "int", StrLen(ImageFile)+1)
   
    ; Load the image.
    r := DllCall("Gdiplus\GdipCreateBitmapFromFile", "uint", &wImageFile, "uint*", bitmap)
   
    if r != 0
        return false, ErrorLevel:=r
   
    ; Get the image's size.
    DllCall("Gdiplus\GdipGetImageWidth", "uint", bitmap, "uint*", width)
    DllCall("Gdiplus\GdipGetImageHeight", "uint", bitmap, "uint*", height)
   
    ; Make room for a BitmapData structure and the image data.
    VarSetCapacity(ImageData, 24 + width * height * 4, 0)
   
    ; Fill the BitmapData structure with details of the desired image format.
    NumPut(width, ImageData, 0, "UInt")
    NumPut(height, ImageData, 4, "UInt")
    NumPut(width * 4, ImageData, 8, "Int") ; Stride
    NumPut(PixelFormat32bppARGB, ImageData, 12, "Int") ; PixelFormat
    NumPut(&ImageData + 24, ImageData, 16, "UInt") ; Scan0
   
    ; Rect specifies the image region to lock.
    VarSetCapacity(rect, 16, 0)
    NumPut(width, rect, 8)
    NumPut(height, rect, 12)
   
    ; Lock the image and fill ImageData.
    r := DllCall("Gdiplus\GdipBitmapLockBits"
        , "uint", bitmap
        , "uint", &rect
        , "uint", ImageLockModeRead | ImageLockModeUserInputBuf
        ,  "int", PixelFormat32bppARGB
        , "uint", &ImageData)
   
    if r = 0 ; Status.Ok
    {
        ; "LockBits and UnlockBits must be used as a pair."
        DllCall("Gdiplus\GdipBitmapUnlockBits", "uint", bitmap, "uint", &ImageData)
    }
   
    ; Delete the bitmap (image in memory).
    DllCall("Gdiplus\GdipDisposeImage", "uint", bitmap)
   
    ; Uninitialize GDI+.
    DllCall("Gdiplus\GdiplusShutdown", "uint", GdipToken)
    DllCall("FreeLibrary", "uint", GdiplusModule)
   
    return r=0, ErrorLevel:=r
}

; Note: X and Y are one-based.
ImageData_GetPixel(ByRef ImageData, X, Y)
{
    return NumGet(ImageData, 24 + ((Y-1)*NumGet(ImageData,0) + (X-1)) * 4)
}

ImageData_GetSize(ByRef ImageData, ByRef Width, ByRef Height)
{
    Width := NumGet(ImageData, 0)
    Height := NumGet(ImageData, 4)
}

Navigation

[0] Message Index

[*] Previous page

Go to full version