# Centralization tool

**URL:** https://community.aseprite.org/t/centralization-tool/5474
**Category:** Features
**Created:** [May 1, 2020, 3:48am UTC](https://community.aseprite.org/t/centralization-tool/5474 "2020-05-01T03:48:36Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![tuxpup](https://community.aseprite.org/letter_avatar/tuxpup/32/5_5575768a8748004e209b776fc1b2916d.png) [@tuxpup](https://community.aseprite.org/u/tuxpup)
#### Post date: [May 3, 2020, 5:58am UTC](https://community.aseprite.org/t/centralization-tool/5474/2 "2020-05-03T05:58:03Z")

</div>

I’ve only been using asesprite since earlier today, and I also think this would be useful. I put together a quick script that does it.

You can grab my script [from this git repository](https://git.sr.ht/~tuxpup/asesprite-script-center-selection).

Here is the current content for anyone who just wants to look… if you want to use it, go to the repository, as that is where I will put any improvements I make:

```auto
----------------------------------------------------------------------
-- Center the current selection on the sprite
-- Copyright 2020 Geoff Beier <geoff@tuxpup.com>
-- Licensed under the MIT license. See LICENSE.txt for details.
----------------------------------------------------------------------

-- bail if there's no active sprite
local spr = app.activeSprite
if not spr then return end

-- bail if nothing's selected
local sel = spr.selection
if sel.isEmpty then return end

--print("sel:"..sel.bounds.x..","..sel.bounds.y)

-- The MoveMask command requires us to specify X <units> up, Y <units> down
-- rather than just specifying new coordinates.
new_x = spr.bounds.width/2 - sel.bounds.width/2
x_dir = "right"
x_distance = 0
if new_x < sel.bounds.x then
	x_dir = "left"
	x_distance = sel.bounds.x - new_x
elseif new_x > sel.bounds.x then
	x_dir = "right"
	x_distance = new_x - sel.bounds.x
end

new_y = spr.bounds.height/2 - sel.bounds.height/2
y_dir = "down"
y_distance = 0
if new_y < sel.bounds.y then
	y_dir = "up"
	y_distance = sel.bounds.y - new_y
elseif new_y > sel.bounds.y then
	y_dir = "down"
	y_distance = new_y - sel.bounds.y
end

--print('need to move ' .. x_dir .. ' ' .. tostring(x_distance) .. ' and ' .. y_dir .. ' ' .. tostring(y_distance))

if x_distance ~= 0 then
	app.command.MoveMask{
		direction=x_dir,
		units="pixel",
		quantity=x_distance
	}
end

if y_distance ~= 0 then
	app.command.MoveMask{
		direction=y_dir,
		units="pixel",
		quantity=y_distance
	}
end

```

---

_[View the full topic](https://community.aseprite.org/t/centralization-tool/5474)._
