{"id":6681,"date":"2014-06-16T16:37:28","date_gmt":"2014-06-16T13:37:28","guid":{"rendered":"http:\/\/blog.belvg.com\/?p=6681"},"modified":"2019-03-28T09:18:06","modified_gmt":"2019-03-28T07:18:06","slug":"how-to-get-real-image-sizes-on-php-level-in-magento","status":"publish","type":"post","link":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html","title":{"rendered":"How to Get Real Image Sizes on PHP Level in Magento"},"content":{"rendered":"<p>Sometimes it is necessary to know the real size of an image before rendering and displaying it on a page. Below you can see the function which returns the array of sizes (such as heigh and width) for a specific image.<!--more--><\/p>\n<pre class=\"lang:php decode:true\">\/**\r\n     * Define real sizes of image from image folder\r\n     *\r\n     * @param string $filename   \r\n     * @return array\r\n     *\/\r\n    public function getImgRealSizes($filename)\r\n    {\r\n        $path = Mage::getBaseDir('media') . DS . $this-&gt;getMediaDir() . DS . $filename;\r\n        if (file_exists($path)) {\r\n            $imageObj = new Varien_Image($path);\r\n            return array('height' =&gt; $imageObj-&gt;getOriginalHeight(),\r\n                         'width' =&gt; $imageObj-&gt;getOriginalWidth());\r\n        }\r\n\r\n        return FALSE;\r\n    }<\/pre>\n<p align=\"left\">Here: $path = Mage::getBaseDir(&#8216;media&#8217;) . DS . $this-&gt;getMediaDir() . DS . $filename; &#8211; full path to the image file<\/p>\n<p>This function is suitable for such modules as Animated Slider and Splashpage.<\/p>\n<p>Here is an example of its usage:<\/p>\n<pre class=\"lang:php decode:true\">        public function getMediaDir($filename)\r\n    {\r\n        return &#8216;myfolder&#8217;;\r\n    }\r\n\r\n    public function myFunction()\r\n    {\r\n        $filename = &#8216;mypicture.jpg&#8217;;\r\n        $sizes = $this-&gt;getImgRealSizes($filename);\r\n        echo $sizes[&#8216;height&#8217;] \/* display real height of current image *\/\r\n        echo $sizes[&#8216;width&#8217;]  \/* display rela width *\/\r\n        }<\/pre>\n","protected":false},"excerpt":{"rendered":"Sometimes it is necessary to know the real size of an image before rendering and &#8230;","protected":false},"author":30,"featured_media":8962,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_acf_changed":false,"footnotes":""},"categories":[14],"tags":[226],"class_list":["post-6681","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-magento","tag-images","post_format-post-format-image"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.4 - aioseo.com -->\n\t<meta name=\"description\" content=\"Sometimes it is necessary to know the real size of an image before rendering and displaying it on a page. Below you can see the function which returns the array of sizes (such as heigh and width) for a specific image.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Andrei Danilchyk\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.4\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-get-real-image-sizes-on-php-level-in-magento.html#article\",\"name\":\"How to Get Real Image Sizes on PHP Level in Magento | BelVG Blog\",\"headline\":\"How to Get Real Image Sizes on PHP Level in Magento\",\"author\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/06\\\/blog-real-size1.jpg\",\"width\":682,\"height\":170},\"datePublished\":\"2014-06-16T16:37:28+02:00\",\"dateModified\":\"2019-03-28T09:18:06+02:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-get-real-image-sizes-on-php-level-in-magento.html#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-get-real-image-sizes-on-php-level-in-magento.html#webpage\"},\"articleSection\":\"Magento, images, Image\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-get-real-image-sizes-on-php-level-in-magento.html#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"name\":\"Magento\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"position\":2,\"name\":\"Magento\",\"item\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-get-real-image-sizes-on-php-level-in-magento.html#listItem\",\"name\":\"How to Get Real Image Sizes on PHP Level in Magento\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-get-real-image-sizes-on-php-level-in-magento.html#listItem\",\"position\":3,\"name\":\"How to Get Real Image Sizes on PHP Level in Magento\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"name\":\"Magento\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\",\"name\":\"BelVG Blog\",\"description\":\"Magento and Prestashop articles\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk#author\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk\",\"name\":\"Andrei Danilchyk\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-get-real-image-sizes-on-php-level-in-magento.html#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/035c7a3d986ac8d09b60f02a1d47ab8822a92657f10160d588ea28f14db1efb7?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Andrei Danilchyk\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-get-real-image-sizes-on-php-level-in-magento.html#webpage\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-get-real-image-sizes-on-php-level-in-magento.html\",\"name\":\"How to Get Real Image Sizes on PHP Level in Magento | BelVG Blog\",\"description\":\"Sometimes it is necessary to know the real size of an image before rendering and displaying it on a page. Below you can see the function which returns the array of sizes (such as heigh and width) for a specific image.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-get-real-image-sizes-on-php-level-in-magento.html#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/06\\\/blog-real-size1.jpg\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-get-real-image-sizes-on-php-level-in-magento.html\\\/#mainImage\",\"width\":682,\"height\":170},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-get-real-image-sizes-on-php-level-in-magento.html#mainImage\"},\"datePublished\":\"2014-06-16T16:37:28+02:00\",\"dateModified\":\"2019-03-28T09:18:06+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\",\"name\":\"BelVG Blog\",\"description\":\"Magento and Prestashop articles\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"How to Get Real Image Sizes on PHP Level in Magento | BelVG Blog","description":"Sometimes it is necessary to know the real size of an image before rendering and displaying it on a page. Below you can see the function which returns the array of sizes (such as heigh and width) for a specific image.","canonical_url":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html#article","name":"How to Get Real Image Sizes on PHP Level in Magento | BelVG Blog","headline":"How to Get Real Image Sizes on PHP Level in Magento","author":{"@id":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk#author"},"publisher":{"@id":"https:\/\/belvg.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2014\/06\/blog-real-size1.jpg","width":682,"height":170},"datePublished":"2014-06-16T16:37:28+02:00","dateModified":"2019-03-28T09:18:06+02:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html#webpage"},"isPartOf":{"@id":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html#webpage"},"articleSection":"Magento, images, Image"},{"@type":"BreadcrumbList","@id":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/belvg.com\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","name":"Magento"}},{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","position":2,"name":"Magento","item":"https:\/\/belvg.com\/blog\/category\/magento","nextItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html#listItem","name":"How to Get Real Image Sizes on PHP Level in Magento"},"previousItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html#listItem","position":3,"name":"How to Get Real Image Sizes on PHP Level in Magento","previousItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","name":"Magento"}}]},{"@type":"Organization","@id":"https:\/\/belvg.com\/blog\/#organization","name":"BelVG Blog","description":"Magento and Prestashop articles","url":"https:\/\/belvg.com\/blog\/"},{"@type":"Person","@id":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk#author","url":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk","name":"Andrei Danilchyk","image":{"@type":"ImageObject","@id":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/035c7a3d986ac8d09b60f02a1d47ab8822a92657f10160d588ea28f14db1efb7?s=96&d=mm&r=g","width":96,"height":96,"caption":"Andrei Danilchyk"}},{"@type":"WebPage","@id":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html#webpage","url":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html","name":"How to Get Real Image Sizes on PHP Level in Magento | BelVG Blog","description":"Sometimes it is necessary to know the real size of an image before rendering and displaying it on a page. Below you can see the function which returns the array of sizes (such as heigh and width) for a specific image.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/belvg.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html#breadcrumblist"},"author":{"@id":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk#author"},"creator":{"@id":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk#author"},"image":{"@type":"ImageObject","url":"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2014\/06\/blog-real-size1.jpg","@id":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html\/#mainImage","width":682,"height":170},"primaryImageOfPage":{"@id":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html#mainImage"},"datePublished":"2014-06-16T16:37:28+02:00","dateModified":"2019-03-28T09:18:06+02:00"},{"@type":"WebSite","@id":"https:\/\/belvg.com\/blog\/#website","url":"https:\/\/belvg.com\/blog\/","name":"BelVG Blog","description":"Magento and Prestashop articles","inLanguage":"en-US","publisher":{"@id":"https:\/\/belvg.com\/blog\/#organization"}}]}},"aioseo_meta_data":{"post_id":"6681","title":"How to Get Real Image Sizes on PHP Level in Magento | #site_title","description":"Sometimes it is necessary to know the real size of an image before rendering and displaying it on a page. Below you can see the function which returns the array of sizes (such as heigh and width) for a specific image.","keywords":[{"label":"Image Sizes","value":"Image Sizes"},{"label":"PHP Level","value":"PHP Level"}],"keyphrases":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_custom_url":null,"og_image_custom_fields":null,"og_image_url":null,"og_image_width":null,"og_image_height":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_image_url":null,"twitter_title":null,"twitter_description":null,"schema_type":"default","schema_type_options":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null,"created":"2026-11-03 18:38:01","updated":"2026-11-03 18:38:01"},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/belvg.com\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/belvg.com\/blog\/category\/magento\" title=\"Magento\">Magento<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tHow to Get Real Image Sizes on PHP Level in Magento\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/belvg.com\/blog\/"},{"label":"Magento","link":"https:\/\/belvg.com\/blog\/category\/magento"},{"label":"How to Get Real Image Sizes on PHP Level in Magento","link":"https:\/\/belvg.com\/blog\/how-to-get-real-image-sizes-on-php-level-in-magento.html"}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/6681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/users\/30"}],"replies":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/comments?post=6681"}],"version-history":[{"count":-5,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/6681\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/media\/8962"}],"wp:attachment":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/media?parent=6681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/categories?post=6681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/tags?post=6681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}