Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

278
Vistas
How to get image dimensions (W x H, in pixels) from filepath, then to outputting?

I'm trying to supply a filepath to an image on my computer, extract the image height and width in pixels, then output those numbers for later use -- ideally into an Excel Spreadsheet. The full process would do this for all images in a folder.

For full context of what is happening here: This information is ultimately going to be used to make decisions in the full workflow about what folders to send these images to based upon their dimensions.
For example : images whose dimensions are very close to a square 1:1 would be sent to the "SQUARE" folder. Those whose dimensions are closest to the 3:2 dimensions would be sent to that folder. And so forth. The full process here will basically automate the function of evaluating image dimensions to determine what standard image formats they are closest to, and then folderize them accordingly.

All of these later steps, I will do inside of PowerAutomate -- simply because I'm very comfortable working inside of there and could easily accomplish the rest of this process using PowerAutomate. However for whatever reason they don't have a function to get image properties (such as image height and width), and then store that information for later use as a variable.

So I basically need to use some fast & effective external method of gathering this image data -- and then the simplest way for me to be able to pick it up would be just to write this info to an Excel spreadsheet.

Since it would loop over all images in a folder, it would need to write the image data for Image 1 in the folder to Row 1, e.g. image height in pixels written to cell A1, image width in pixels written to B2. Image 2's information would then be written to A2 + B2. Etc until completion.

Any ideas on the simplest way that I could do this with some sort of computer program? It could be Javascript, really anything that I'd be able to easily execute on my local computer.

I'm a complete noob when it comes to Javascript etc. Only just beginning to learn the basics. If you could go above and beyond and just supply me with a template program that would accomplish this -- with a template image folder that I could then substitute with my filepath, and also a template Excel filepath that I could replace with the one I would use (a sort of // SUBSTITUTE YOUR IMAGE FOLDER FILEPATH HERE type deal) -- that would be downright amazing! Even just some scraps to get me going would be super helpful.

I found an online resource recommending something like this (most cover images via URLs -- not filepaths), however I haven't had luck with successfully executing this. Seems to be a step in the right direction however:

using (Image img = System.Drawing.Image.FromFile("C:\Users\suppo\Pictures\testing\this-is-a-test-product-image-1.jpg"))
{
    int height = img.Height;
    int width = img.Width;
}

        alert("Current width=" + width + ", " + "Original height=" + height);

Then instead of displaying the outputs as an alert message, ideally it would instead write these outputs onto the respective cells of an Excel spreadsheet whose filepath would be provided somewhere in here. Then the whole thing would just loop over all images in the folder, and the row that it would write the outputs to would correspond to the current step in the Loop process -- with the number of times it would run through the loop obviously corresponding to the number of files in the given folder.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Ended up writing a Python script to accomplish this. Not bad for only downloading Python and starting out with "Hello world!" about 3 hours ago!

import os

directory = "C:\\Users\\suppo\\Pictures\\testing"

APP_FOLDER = "C:\\Users\\suppo\\Pictures\\testing"

totalFiles = 0
totalDir = 0

for base, dirs, files in os.walk(APP_FOLDER):
    print('Searching in : ',base)
    for directories in dirs:
        totalDir += 1
    for Files in files:
        totalFiles += 1


print('Total number of files',totalFiles)
print('Total Number of directories',totalDir)
print('Total:',(totalDir + totalFiles))

import xlsxwriter

#create file (workbook) and worksheeet
outWorkbook = xlsxwriter.Workbook("Testing Excel Python v1.xlsx")
outSheet = outWorkbook.add_worksheet()


for file_index, filename in enumerate(os.listdir(directory)): 
    if filename.endswith(".jpg") or filename.endswith(".png"):
        from PIL import Image

        # get image
        filepath = 'C:\\Users\\suppo\\Pictures\\testing\\' + filename
        img = Image.open(filepath)

        # get width and height
        width = img.width
        height = img.height

        # display width and height
        print("The height of the image is: ", height)
        print("The width of the image is: ", width)        

        outSheet.write(f"A{file_index+1}", width)
        outSheet.write(f"B{file_index+1}", height)
        outSheet.write(f"C{file_index+1}", "C:\\Users\\suppo\\Pictures\\testing\\" + filename)

outWorkbook.close()
about 4 years ago · Juan Pablo Isaza Denunciar

0

Does it need to be a true Excel .xlsx file? If you can use a CSV, you can use a Powershell script like this (making sure you execute it from the directory in which the images are placed):

Get-ChildItem | ForEach-Object {
    $img = [System.Drawing.Image]::FromFile("$_") 
    $width = $img.Width
    $height = $img.Height 
    echo "$width,$height,$_"
} | Out-File -FilePath "image-dimensions.csv"

I'm running this on linux, so the file path format will be different, but this is basically what the output file will look like:

550,366,/home/example/Pictures/foo.jpg
256,256,/home/example/Pictures/bar.jpg
640,482,/home/example/Pictures/kitten.png

Then you can just import the CSV into Excel.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda