From 9584ca080c10777407c59c5939dd0cf2a88a847b Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 13 Jan 2016 17:32:09 -0800 Subject: some initial work on uploading and cropping cover photos --- include/photo/photo_driver.php | 3 +++ include/photo/photo_gd.php | 17 ++++++++++++ include/photo/photo_imagick.php | 18 +++++++++++++ mod/profile_photo.php | 4 +-- view/tpl/cover_photo.tpl | 23 ++++++++++++++++ view/tpl/cropcover.tpl | 58 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 121 insertions(+), 2 deletions(-) create mode 100755 view/tpl/cover_photo.tpl create mode 100755 view/tpl/cropcover.tpl diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 0de3b9c97..dce92d8da 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -69,6 +69,8 @@ abstract class photo_driver { abstract function cropImage($max,$x,$y,$w,$h); + abstract function cropImageRect($maxx,$maxy,$x,$y,$w,$h); + abstract function imageString(); @@ -229,6 +231,7 @@ abstract class photo_driver { $this->doScaleImage($dest_width,$dest_height); } + public function scaleImageSquare($dim) { if(!$this->is_valid()) return FALSE; diff --git a/include/photo/photo_gd.php b/include/photo/photo_gd.php index 2ac7287e4..24bdc204f 100644 --- a/include/photo/photo_gd.php +++ b/include/photo/photo_gd.php @@ -108,6 +108,23 @@ class photo_gd extends photo_driver { $this->setDimensions(); } + public function cropImageRect($maxx,$maxy,$x,$y,$w,$h) { + if(!$this->is_valid()) + return FALSE; + + $dest = imagecreatetruecolor( $maxx, $maxy ); + imagealphablending($dest, false); + imagesavealpha($dest, true); + if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha + imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $maxx, $maxy, $w, $h); + if($this->image) + imagedestroy($this->image); + $this->image = $dest; + $this->setDimensions(); + } + + + public function imageString() { if(!$this->is_valid()) return FALSE; diff --git a/include/photo/photo_imagick.php b/include/photo/photo_imagick.php index 3f84fd06c..32bb61342 100644 --- a/include/photo/photo_imagick.php +++ b/include/photo/photo_imagick.php @@ -163,6 +163,24 @@ class photo_imagick extends photo_driver { $this->doScaleImage($max,$max); } + public function cropImageRect($maxx,$maxy,$x,$y,$w,$h) { + if(!$this->is_valid()) + return FALSE; + + $this->image->setFirstIterator(); + do { + $this->image->cropImage($w, $h, $x, $y); + /** + * We need to remove the canvas, + * or the image is not resized to the crop: + * http://php.net/manual/en/imagick.cropimage.php#97232 + */ + $this->image->setImagePage(0, 0, 0, 0); + } while ($this->image->nextImage()); + + $this->doScaleImage($maxx,$maxy); + } + public function imageString() { if(!$this->is_valid()) return FALSE; diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 2884505f0..0091d0585 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -502,8 +502,8 @@ function profile_photo_crop_ui_head(&$a, $ph, $hash, $smallest){ $width = $ph->getWidth(); $height = $ph->getHeight(); - if($width < 300 || $height < 300) { - $ph->scaleImageUp(200); + if($width < 500 || $height < 500) { + $ph->scaleImageUp(400); $width = $ph->getWidth(); $height = $ph->getHeight(); } diff --git a/view/tpl/cover_photo.tpl b/view/tpl/cover_photo.tpl new file mode 100755 index 000000000..1db139e7b --- /dev/null +++ b/view/tpl/cover_photo.tpl @@ -0,0 +1,23 @@ +
+

{{$title}}

+ +
+ + +
+ + + +
+ +
+ +
+
+ +
+ + +
diff --git a/view/tpl/cropcover.tpl b/view/tpl/cropcover.tpl new file mode 100755 index 000000000..2bfd65a8f --- /dev/null +++ b/view/tpl/cropcover.tpl @@ -0,0 +1,58 @@ +

{{$title}}

+

+{{$desc}} +

+
+{{$title}} +
+
+
+
+ + + +
+ + + + + + + + + + + +
+ +
+ +
-- cgit v1.2.3