From 26006328fbf0439b91a2a42b8cdf748a201111fb Mon Sep 17 00:00:00 2001 From: Jono Menz Date: Mon, 15 Sep 2014 15:21:12 -0700 Subject: [PATCH] Added CSS percentage outputs For background-position when using background-size:cover --- code/FocusPointImage.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/code/FocusPointImage.php b/code/FocusPointImage.php index e0a6846..49d4eac 100755 --- a/code/FocusPointImage.php +++ b/code/FocusPointImage.php @@ -66,6 +66,28 @@ public function BasicFocusArea() { return 'focus-'.$horzFocus.'-'.$vertFocus; } + /** + * Generate a percentage based description of x focus point for use in CSS. + * Range is 0% - 100%. Example x=.5 translates to 75% + * Use in templates with {$PercentageX}% + * + * @return int + */ + public function PercentageX() { + return round(($this->owner->FocusX + 1)*50); + } + + /** + * Generate a percentage based description of y focus point for use in CSS. + * Range is 0% - 100%. Example y=-.5 translates to 75% + * Use in templates with {$PercentageY}% + * + * @return int + */ + public function PercentageY() { + return round(($this->owner->FocusY - 1)*-50); + } + /** * Generate a resized copy of this image with the given width & height, cropping to maintain aspect ratio and focus point. * Use in templates with $CroppedFocusedImage