{"id":128,"date":"2024-08-16T17:21:25","date_gmt":"2024-08-16T17:21:25","guid":{"rendered":"https:\/\/www.mickiwiki.com\/?p=128"},"modified":"2025-03-25T13:02:28","modified_gmt":"2025-03-25T13:02:28","slug":"centres","status":"publish","type":"post","link":"https:\/\/www.mickiwiki.com\/?p=128","title":{"rendered":"Centres"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Change the co-ordinates of an overlay FROM its centre relative to canvas centre TO its top left corner relative to canvas top left corner (0,0)<br>W= canvas width<br>H= canvas height<br>w= overlay width<br>h = overlay height<br>cx = overlay centre x relative to canvas centre x<br>( left of canvas centre cx is negative, right of canvas centre cx is positive )<br>cy = overlay centre y relative to canvas centre y<br>( above canvas centre cy is negative, below canvas centre cy is positive )<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Position of top left corner of overlay relative to top left corner of canvas is;<br>x=((W-w)\/2)+cx<br>y=((H-h)\/2)+cy<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is probably useful if you want to place images. If you calculate from their centres it doesn&#8217;t matter how big the images are.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use Image::Imlib2;\nmy ($x,$y,$x1,$y1,$w,$h,$canw,$canh);\n$canw=400;\n$canh=400;\nmy $image0=Image::Imlib2->new($canw,$canh);\n$image0->has_alpha(255);\n$x=-100;\n$y=-100;\n$w=100;###&lt;&lt;&lt;&lt;\n$h=100;###&lt;&lt;&lt;&lt;\n$x1=(($canw-$w)\/2)+$x;\n$y1=(($canh-$h)\/2)+$y;\n$image0->set_color(0,0,255,100);#blue\n$image0->fill_rectangle($x1,$y1,$w,$h);\n\n$x=-100;\n$y=-100;\n$w=200;###&lt;&lt;&lt;&lt;\n$h=200;###&lt;&lt;&lt;&lt;\n$x1=(($canw-$w)\/2)+$x;\n$y1=(($canh-$h)\/2)+$y;\n$image0->set_color(255,0,0,100);#red\n$image0->fill_rectangle($x1,$y1,$w,$h);\n\n$image0->save('rectangle3.png');<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"800\" src=\"https:\/\/www.mickiwiki.com\/wp-content\/uploads\/2024\/08\/rectangle2.png\" alt=\"\" class=\"wp-image-214\" srcset=\"https:\/\/www.mickiwiki.com\/wp-content\/uploads\/2024\/08\/rectangle2.png 800w, https:\/\/www.mickiwiki.com\/wp-content\/uploads\/2024\/08\/rectangle2-300x300.png 300w, https:\/\/www.mickiwiki.com\/wp-content\/uploads\/2024\/08\/rectangle2-150x150.png 150w, https:\/\/www.mickiwiki.com\/wp-content\/uploads\/2024\/08\/rectangle2-768x768.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Change the co-ordinates of an overlay FROM its centre relative to canvas centre TO its top left corner relative to canvas top left corner (0,0)W= canvas widthH= canvas heightw= overlay widthh = overlay heightcx = overlay centre x relative to canvas centre x( left of canvas centre cx is negative, right of canvas centre cx&hellip;&nbsp;<a href=\"https:\/\/www.mickiwiki.com\/?p=128\" rel=\"bookmark\"><span class=\"screen-reader-text\">Centres<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-128","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.mickiwiki.com\/index.php?rest_route=\/wp\/v2\/posts\/128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mickiwiki.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mickiwiki.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mickiwiki.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mickiwiki.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=128"}],"version-history":[{"count":3,"href":"https:\/\/www.mickiwiki.com\/index.php?rest_route=\/wp\/v2\/posts\/128\/revisions"}],"predecessor-version":[{"id":215,"href":"https:\/\/www.mickiwiki.com\/index.php?rest_route=\/wp\/v2\/posts\/128\/revisions\/215"}],"wp:attachment":[{"href":"https:\/\/www.mickiwiki.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mickiwiki.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mickiwiki.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}