{"id":100,"date":"2011-03-11T11:15:37","date_gmt":"2011-03-11T11:15:37","guid":{"rendered":"http:\/\/blog.soton.ac.uk\/tag4fun\/?p=100"},"modified":"2011-05-26T14:33:36","modified_gmt":"2011-05-26T14:33:36","slug":"scaling-images","status":"publish","type":"post","link":"https:\/\/blog.soton.ac.uk\/tag4fun\/2011\/03\/11\/scaling-images\/","title":{"rendered":"Scaling images"},"content":{"rendered":"<p>The same image can be posted a number of times at different sizes, for example:<br \/>\n<a href=\"http:\/\/blog.soton.ac.uk\/tag4fun\/files\/2011\/02\/IMG_20110223_125353.jpg\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-92\" title=\"IMG_20110223_125353\" src=\"http:\/\/blog.soton.ac.uk\/tag4fun\/files\/2011\/02\/IMG_20110223_125353.jpg\" alt=\"\" width=\"100\"  style=\"width: 100px; !important\" srcset=\"https:\/\/blog.soton.ac.uk\/tag4fun\/files\/2011\/02\/IMG_20110223_125353.jpg 2592w, https:\/\/blog.soton.ac.uk\/tag4fun\/files\/2011\/02\/IMG_20110223_125353-300x225.jpg 300w, https:\/\/blog.soton.ac.uk\/tag4fun\/files\/2011\/02\/IMG_20110223_125353-1024x771.jpg 1024w\" sizes=\"(max-width: 2592px) 100vw, 2592px\" \/><\/a><a href=\"http:\/\/blog.soton.ac.uk\/tag4fun\/files\/2011\/02\/IMG_20110223_125353.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-92\" title=\"IMG_20110223_125353\" src=\"http:\/\/blog.soton.ac.uk\/tag4fun\/files\/2011\/02\/IMG_20110223_125353.jpg\" alt=\"\" width=\"2592\" height=\"1952\" srcset=\"https:\/\/blog.soton.ac.uk\/tag4fun\/files\/2011\/02\/IMG_20110223_125353.jpg 2592w, https:\/\/blog.soton.ac.uk\/tag4fun\/files\/2011\/02\/IMG_20110223_125353-300x225.jpg 300w, https:\/\/blog.soton.ac.uk\/tag4fun\/files\/2011\/02\/IMG_20110223_125353-1024x771.jpg 1024w\" sizes=\"auto, (max-width: 2592px) 100vw, 2592px\" \/><\/a><\/p>\n<p>To deal with this we will simply store the tag position in the database relative to the full sized image, and scale the tags on each image to match the resized image. Our initial prototype (and the one running on this blog) did not have this however it has been implemented on the latest prototypes as such:<\/p>\n<blockquote><p>\/**<\/p>\n<p>* Get the original size of an image<\/p>\n<p>* @param {string} img The location of the image<\/p>\n<p>* @return {{width: number, height: number}} The dimensions of the image<\/p>\n<p>*\/<\/p>\n<p>me.jscott.taggr.getImageSize = function (img) {<\/p>\n<p>var i = new Image();<\/p>\n<p>i.src = img;<\/p>\n<p>return {&#8220;width&#8221;: i.width, &#8220;height&#8221;: i.height}<\/p>\n<p>}<\/p>\n<p>var original_size = me.jscott.taggr.getImageSize(imgs[i].src);<\/p>\n<p>var size = goog.style.getSize(imgs[i]);<\/p>\n<div id=\"_mcePaste\">imgs[i].setAttribute(&#8216;_tgr_width_scale&#8217;, size.width \/ original_size.width);<\/div>\n<div id=\"_mcePaste\">imgs[i].setAttribute(&#8216;_tgr_height_scale&#8217;, size.height \/ original_size.height);<\/div>\n<div>\/\/ &#8230;<\/div>\n<div>\/\/ position tag<\/div>\n<div>\n<div>goog.style.setSize(container, new goog.math.Size(parseInt(a.getAttribute(&#8220;_tgr_width&#8221;),10), parseInt(a.getAttribute(&#8220;_tgr_height&#8221;),10)));<\/div>\n<div>goog.style.setPosition(container, new goog.math.Coordinate(parseInt(a.getAttribute(&#8220;_tgr_absolute_x&#8221;),10), parseInt(a.getAttribute(&#8220;_tgr_absolute_y&#8221;),10));<\/div>\n<\/div>\n<\/blockquote>\n<div>(although the actual code is a lot nicer formatted with comments and everything&#8230;. honestly!)<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The same image can be posted a number of times at different sizes, for example: To deal with this we will simply store the tag position in the database relative to the full sized image, and scale the tags on &hellip; <a href=\"https:\/\/blog.soton.ac.uk\/tag4fun\/2011\/03\/11\/scaling-images\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":159,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6475],"tags":[6481,191,11809],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-technical-problems","tag-javascript","tag-prototype","tag-scaling"],"_links":{"self":[{"href":"https:\/\/blog.soton.ac.uk\/tag4fun\/wp-json\/wp\/v2\/posts\/100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.soton.ac.uk\/tag4fun\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.soton.ac.uk\/tag4fun\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/tag4fun\/wp-json\/wp\/v2\/users\/159"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/tag4fun\/wp-json\/wp\/v2\/comments?post=100"}],"version-history":[{"count":5,"href":"https:\/\/blog.soton.ac.uk\/tag4fun\/wp-json\/wp\/v2\/posts\/100\/revisions"}],"predecessor-version":[{"id":507,"href":"https:\/\/blog.soton.ac.uk\/tag4fun\/wp-json\/wp\/v2\/posts\/100\/revisions\/507"}],"wp:attachment":[{"href":"https:\/\/blog.soton.ac.uk\/tag4fun\/wp-json\/wp\/v2\/media?parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/tag4fun\/wp-json\/wp\/v2\/categories?post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/tag4fun\/wp-json\/wp\/v2\/tags?post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}