本文整理汇总了PHP中OC_Image::centerCrop方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Image::centerCrop方法的具体用法?PHP OC_Image::centerCrop怎么用?PHP OC_Image::centerCrop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_Image
的用法示例。
在下文中一共展示了OC_Image::centerCrop方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleGetAlbumThumbnail
function handleGetAlbumThumbnail($token, $albumname)
{
$owner = OC_Gallery_Sharing::getTokenOwner($token);
$file = OCP\Config::getSystemValue("datadirectory") . '/' . $owner . '/gallery/' . $albumname . '.png';
$image = new OC_Image($file);
if ($image->valid()) {
$image->centerCrop();
$image->resize(200);
$image->fixOrientation();
OCP\Response::enableCaching(3600 * 24);
// 24 hour
$image->show();
}
}
示例2: handleGetAlbumThumbnail
function handleGetAlbumThumbnail($token, $albumname)
{
$owner = OC_Gallery_Sharing::getTokenOwner($token);
$view = OCP\Files::getStorage('gallery');
$file = $view->fopen($albumname . '.png', 'r');
$image = new OC_Image($file);
if ($image->valid()) {
$image->centerCrop();
$image->resize(200);
$image->fixOrientation();
OCP\Response::enableCaching(3600 * 24);
// 24 hour
$image->show();
}
}
示例3: testCenterCrop
public function testCenterCrop()
{
$img = new \OC_Image(OC::$SERVERROOT . '/tests/data/testimage.png');
$img->centerCrop();
$this->assertEquals(128, $img->width());
$this->assertEquals(128, $img->height());
$img = new \OC_Image(file_get_contents(OC::$SERVERROOT . '/tests/data/testimage.jpg'));
$img->centerCrop();
$this->assertEquals(1050, $img->width());
$this->assertEquals(1050, $img->height());
$img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT . '/tests/data/testimage.gif')));
$img->centerCrop(512);
$this->assertEquals(512, $img->width());
$this->assertEquals(512, $img->height());
}
示例4: getThumbnail
public static function getThumbnail($image_name, $owner = null)
{
if (!$owner) {
$owner = OCP\USER::getUser();
}
$save_dir = OCP\Config::getSystemValue("datadirectory") . '/' . $owner . '/gallery/';
$save_dir .= dirname($image_name) . '/';
$image_path = $image_name;
$thumb_file = $save_dir . basename($image_name);
if (!is_dir($save_dir)) {
mkdir($save_dir, 0777, true);
}
if (file_exists($thumb_file)) {
$image = new OC_Image($thumb_file);
} else {
$image_path = OC_Filesystem::getLocalFile($image_path);
if (!file_exists($image_path)) {
return null;
}
$image = new OC_Image($image_path);
if ($image->valid()) {
$image->centerCrop(200);
$image->fixOrientation();
$image->save($thumb_file);
}
}
if ($image->valid()) {
return $image;
} else {
$image->destroy();
}
return null;
}
示例5: getThumbnail
public static function getThumbnail($image_name, $owner = null)
{
if (!$owner) {
$owner = OCP\USER::getUser();
}
$view = OCP\Files::getStorage('gallery');
$save_dir = dirname($image_name);
if (!$view->is_dir($save_dir)) {
$view->mkdir($save_dir);
}
$view->chroot($view->getRoot() . '/' . $save_dir);
$thumb_file = basename($image_name);
if ($view->file_exists($thumb_file)) {
$image = new OC_Image($view->fopen($thumb_file, 'r'));
} else {
$image_path = OC_Filesystem::getLocalFile($image_name);
if (!file_exists($image_path)) {
return null;
}
$image = new OC_Image($image_path);
if ($image->valid()) {
$image->centerCrop(200);
$image->fixOrientation();
$image->save($view->getLocalFile($thumb_file));
}
}
if ($image->valid()) {
return $image;
} else {
$image->destroy();
}
return null;
}
示例6: getStandardImage
// invalid vcard
if (is_null($contact)) {
OCP\Util::writeLog('contacts', 'thumbnail.php. The VCard for ID ' . $id . ' is not RFC compatible', OCP\Util::ERROR);
getStandardImage();
exit;
}
OCP\Response::enableCaching($caching);
OC_Contacts_App::setLastModifiedHeader($contact);
$thumbnail_size = 23;
// Find the photo from VCard.
$image = new OC_Image();
$photo = $contact->getAsString('PHOTO');
if ($photo) {
OCP\Response::setETagHeader(md5($photo));
if ($image->loadFromBase64($photo)) {
if ($image->centerCrop()) {
if ($image->resize($thumbnail_size)) {
if ($image->show()) {
// done
exit;
} else {
OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t display thumbnail for ID ' . $id, OCP\Util::ERROR);
}
} else {
OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t resize thumbnail for ID ' . $id, OCP\Util::ERROR);
}
} else {
OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t crop thumbnail for ID ' . $id, OCP\Util::ERROR);
}
} else {
OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t load image string for ID ' . $id, OCP\Util::ERROR);
示例7: cacheThumbnail
public static function cacheThumbnail($id, \OC_Image $image = null)
{
if (\OC_Cache::hasKey(self::THUMBNAIL_PREFIX . $id)) {
return \OC_Cache::get(self::THUMBNAIL_PREFIX . $id);
}
if (is_null($image)) {
$vcard = self::getContactVCard($id);
// invalid vcard
if (is_null($vcard)) {
\OCP\Util::writeLog('contacts', __METHOD__ . ' The VCard for ID ' . $id . ' is not RFC compatible', \OCP\Util::ERROR);
return false;
}
$image = new \OC_Image();
if (!isset($vcard->PHOTO)) {
return false;
}
if (!$image->loadFromBase64((string) $vcard->PHOTO)) {
return false;
}
}
if (!$image->centerCrop()) {
\OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t crop thumbnail for ID ' . $id, \OCP\Util::ERROR);
return false;
}
if (!$image->resize(self::THUMBNAIL_SIZE)) {
\OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t resize thumbnail for ID ' . $id, \OCP\Util::ERROR);
return false;
}
// Cache for around a month
\OC_Cache::set(self::THUMBNAIL_PREFIX . $id, $image->data(), 3000000);
\OCP\Util::writeLog('contacts', 'Caching ' . $id, \OCP\Util::DEBUG);
return \OC_Cache::get(self::THUMBNAIL_PREFIX . $id);
}
示例8: rtrim
<?php
// Get the data
$imageData = $_POST['canv_data'];
$title = rtrim($_POST['title'], 'pdf');
$location = urldecode(dirname($_POST['location']));
if ($location != '/') {
$location = $location . '/';
}
$filteredData = substr($imageData, strpos($imageData, ",") + 1);
$owner = OCP\USER::getUser();
$save_dir = OCP\Config::getSystemValue("datadirectory") . '/' . $owner . '/reader';
$save_dir .= $location;
$thumb_file = $save_dir . $title;
if (!is_dir($save_dir)) {
mkdir($save_dir, 0777, true);
}
$image = new OC_Image($filteredData);
if ($image->valid()) {
$image->centerCrop(100);
$image->fixOrientation();
$image->save($thumb_file . 'png');
}