Bogiecom.com
  • About
  • Magento
  • Sitecore
  • WordPress

Imagick Powershell Resize Images In Folder

Posted on November 18, 2011 by bc-admin

Here’s a quick one-liner to re-size photos if you have Imagick installed using PowerShell. It also renames the files with the dimensions specified:

1
2
PS C:\Users\SloshDev> gci("*.jpg") |
      %{convert  $_.FullName -resize 500x500 $_.Name -replace '\.jpg$','-500x500.jpg'}

Ultimately ended up with this to rename the file based on the actual dimensions of the file in the end:

1
2
PS C:\Users\SloshDev> gci("*.jpg") |
   %{convert $_.FullName -resize 500x500 -set filename:area '%wx%h' ($destination + ($_.Name.Trim("\.jpg") + "-%[filename:area].jpg"))}

This is great if you want to do this within the file itself, however if you need to specify dimensions, source and destination directories, and specific image file extensions you could use a script like this:

1
2
3
4
5
6
7
$source = 'C:\User\SloshDev\My Pictures\'
     $destination = 'C:\User\SloshDev\My Pictures\500's\'
     $ext = "jpg"
     $size = "500x500"
     #Resize Images
      gci("$source*.$ext") |
        %{convert $_.FullName -resize $size -set filename:area '%wx%h' ($destination + ($_.Name.Trim("\.$ext") + "-%[filename:area]." + $ext))}

Posted in Image Resizing, Imagick, Powershell |
« Append Extension to All Files in Directory
Find String in Files with Given Extension Using PowerShell »

Pages

  • About
  • Magento
  • Sitecore
  • WordPress

Archives

  • January 2017
  • December 2013
  • November 2013
  • February 2013
  • January 2013
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • November 2011
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • September 2009

Categories

  • .NET
  • Air Force
  • Apache Configuration
  • Bash
  • C#
  • Comma-Delimited
  • Custom Field Validator
  • Date Format
  • Dump Files
  • Files
  • Grep
  • Grooveshark
  • HTML
  • Image Resizing
  • Imagick
  • Integration
  • jQuery
  • Konami Code
  • Linux
  • Magento
  • Magento Third Party CMS Integration
  • Mini Shuttle
  • Miva Merchant 5.5
  • MySQL
  • PHP
  • Powershell
  • Regular Expressions
  • Rename-Item
  • Sed
  • Shell Scripting
  • Sitecore
  • Strings
  • Uncategorized
  • Updating Product Attributes
  • Video Games
  • Wordpress
  • X-37
  • XML
  • YUI Konami Event

CyberChimps WordPress Themes

© 2008 - 2016 Bogiecom.com