I was just searching the forum about transforms and came across this post from 11 months ago that @JonB offers some code. I thought it was worth re-posting. It's nice

https://forum.omz-software.com/topic/2268/view-transform-origin