Announcement

Collapse
No announcement yet.

aspect-ratio-based canvas resize

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    aspect-ratio-based canvas resize

    I apologize if this has been posted elsewhere or is obvious. I've tried the various menus and can't find the proper settings.

    Is it possible to batch do this with irfanview?
    make the pic a specific aspect ratio by adding borders either on top+bottom, or left+right, but without modifying the image in any other way (the dimensions of the image, without counting the border, is still the same).

    I describe the problem somewhat better in this thread (with sample pictures of what I want done)


    notes: the options seem to be in percentage, or fixed number of pixels, but not as percentage of the opposite side (that'd solve the problem. by opposite side, I mean new_width = old_width; new_height = 1.5 x old_width )
    the pics are of various sizes (they're scans)
    the object of this to avoid automatic cropping from print centers like costco or walmart (they don't have an option to not crop; the option to add white borders just makes the cropped image smaller, and adds borders on all four sides - kind of stupid IMHO)

    PS: if this has to be scripted, can it be done so that the pixel parity is checked and adjusted for? the reason is if we canvas resize from 1500 to 1551 for instance, there will be 1/2 pixel interpolation. we just add a pixel to make it from 1500 to 1552.

    #2
    Hi
    What you ask is possible using a script file written in something like VBS but I cannot think of an elegant way to do it. I think it would need the following steps for each image file;

    1. Call Irfanview using the /info=txtfile option to get the image Width and Height
    2. Calculate required Width and Height of new image having correct aspect ratio
    3. Modify i_view32.ini file to insert new values into CanvW and CanvH parameters
    4. Call Irfanview again using the /Advancedbatch option to make the change

    I have done all these things before in VBS scripts and they worked OK but I would expect that it would take 2-3 seconds per image due to all the opening and closing of Irfanview, so your 1000 images will take a while to process.

    However is it really necessary to do it this way? Can you not just resize, keeping aspect ratio, to fit within a fixed size of say 1200x800 and then Add canvas (centered) to add borders to the appropriate sides? 1200x800 would give a 6x4in print at 200DPI which is probably about what Costco would scale it down to anyway.
    You could do that with a standard Batch Conversion/Rename process from the Irfanview GUI - see example below.

    Click image for larger version

Name:	Advanced.png
Views:	1
Size:	88.0 KB
ID:	80846

    Edit: You would probably have to sort your images first into portrait and landscape formats so that you could resize a portrait batch to 800x1200 and a landscape batch to 1200x800. You can do that fairly easily in the Thumbnail window.
    Last edited by Mij; 17.10.2012, 06:21 PM.

    Comment


      #3
      Sorry to bump and old post but this is exactly what I'm trying to do. Been looking at other software as well. Does anyone know of a method to do this?

      Images are all different sizes and aspect ratios, basically random.

      End goal: All images 750px x 563px without losing any of the image

      Current process:
      Add white borders to the sides or the top and bottom to correct aspect ratio
      Resize image

      In the future I can foresee needing the images in different sizes with the same aspect ratio. If I can get the aspect ratio corrected and keep the images at full size I can then create new batches as needed for different sizes.

      Learning VB script isn't something I'm to keen on at the moment. I may be willing to pay someone that is up to the task.

      Comment


        #4
        Well I decided to start playing with a VBScript. I seem to be getting close but am stuck at the moment.

        The script is using Irfanview to create an info file. I'm reading the dimensions from the file. Doing the math to get the new dimensions and then writing them to the ini file.

        Error I'm getting:

        Well I was but typing up this post I found the issues.

        This is _VERY_ rough code but thought I would post it up for others to use. I'm sure it's not very efficient and could us a lot of help so use at your own risk! Allows you to drag and drop pictures like this video:
        Auf YouTube findest du die angesagtesten Videos und Tracks. Außerdem kannst du eigene Inhalte hochladen und mit Freunden oder gleich der ganzen Welt teilen.


        Decided to clean up the code a bit will repost it shortly...
        Last edited by Muttley; 22.05.2013, 07:50 PM.

        Comment


          #5
          Okay cleaned up the code a bit. I provide no support! Use at your own risk. Best you have a programming understanding before trying to mess with the mess that I made

          ' Based on
          ' Nioi Pier Giuliano

          ' http://piergiu.wordpress.com/

          ' purpose of this script:
          ' resizes images with irfanview and saves them in the script folder

          ' Modified to create images with a specific aspect ratio
          ' Various Code noted below from:
          ' blogs.technet.com/b/heyscriptingguy/


          '----------------------DO NOT modify this----------------------------
          set objShell = wscript.createObject("wscript.shell")
          set objFSO = CreateObject("Scripting.FileSystemObject")

          DIM exe,switch,convert,all,width,height,installationPa th,info,genText,iniLocation,iniFile
          Const ForReading = 1
          Const ForWriting = 2
          '--------------------------------------------------------------------


          '-----------------PLEASE DO modify this at your needs----------------
          installationPath = "C:\Program Files (x86)\IrfanView\"
          runLocation = "C:\Users\Tim\Desktop\Temp"
          iniLocation = "C:\Users\Tim\Desktop\Temp"
          '--------------------------------------------------------------------


          '----------------------Set command line strings----------------------------
          exe = "CMD /C " & """" & installationPath & "i_view32.exe" & """"
          iniFile = runLocation & "\i_view32.ini"
          info = " /info=" & runLocation & "\fileInfo.txt"
          switch = " /advancedbatch /ini=" & iniLocation & " /convert="

          '----------------------Execute----------------------------
          scriptFolder = objFSO.GetParentFolderName(Wscript.ScriptFullName)

          For Each a In WScript.Arguments

          set objFile = objFSO.GetFile(a)
          convert= "$D$N_test.jpg" 'Uses IrfanView patterns to name new file
          'Alternate file naming option
          'convert= scriptFolder & "\" & objFSO.GetBaseName(objFile) & "_rid." & objFSO.GetExtensionName(objFile)
          '----------------------Generate text file----------------------------
          genText= exe & " " & a & info
          iReturn = objShell.Run(genText, , True)
          'WScript.Echo all
          '----------------------Retrieve dimensions----------------------------
          '--Get the current height and width from fileInfo.txt
          '-- Code from http://blogs.technet.com/b/heyscript...xt-file.aspx--

          Set objFSO = CreateObject("Scripting.FileSystemObject")
          Set objFile = objFSO.OpenTextFile("C:\Users\Tim\Desktop\Temp\fil eInfo.txt")

          Do Until objFile.AtEndOfStream
          strData = ""
          strSearchString = objFile.ReadLine

          intStart = InStr(strSearchString, "Image dimensions = ") 'Find the start of pic dimensions

          If intStart <> 0 Then
          intStart = intStart + 19
          strText = Mid(strSearchString, intStart, 50)'strText will contain both dimensions
          strWidth = "" 'null the value

          For i = 1 to Len(strText)
          If Mid(strText, i, 1) = " " Then
          Exit For
          Else
          strWidth = strWidth & Mid(strText, i, 1)'strWidth just has the width
          End If
          Next
          End If
          Loop

          intStart2 = InStr(strText, "x")'find the start of heigth dimension
          intStart2 = intStart2 + 2

          strText2 = Mid(strText, intStart2, 10)
          strHeight = "" 'null the value

          For i = 1 to Len(strText2)
          If Mid(strText2, i, 1) = " " Then
          Exit For
          Else
          strHeight = strHeight & Mid(strText2, i, 1)'strHeight is the height
          End If
          Next


          '----------------------Analyze dimensions----------------------------
          '--Determine which dimension needs to be larger
          '--Modify this section to determine the new image size
          intWidth = clng(strWidth)
          intHeight = clng(strHeight)

          If intWidth/intHeight > 1.33 Then
          If intWidth/intHeight < 1.34 Then
          widthNew = intWidth
          heightNew = intHeight
          Else
          widthNew = intWidth
          heightNew = round(intWidth/4*3)
          End If
          Else
          widthNew = round(intHeight*4/3)
          heightNew = intHeight
          End If


          '----------------------New Dimensions----------------------------
          '--Write to ini file the new dimensions CanvW and CanvH
          '-- Code from http://blogs.technet.com/b/heyscript...-a-script.aspx --


          Set objFSO = CreateObject("Scripting.FileSystemObject")
          Set objTextFile = objFSO.OpenTextFile(iniFile, ForReading)
          strNewFile = "" 'null the value

          Do Until objTextFile.AtEndOfStream
          strNextLine = objTextFile.Readline

          intLineFinder = InStr(strNextLine, "CanvW")
          If intLineFinder <> 0 Then
          strNextLine = "CanvW=" & widthNew
          End If

          intLineFinder = InStr(strNextLine, "CanvH")
          If intLineFinder <> 0 Then
          strNextLine = "CanvH=" & heightNew
          End If

          strNewFile = strNewFile & strNextLine & vbCrLf
          Loop

          objTextFile.Close

          Set objTextFile = objFSO.OpenTextFile(iniFile, ForWriting)

          objTextFile.WriteLine strNewFile
          objTextFile.Close


          '----------------------Execute conversion----------------------------
          all= exe & " " & a & switch & convert
          iReturn = objShell.Run(all, , True)
          'WScript.Echo all

          Next
          '--------------------------------------------------------------------

          Comment

          Working...
          X