{"id":69813,"date":"2005-05-13T11:59:00","date_gmt":"2005-05-13T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/05\/13\/how-can-i-display-the-vertical-and-horizontal-sizes-of-a-jpg-file\/"},"modified":"2005-05-13T11:59:00","modified_gmt":"2005-05-13T11:59:00","slug":"how-can-i-display-the-vertical-and-horizontal-sizes-of-a-jpg-file","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-display-the-vertical-and-horizontal-sizes-of-a-jpg-file\/","title":{"rendered":"How Can I Display the Vertical and Horizontal Sizes of a .JPG File?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I display the vertical and horizontal resolutions of a .JPG file?<BR><BR>&#8212; ST<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, ST. This is a very commonly-asked question, and for the longest time we had no answer for it: nothing built into the operating system seemed capable of returning this information, and even <A href=\"http:\/\/null\/technet\/scriptcenter\/resources\/tales\/sg0305.mspx\"><B>Dsofile<\/B><\/A>, a COM object released by the Microsoft Office team specifically to return the values of extended properties like this, can\u2019t get us picture sizes. The whole thing seemed hopeless.<\/P>\n<P>But just because things looked bleak does that mean we gave up? Well, to tell you the truth, yes. But then we pieced together a <A href=\"http:\/\/null\/technet\/scriptcenter\/funzone\/default.mspx\"><B>Fun Zone<\/B><\/A> article on using scripts to manage music files and playlists, and purely by accident we stumbled upon a workaround: as long as you import all your .JPG files into Windows Media Player you can use scripts to return information about the file, such as a picture\u2019s vertical and horizontal size.<\/P>\n<P>Now keep in mind that, by default, Windows Media Player doesn\u2019t automatically keep track of photo items. To add .JPG files to your media collection from inside Windows Media Player you\u2019ll need to click <B>File<\/B> and then select one of the options under <B>Add to Library<\/B>. Before you can do <I>that<\/I>, however, you must first click <B>Tools<\/B>, click <B>Options<\/B>, and then, on the <B>Player<\/B> tab, select <B>Enable picture support for devices<\/B>. If you don\u2019t enable picture support, Windows Media Player will tell you that .JPG is an unsupported file extension. Enable picture support, then start adding pictures to the media collection.<\/P>\n<TABLE id=\"E5D\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. This doesn\u2019t move your files or convert your .JPGs to some sort of proprietary Windows Media Player format; in fact, it doesn\u2019t do anything to your files other than make them known to the Windows Media Player library.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>After your .JPG files <I>are<\/I> known to Windows Media Player than you can use a script like this to retrieve the vertical and horizontal sizes of each picture:<\/P><PRE class=\"codeSample\">Set objPlayer = CreateObject(&#8220;WMPlayer.OCX&#8221; )\nSet colMediaCollection = objPlayer.mediaCollection<\/p>\n<p>Set objPhotos = colMediaCollection.getByAttribute(&#8220;MediaType&#8221;, &#8220;photo&#8221;)<\/p>\n<p>For i = 0 to objPhotos.Count &#8211; 1\n    Set objPhoto = objPhotos.item(i)\n    Wscript.Echo &#8220;Name: &#8221; &amp; objPhoto.Name\n    Wscript.Echo &#8220;Height: &#8221; &amp; objPhoto.getItemInfo(&#8220;WM\/VideoHeight&#8221;)\n    Wscript.Echo &#8220;Width: &#8221; &amp; objPhoto.getItemInfo(&#8220;WM\/VideoWidth&#8221;)\nNext\n<\/PRE>\n<P>The script begins by creating an instance of the <B>WMPlayer.OCX<\/B> object, and then binds to the Windows Media Player media collection. The script then uses the <B>getByAttribute<\/B> method to return a collection of all the photo items in the media collection (in the world of Windows Media Player 10, photo items are simply .JPG files).<\/P>\n<P>Our photo items come back in the form of an array; to iterate each item in that array we create a For Next loop that runs from 0 (the first item in an array is always numbered 0) to the number of items in the array minus 1 (<B>objPhotos.Count &#8211; 1<\/B>). Inside that For Next loop we bind to each .JPG file using this line of code:<\/P><PRE class=\"codeSample\">Set objPhoto = objPhotos.item(i)\n<\/PRE>\n<P>We then echo the values of the <B>Name<\/B>, <B>WM\/VideoHeight<\/B>, and <B>WM\/VideoWidth<\/B> attributes. As you probably already guessed, the latter two attributes give us the height and width of each picture. <\/P>\n<P>Incidentally, you can do more with .JPG files than simply retrieve their height and width. For a complete list of photo item attributes check out the <A href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/wmplay10\/mmp_sdk\/windowsmediaplayer10sdk.asp\" target=\"_blank\"><B>Windows Media Player SDK<\/B><\/A> on MSDN.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I display the vertical and horizontal resolutions of a .JPG file?&#8212; ST Hey, ST. This is a very commonly-asked question, and for the longest time we had no answer for it: nothing built into the operating system seemed capable of returning this information, and even Dsofile, a COM object released [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[123,3,5,192],"class_list":["post-69813","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-multimedia","tag-scripting-guy","tag-vbscript","tag-windows-media-player-and-audio"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I display the vertical and horizontal resolutions of a .JPG file?&#8212; ST Hey, ST. This is a very commonly-asked question, and for the longest time we had no answer for it: nothing built into the operating system seemed capable of returning this information, and even Dsofile, a COM object released [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=69813"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69813\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=69813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=69813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=69813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}