Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Can I use a batchfile to read the size of an online picture and write that size to a file?

Say, I want to read the size of this picture:

https://www.google.com/images/srpr/logo4w.png

...and want that size added to a txt-file.

Can it be done in a batch file?

Like:

@echo off

getwidth (https://www.google.com/images/srpr/logo4w.png) >> c:\width.txt

getheigth (https://www.google.com/images/srpr/logo4w.png) >> c:\height.txt

Ofcourse, those getwidth and getheigth batch commands don't exist. But how do I get this done?

And if the picture URL doesn't exist, that it would write 0 to width.txt and height.txt.

2 Answers

Relevance
  • 8 years ago
    Favorite Answer

    Nope.

    There are lots of things you can't do in a batch file, and this is one of them.

    Why?

    1) BATCH predates the internet, buy a couple decades. So there was never any built in support for getting stuff from the internet, and there never will be.

    2) The link to the image won't tell you what the width or height of the .png file is. About all you can do with the link is download the file. Until the file is downloaded, there is no way to figure out the width and height.

    3) You *could* call wget or curl from a batch file to download the file. That gets you part way there...you at least have the file. But BATCH doesn't have any built in support for reading a binary file like a .png to read the width and height attributes.

    Trying to do this from a batch file will be an exercise in frustration. You are better off using a more modern scripting language, or a real programming language. You can probably do this in a .VBS file, not sure, didn't try it, but I suspect you can.

    You can also do it using PowerShell. I'm not all that handy with PowerShell, but I managed to put this together in about 10 minutes, and it does what you asked for:

    add-type -AssemblyName System.Drawing

    $webclient = New-Object System.Net.WebClient

    $url = "https://www.google.com/images/srpr/logo4w.png%22

    $file = "logo4w.png"

    $webclient.DownloadFile($url,$file)

    $png = New-Object System.Drawing.Bitmap $file

    Add-Content width.txt $png.Height

    Add-Content height.txt $png.Width

  • 8 years ago

    You can BUT you need a third party command line jpeg utility ....then its:

    3rparty.exe myimage.jpg >> outfile.txt

    Check out this discussion at the link below -- especially where they discuss "imagemajick" --

Still have questions? Get your answers by asking now.