Windows Vista Forums

Upload images from folder to a program by powershell
  1. #1



    Member
    Join Date : Oct 2012
    Posts : 6
    Vista Home Premium x64
    Local Time: 01:48 PM

    Upload images from folder to a program by powershell

    Its like, I have a folder containing 2000+ jpg images and have folders somewhere with name 1, 1.33, 1.5, 2 with are basically ratio names. I want if powershell could upload those images and crop them according to the closest aspect ratios(1, 1.33, 1.5, 2) and save into respective ratio folder.

    Or tell this software JPEGCrops to upload image and use its functions to crop image to closest ratio and save to respective ratio 1, 1.33, 1.5, 2 folder.



    if you are not able to understand, its like:

    powershell uploads images from "C:\images\" folder

    check each image' ratio, by width/height

    if(ratio is closest to any 1, 1.33, 1.5, 2 ) crop into that

    then save it into respective 1, 1.33, 1.5, 2 folder.

      My System SpecsSystem Spec

  2. #2
    tom982's Avatar

    ٩(͡๏̯͡๏)۶



    Join Date : Mar 2010
    England
    Posts : 3,642
    Windows 7 Ultimate x64 SP1
    Local Time: 08:48 PM
    uk uk england

     

    Re: Upload images from folder to a program by powershell

    Hello busybee235 and welcome to the forums

    Are they all grouped into aspect ratios as they are? Say 400 at 1.4, 250 at 1.33 etc. Or is every file different? If there's less than 10 (give or take a few) different aspect ratios, I think I can help.

    Please ignore this, I just don't want to lose the link: http://sumtips.com/2011/12/sort-orga...ect-ratio.html

    Tom

      My System SpecsSystem Spec

  3. #3



    Member
    Join Date : Oct 2012
    Posts : 6
    Vista Home Premium x64
    Local Time: 01:48 PM


      Thread Starter

    Re: Upload images from folder to a program by powershell

    thanks tom for replying.

    All 200+ images are unsorted and mixed in a folder with mixed ratio and that too different other than mentioned (1,1.33,1.5,2) ratios.

      My System SpecsSystem Spec

  4. #4
    tom982's Avatar

    ٩(͡๏̯͡๏)۶



    Join Date : Mar 2010
    England
    Posts : 3,642
    Windows 7 Ultimate x64 SP1
    Local Time: 08:48 PM
    uk uk england

     

    Re: Upload images from folder to a program by powershell

    No worries My C# is very rusty, but I might just be able to code this for you if I have to. There are easier solutions that I would like to try first.

    Of those 200+ images, how many different aspect ratios are there?

      My System SpecsSystem Spec

  5. #5



    Member
    Join Date : Oct 2012
    Posts : 6
    Vista Home Premium x64
    Local Time: 01:48 PM


      Thread Starter

    Re: Upload images from folder to a program by powershell

    Each image has different aspect ratio. I want if powershell can move those files which are closest to the mentioned ratio folder(1,1.33,1.5,2). It goes on checking each image and move them to appropriate folder. This is just powershell requirement.

    for eg. 1 image has dimension(1366 x 768) width x height

    so it has ratio 1366/768=1.78
    Now script should compare this ratio(1.78) with all the ratios(1,1.33,1.5,2) and find closest to it i.e. 2, then it should move that image to the folder named 2.

    Its simpler than using and uploading into any other program.

      My System SpecsSystem Spec

  6. #6



    Member
    Join Date : Oct 2012
    Posts : 6
    Vista Home Premium x64
    Local Time: 01:48 PM


      Thread Starter

    Re: Upload images from folder to a program by powershell

    This should go on until the last image in source folder.

    Sorry, for repetition.

      My System SpecsSystem Spec

  7. #7
    tom982's Avatar

    ٩(͡๏̯͡๏)۶



    Join Date : Mar 2010
    England
    Posts : 3,642
    Windows 7 Ultimate x64 SP1
    Local Time: 08:48 PM
    uk uk england

     

    Re: Upload images from folder to a program by powershell

    Quote Originally Posted by busybee235 View Post
    Each image has different aspect ratio. I want if powershell can move those files which are closest to the mentioned ratio folder(1,1.33,1.5,2). It goes on checking each image and move them to appropriate folder. This is just powershell requirement.

    for eg. 1 image has dimension(1366 x 768) width x height

    so it has ratio 1366/768=1.78
    Now script should compare this ratio(1.78) with all the ratios(1,1.33,1.5,2) and find closest to it i.e. 2, then it should move that image to the folder named 2.

    Its simpler than using and uploading into any other program.
    Hello busybee,

    I'll give it a go, but I can't promise anything. I'm going to have to learn a little powershell to do this! I found a great script to get the image properties:

    Code:
    [System.Reflection.Assembly]::LoadFile( "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll")  
      
     "Name|SizeInBytes|Width|Height" >> C:\JPGInfo.txt  
      
     $path = "C:\Images\"  
     $images = Get-ChildItem -Recurse $path -Include *.jpg  
      
     foreach ($image in $images)  
     {  
         $name = $image.Name  
         $length = $image.Length  
         $imageFile = [System.Drawing.Image]::FromFile($image.FullName) 
         $width = $imageFile.Width  
         $height = $imageFile.Height 
      
         "$name|$length|$width|$height" >> C:\JPGInfo.txt  
          
         $imageFile.Dispose() 
     }
    Source: Capturing Image Attributes - PowerShellCommunity.org - Windows PowerShell Discussion Forums - Using PowerShell - Working with .NET

    Now I need to modify that to calculate the aspect ratio and sort out the directories, then upload the lot. Where do you want to upload these images to?

    Edit: What am I talking about, this is way above me I don't have time to teach myself Powershell. I hope you get a reply here though:

    http://powergui.org/thread.jspa?threadID=19501

    Quote Originally Posted by busybee235 View Post
    This should go on until the last image in source folder.

    Sorry, for repetition.
    No worries

    Tom

      My System SpecsSystem Spec

  8. #8



    Member
    Join Date : Oct 2012
    Posts : 6
    Vista Home Premium x64
    Local Time: 01:48 PM


      Thread Starter

    Re: Upload images from folder to a program by powershell

    you can provide in C# or C!!

      My System SpecsSystem Spec

  9. #9



    Member
    Join Date : Oct 2012
    Posts : 6
    Vista Home Premium x64
    Local Time: 01:48 PM


      Thread Starter

    Re: Upload images from folder to a program by powershell

    I have made an algorithm of finding closest ratio of a image, if it can be any of your help, I can tell you.

      My System SpecsSystem Spec

Upload images from folder to a program by powershell problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Files and folder containing images/icons markaz General Discussion 4 09 May 2011
How to change folder icon that can preview images in the folder? yuezhang448 Vista General 0 18 May 2009
Embed images in email powershell code sample Matt Duguid PowerShell 4 08 May 2008
folder images pig5 Vista General 2 11 Jun 2007
Spyware .exe program won't save or run into Program Files folder Little Lil Vista General 3 20 Mar 2007