function resize_image($filename, $destfile = null, $width = 600, $quality = 90) { try { require_once dirname(__DIR__) . '/Util/ImageResize.php'; $img = new Eventviva\ImageResize($filename); $img->quality_jpg = $quality; if ($img->getSourceWidth() > $img->getSourceHeight()) { if ($img->getSourceWidth() < $width) { if ($destfile == $filename) { return false; } } else { $img->resizeToWidth($width); } } else { if ($img->getSourceHeight() < $width) { if ($destfile == $filename) { return false; } } else { $img->resizeToHeight($width); } } if ($destfile === null) { $destfile = $filename; } $img->save($destfile); return true; } catch (Exception $e) { } return false; }
if (empty($post['author'])) { $post['author'] = 'none'; } $errors = array(); if (!empty($_POST['file'])) { $dataURL = $_POST['file']; $data = explode(',', $dataURL)[1]; $data = base64_decode($data); $file = uniqid(); $name = preg_replace("/\\.[^.\\s]{3,4}\$/", "", $file); $location = WWW_ROOT . 'uploads/images/' . $_POST['content']; $success = file_put_contents($location, $data); $upload = $pinDAO->insert($post); if (!empty($upload)) { $image = new Eventviva\ImageResize($location); $image->resizeToWidth(800); $image->save(WWW_ROOT . 'uploads/images/' . 'large_' . $_POST['content']); $image->resizeToWidth(300); $image->save(WWW_ROOT . 'uploads/images/' . $_POST['content']); echo json_encode($upload); } } else { echo json_encode($pinDAO->insert($post), JSON_NUMERIC_CHECK); } }); $app->get('/pins/tags/?', function () use($pinDAO) { header("Content-Type: application/json"); echo json_encode($pinDAO->selectTagsById($_SESSION['user']['id']), JSON_NUMERIC_CHECK); exit; }); $app->get('/pins/tags/:tag/?', function ($tag) use($pinDAO) {
if (!is_dir($path . '/thumbnails')) { mkdir($path . '/thumbnails'); } if (!file_exists($targetPath . '.aes')) { if (move_uploaded_file($tFile, $targetPath)) { $finfo = finfo_open(FILEINFO_MIME_TYPE); $fileType = finfo_file($finfo, $targetPath); finfo_close($finfo); require_once 'includes/aes256/AESCryptFileLib.php'; require_once 'includes/aes256/MCryptAES256Implementation.php'; $mcrypt = new MCryptAES256Implementation(); $lib = new AESCryptFileLib($mcrypt); if (preg_match("/image/i", $fileType)) { include 'includes/ImageResize.php'; $image = new \Eventviva\ImageResize($targetPath); $image->resizeToWidth(180)->save($thumbnailPath); $file_enc = $fName . '.aes'; $thumb_enc = $thumbName . '.aes'; @unlink($path . '/' . $file_enc); $lib->encryptFile($targetPath, $aeskey, $path . '/' . $file_enc); @unlink($path . '/thumbnails/' . $file_enc); $lib->encryptFile($thumbnailPath, $aeskey, $path . '/thumbnails/' . $thumb_enc); @unlink($targetPath); @unlink($thumbnailPath); } else { if (preg_match("/video/i", $fileType)) { $file_enc = $fName . '.aes'; //$thumb_enc = $thumbName.'.aes'; @unlink($path . '/' . $file_enc); $lib->encryptFile($targetPath, $aeskey, $path . '/' . $file_enc); //@unlink($path.'/thumbnails/'.$file_enc);
function download($url, $store_dir) { $filename = get_image_filename($url, $store_dir); if (file_exists($filename)) { return; } //存在时不下载 $curl = new Curl\Curl(); $curl->setHeader('X-Requested-With', 'XMLHttpRequest'); $curl->setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:40.0) Gecko/20100101 Firefox/40.0'); $curl->setHeader('Accept-Language', 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3'); $curl->setHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'); @mkdir($store_dir, 0755, true); $curl->get($url); $data = $curl->response; file_put_contents($filename, $data); try { $image = new \Eventviva\ImageResize($filename); $image->resizeToWidth(JS_IMG_WIDTH); $image->save($filename); } catch (Exception $e) { } return $filename; }
/** * Generates and stores a cached copy of this thumbnail */ public function generate() { $image = new Eventviva\ImageResize($this->getOriginalUrl()); $image->resizeToWidth($this->_size); $image->save($this->_cache->getCachePath() . DIRECTORY_SEPARATOR . $this->getFilename(), IMAGETYPE_JPEG); }