Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • September 01, 2015, 11:12:48 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: Find pics in required orientation on PC for digital frame  (Read 8081 times)

IconBoy

  • Charter Member
  • Joined in 2006
  • ***
  • gravatar avatar
  • Posts: 35
    • View Profile
    • Donate to Member
IDEA: Find pics in required orientation on PC for digital frame
« on: December 07, 2007, 11:00:32 PM »
Hi DCers
Had a great idea :D for the guru programmers out there in DC Land as I am trying to get a digital frame ready with pics to send to dear old Mom and Dad as a gift:
It would be great if there was an utility that would search a user-selected folder (with the option to search sub-folders if desired) for certain types of files (e.g. JPGs), but it would need to find only pics that were Landscape orientation (or Portrait depending on the user-selected preference), because most people will either have their digital-frame in either Landscape (or Portrait) mode and wouldn't want the pics in the other orientation to show up as they would not fit the screen. Once the pics are found, it would then copy them to a user-selected folder.
Would anyone know how to code this and give us a working example?
This would save me many hours right now as I am going through all the hundreds of camera pics on PC to find ones that Mom and Dad have not seen/been sent of the kiddos, but I then have to choose which ones are the correct orientation for the frame.
If the digital-frame size (e.g. 5". 7" etc.) is relevant to the pixel size of the pics (e.g. 800x600), then the app could recommend (via an on-screen message) the best setting to resize the newly found pics. There are many apps out there that resize just fine so adding to it wouldn't be needed I guess.
What do you all think of this idea?
« Last Edit: December 07, 2007, 11:04:48 PM by IconBoy »

agentsteal

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 75
    • View Profile
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #1 on: December 16, 2007, 04:19:22 PM »
I made you a PHP script :Thmbsup:

Code: PHP
  1. <?php
  2.  
  3. $folder = './';
  4. $subfolders = true;
  5. $extension = 'jpg';
  6. $orientation = 'L';
  7. $copytofolder = 'C:/Images/';
  8.  
  9. if (!is_dir ($folder))
  10. {
  11. echo ($folder . ' doesn\'t exist.');
  12. }
  13. elseif (!is_dir ($copytofolder))
  14. {
  15. echo ($copytofolder . ' doesn\'t exist.');
  16. }
  17. else
  18. {
  19. getImages ($folder, $subfolders, $extension, $orientation, $copytofolder);
  20. }
  21. function getImages ($folder, $subfolders, $extension, $orientation, $copytofolder)
  22. {
  23. $files = opendir ($folder);
  24. while ($image = readdir ($files))
  25. {
  26. if (is_dir ($folder . '/' . $image))
  27. {
  28. if ($subfolders && $image != '.' && $image != '..')
  29. {
  30. getImages ($folder . '/' . $image, $subfolders, $extension, $orientation, $copytofolder);
  31. }
  32. }
  33. elseif (substr ($image, -1 - strlen ($extension)) == '.' . $extension)
  34. {
  35. list ($width, $height) = getimagesize ($folder . '/' . $image);
  36. if (strtolower ($orientation) == 'p' && $height > $width)
  37. {
  38. echo ('Copying ' . $image . '...');
  39. fwrite (fopen ($copytofolder . '/' . $image, 'w'), file_get_contents ($folder . '/' . $image));
  40. }
  41. if (strtolower ($orientation) == 'l' && $height < $width)
  42. {
  43. echo ('Copying ' . $image . '...');
  44. fwrite (fopen ($copytofolder . '/' . $image, 'w'), file_get_contents ($folder . '/' . $image));
  45. }
  46. }
  47. }
  48. }
  49. ?>

IconBoy

  • Charter Member
  • Joined in 2006
  • ***
  • gravatar avatar
  • Posts: 35
    • View Profile
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #2 on: December 16, 2007, 08:54:19 PM »
thanks! Excuse my ignorance, but how do I apply this PHP script to my folder on my computer? I have *no* idea how to implement this.

agentsteal

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 75
    • View Profile
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #3 on: December 16, 2007, 09:06:16 PM »
If you want I can make a version that's easier to use.

To run the program:
1. Change the parameters at the top of the script to set the folders/options.
2. Save the script as a .php file.
3. Install PHP: http://us.php.net/ge...er.msi/from/a/mirror
4. Open a command prompt and say: php C:\directory\scriptfile.php

IconBoy

  • Charter Member
  • Joined in 2006
  • ***
  • gravatar avatar
  • Posts: 35
    • View Profile
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #4 on: December 16, 2007, 11:13:35 PM »
I would be most grateful if you could make one that's easier to use.
Thank you for your help so far :-)

agentsteal

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 75
    • View Profile
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #5 on: December 17, 2007, 01:03:51 AM »
Okay try this one...
http://agentsteal.11....com/imagefinder.zip

1. Extract the archive.
2. Set the folders and options in the settings.txt file.
3. Double click on imagefinder.exe

IconBoy

  • Charter Member
  • Joined in 2006
  • ***
  • gravatar avatar
  • Posts: 35
    • View Profile
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #6 on: December 17, 2007, 01:25:23 AM »
I had a folder on my desktop called Test and copied the two files you had in the zip into it. I created a folder called Temp on the root of C drive and this is the settings file I used:
Code: [Select]
folder=./
subfolders=true
extension=jpg
orientation=L
copytofolder=C:/Temp/
I then ran the exe file but nothing copied to C:\Temp.
Any reason why it is not working?
Thanks!
« Last Edit: December 17, 2007, 01:28:29 AM by IconBoy »

agentsteal

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 75
    • View Profile
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #7 on: December 17, 2007, 01:36:33 AM »
Test contains landscape jpg files right?

Oh I think the extensions might be case sensitive. Are the files .JPG? If they are, try changing the extension option to JPG. If that's the problem I can make them case insensitive...
« Last Edit: December 17, 2007, 01:45:37 AM by agentsteal »

IconBoy

  • Charter Member
  • Joined in 2006
  • ***
  • gravatar avatar
  • Posts: 35
    • View Profile
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #8 on: December 17, 2007, 09:26:08 AM »
There were both landscape and portrait pics - I made sure there were both types - I wanted to see how it worked! I will check the Case option and see what I can do.
Edit: The script seems to run okay and I checked the case option and it works if the correct case option is selected. It might be quite handy to have the case option a user choice in the settings file. Wow, so glad that it works - I am sure it is gonna save me a few hours! :D
By the way, how would I change the settings file if my Temp folder is on the desktop? Would it need quotes to go around the file locations?
Edit: I just tried it with and without quotes and it seems to work without the quotes.
Is there anyway that the dialog box can close automatically (or a user option in settings if you would prefer to keep the Ctrl+C choice to close) once it is complete?
And another one: Is it possible that the folder can be created automatically if it doesn't exist?
Thanks!
« Last Edit: December 17, 2007, 09:55:16 AM by IconBoy »

agentsteal

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 75
    • View Profile
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #9 on: December 17, 2007, 09:48:03 AM »
The program works right? What was the problem with the Test folder?

No quotes. I'll add the Ctrl-C option and the folder creation.
« Last Edit: December 17, 2007, 09:51:55 AM by agentsteal »

IconBoy

  • Charter Member
  • Joined in 2006
  • ***
  • gravatar avatar
  • Posts: 35
    • View Profile
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #10 on: December 17, 2007, 09:57:13 AM »
The program works great! :D
Is there any way this could be made into an AutoHotKey script or does it need to be an exe file?
There was no problem with the test folder, I was just using it as an example of the folder to be created automatically if it didn't exist!

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #11 on: December 17, 2007, 10:09:20 AM »
IconBoy:
When you first posted about this request, i tried to make in ahk, but there's no way to see the size of an image in ahk :(
But if agentsteal's solution solves your problem, you'd you want another solution?

IconBoy

  • Charter Member
  • Joined in 2006
  • ***
  • gravatar avatar
  • Posts: 35
    • View Profile
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #12 on: December 17, 2007, 10:19:39 AM »
When you first posted about this request, i tried to make in ahk, but there's no way to see the size of an image in ahk :(
Thanks jgpaiva for trying to get an AHK solution. I just wondered if it was possible because I use AHK so much!
AgentSteal's option is great so far 8)

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #13 on: December 17, 2007, 12:25:41 PM »
Well.. Out of fun, i decided to make this in java.. LOL

Just open a command line and launch the file like this:
Code: [Select]
moveImage.jar <name of dir with files> <P or L, for portrait or landscape>
An example would be:
Code: [Select]
moveImage.jar c:\mydir P
The result will be that the files that match the orientation chosen will be moved to a new folder that is created inside the folder that contains the files, named moveImages ;)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 34,971
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #14 on: December 17, 2007, 02:12:15 PM »
welcome to the site agentsteal  :up:
great to have another php coder here.

agentsteal

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 75
    • View Profile
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #15 on: January 07, 2009, 12:29:47 AM »
The program is now hosted at http://agentsteal.dc....com/imagefinder.zip

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Find pics in required orientation on PC for digital frame
« Reply #16 on: January 10, 2009, 06:22:48 PM »
 :) Here's your AutoHotkey script, IconBoy!

Just edit the first few lines.

Skrommel

Code: [Select]
;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)
}
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.