aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-23 21:05:35 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-23 21:05:35 +0000
commitd53280ff80b672255a8ae2469a668f3b8f63977f (patch)
tree7823d86eb3f273452c246edc5477901e9bf3696c /engine
parent7172a9c77c3885e889208693f0f1044b6d502eaa (diff)
downloadelgg-d53280ff80b672255a8ae2469a668f3b8f63977f.tar.gz
elgg-d53280ff80b672255a8ae2469a668f3b8f63977f.tar.bz2
Image cropping works!
git-svn-id: https://code.elgg.org/elgg/trunk@1082 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/filestore.php24
1 files changed, 19 insertions, 5 deletions
diff --git a/engine/lib/filestore.php b/engine/lib/filestore.php
index 061fe9f4f..dcf802cd5 100644
--- a/engine/lib/filestore.php
+++ b/engine/lib/filestore.php
@@ -617,7 +617,7 @@
* @param true|false $square If set to true, will take the smallest of maxwidth and maxheight and use it to set the dimensions on all size; the image will be cropped.
* @return false|mixed The contents of the resized image, or false on failure
*/
- function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight, $square = false) {
+ function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight, $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) {
// Get the size information from the image
if ($imgsizearray = getimagesize($input_name)) {
@@ -669,11 +669,25 @@
// Crop the image if we need a square
if ($square) {
- $widthoffset = floor(($imgsizearray[0] - $width) / 2);
- $heightoffset = floor(($imgsizearray[1] - $height) / 2);
+ if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) {
+ $widthoffset = floor(($imgsizearray[0] - $width) / 2);
+ $heightoffset = floor(($imgsizearray[1] - $height) / 2);
+ } else {
+ $widthoffset = $x1;
+ $heightoffset = $y1;
+ $width = ($x2 - $x1);
+ $height = $width;
+ }
} else {
- $widthoffset = 0;
- $heightoffset = 0;
+ if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) {
+ $widthoffset = 0;
+ $heightoffset = 0;
+ } else {
+ $widthoffset = $x1;
+ $heightoffset = $y1;
+ $width = ($x2 - $x1);
+ $height = ($y2 - $y1);
+ }
}//else {
// Resize and return the image contents!
imagecopyresampled($newimage, $oldimage, 0,0,$widthoffset,$heightoffset,$newwidth,$newheight,$width,$height);