Welcome Guest.   Make a donation to an author on the site September 02, 2014, 06:43:44 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Your Support Funds this Site: View the Supporter Yearbook.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: IDEA: Find pics in required orientation on PC for digital frame  (Read 7276 times)
IconBoy
Charter Member
***
Posts: 35

View Profile Give some DonationCredits to this forum member
« on: December 07, 2007, 11:00:32 PM »

Hi DCers
Had a great idea cheesy 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 » Logged
agentsteal
Honorary Member
**
Posts: 75



View Profile Give some DonationCredits to this forum member
« Reply #1 on: December 16, 2007, 04:19:22 PM »

I made you a PHP script Thmbsup

Formatted for PHP with the GeSHI Syntax Highlighter [copy or print]
  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. ?>
Logged
IconBoy
Charter Member
***
Posts: 35

View Profile Give some DonationCredits to this forum member
« 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.
Logged
agentsteal
Honorary Member
**
Posts: 75



View Profile Give some DonationCredits to this forum member
« 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/get/php...staller.msi/from/a/mirror
4. Open a command prompt and say: php C:\directory\scriptfile.php
Logged
IconBoy
Charter Member
***
Posts: 35

View Profile Give some DonationCredits to this forum member
« 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 :-)
Logged
agentsteal
Honorary Member
**
Posts: 75



View Profile Give some DonationCredits to this forum member
« Reply #5 on: December 17, 2007, 01:03:51 AM »

Okay try this one...
http://agentsteal.110mb.com/imagefinder.zip

1. Extract the archive.
2. Set the folders and options in the settings.txt file.
3. Double click on imagefinder.exe
Logged
IconBoy
Charter Member
***
Posts: 35

View Profile Give some DonationCredits to this forum member
« 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:
[copy or print]
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 » Logged
agentsteal
Honorary Member
**
Posts: 75



View Profile Give some DonationCredits to this forum member
« 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 » Logged
IconBoy
Charter Member
***
Posts: 35

View Profile Give some DonationCredits to this forum member
« 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! cheesy
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 » Logged
agentsteal
Honorary Member
**
Posts: 75



View Profile Give some DonationCredits to this forum member
« 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 » Logged
IconBoy
Charter Member
***
Posts: 35

View Profile Give some DonationCredits to this forum member
« Reply #10 on: December 17, 2007, 09:57:13 AM »

The program works great! cheesy
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!
Logged
jgpaiva
Global Moderator
*****
Posts: 4,710



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« 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 Sad
But if agentsteal's solution solves your problem, you'd you want another solution?
Logged

IconBoy
Charter Member
***
Posts: 35

View Profile Give some DonationCredits to this forum member
« 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 Sad
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 Cool
Logged
jgpaiva
Global Moderator
*****
Posts: 4,710



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« 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:
[copy or print]
moveImage.jar <name of dir with files> <P or L, for portrait or landscape>
An example would be:
[copy or print]
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 Wink

* MoveImages.zip (3.62 KB - downloaded 205 times.)
Logged

mouser
First Author
Administrator
*****
Posts: 33,294



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #14 on: December 17, 2007, 02:12:15 PM »

welcome to the site agentsteal  thumbs up
great to have another php coder here.
Logged
agentsteal
Honorary Member
**
Posts: 75



View Profile Give some DonationCredits to this forum member
« Reply #15 on: January 07, 2009, 12:29:47 AM »

The program is now hosted at http://agentsteal.dcmembers.com/imagefinder.zip
Logged
skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #16 on: January 10, 2009, 06:22:48 PM »

 smiley Here's your AutoHotkey script, IconBoy!

Just edit the first few lines.

Skrommel

[copy or print]
;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)
}
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.13s | Server load: 0.01 ]