function watermark($fun = null) { //check if the function is defined if ($fun) { $fun($this->watermark); } //get the values from the current object $overlay = $this->watermark->image; $amount = $this->watermark->opacity; $size = $this->watermark->size; $padding = $this->watermark->padding; $position = $this->watermark->position; //load the defaults and create a filter $width = $this->width; $height = $this->height; $filter = imagecreatetruecolor($width, $height); //set options to make the background transparent imagealphablending($filter, false); imagesavealpha($filter, true); //get the filter size and calculate the percentages list($w, $h) = getimagesize($overlay); $percent = $this->percent($size, $w); $newwidth = $w * $percent; $newheight = $h * $percent; //create a watermark image $watermark = new hashimage(); $png = $watermark->load($overlay)->image; //get its position $this->watermarkPosition($newwidth, $newheight); //make the background transparent and copy the filter to frame with opacity $transparent = imagecolorallocatealpha($filter, 255, 255, 255, 127); imagefilledrectangle($filter, 0, 0, $width, $height, $transparent); imagecopyresampled($filter, $png, $this->watermark->x, $this->watermark->y, 0, 0, $newwidth, $newheight, $w, $h); //merge the images $comp = imagecreatetruecolor($width, $height); imagecopy($comp, $this->image, 0, 0, 0, 0, $width, $height); imagecopy($comp, $filter, 0, 0, 0, 0, $width, $height); imagecopymerge($this->image, $comp, 0, 0, 0, 0, $width, $height, $amount); //remove the image from memory imagedestroy($comp); return $this; }
public function cropimage() { $request = pathang::getInstance('request'); $username = $request->get('username'); $imagefile = 'img/users/' . $username . '_original.jpg'; $image_edit = 'img/users/' . $username . '.jpg'; $edit_page = ROOT . $username . '/edit'; require_once 'lib/hashimage/hashimage.php'; $image = new hashimage(); $image->load($imagefile); $a_width = $image->width; $a_height = $image->height; if ($a_width > 599) { $percent = $a_width / 600; } else { $percent = 1; } $x = 0; $y = 0; $width = $a_width; $height = $a_height; if (!$request->get('w')) { exit; } if ($request->get('x')) { $x = $request->get('x'); } if ($request->get('y')) { $y = $request->get('y'); } if ($request->get('w')) { $width = $request->get('w'); } if ($request->get('h')) { $height = $request->get('h'); } $x = $x * $percent; $width = $width * $percent; $y = $y * $percent; $height = $height * $percent; echo $x . ' ' . $y . ' ' . $width . ' ' . $height; //exit(); $image = new hashimage(); $image->load($imagefile)->crop($x, $y, $width, $height)->save($image_edit); header('Location: ' . $edit_page); }