Esempio n. 1
0
 private static function _cropImage()
 {
     $out = new stdClass();
     $out->success = false;
     $out->message = 'Unable to crop image';
     $imageFile = Lib\Url::Post('imageFile');
     $x = Lib\Url::Post('x', true);
     $y = Lib\Url::Post('y', true);
     $width = Lib\Url::Post('width', true);
     $height = Lib\Url::Post('height', true);
     if ($imageFile && null !== $x && null !== $y && null !== $width && null !== $height) {
         $imageFile = $imageFile[0] === '/' ? '.' . $imageFile : $imageFile;
         $image = Lib\ImageLoader::loadImage($imageFile);
         if ($image) {
             $image = self::_sizeUp($image->image);
             $croppedImage = imagecreatetruecolor(BRACKET_IMAGE_SIZE, BRACKET_IMAGE_SIZE);
             imagecopyresampled($croppedImage, $image, 0, 0, $x, $y, BRACKET_IMAGE_SIZE, BRACKET_IMAGE_SIZE, $width, $height);
             $fileName = '/cache/' . md5($imageFile) . '.jpg';
             imagejpeg($croppedImage, '.' . $fileName);
             imagedestroy($image);
             imagedestroy($croppedImage);
             $out->success = true;
             $out->fileName = $fileName;
         }
     } else {
         $out->message = 'Parameters missing';
     }
     Lib\Display::renderJson($out);
 }
Esempio n. 2
0
 private static function _verifyImage($url)
 {
     $image = Lib\ImageLoader::loadImage($url);
     $retVal = $image && imagesx($image->image) === BRACKET_IMAGE_SIZE && imagesy($image->image) === BRACKET_IMAGE_SIZE;
     imagedestroy($image->image);
     return $retVal;
 }