本文整理匯總了PHP中Thumbnail::open方法的典型用法代碼示例。如果您正苦於以下問題:PHP Thumbnail::open方法的具體用法?PHP Thumbnail::open怎麽用?PHP Thumbnail::open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Thumbnail
的用法示例。
在下文中一共展示了Thumbnail::open方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getAvatar
public static function getAvatar(\User $user, $res)
{
global $wgDefaultAvatar, $wgDefaultAvatarRes;
$path = $wgDefaultAvatar;
// If user exists
if ($user && $user->getId()) {
global $wgUploadDirectory, $wgUploadPath;
$avatarPath = "/avatars/{$user->getId()}/{$res}.png";
// Check if requested avatar thumbnail exists
if (file_exists($wgUploadDirectory . $avatarPath)) {
$path = $wgUploadPath . $avatarPath;
} else {
if ($res !== 'original') {
// Dynamically generate upon request
$originalAvatarPath = "/avatars/{$user->getId()}/original.png";
if (file_exists($wgUploadDirectory . $originalAvatarPath)) {
$image = Thumbnail::open($wgUploadDirectory . $originalAvatarPath);
$image->createThumbnail($res, $wgUploadDirectory . $avatarPath);
$image->cleanup();
$path = $wgUploadPath . $avatarPath;
}
}
}
}
return $path;
}
示例2: processUpload
private function processUpload()
{
$request = $this->getRequest();
$dataurl = $request->getVal('avatar');
if (!$dataurl || parse_url($dataurl, PHP_URL_SCHEME) !== 'data') {
$this->displayMessage($this->msg('avatar-notuploaded'));
return false;
}
$img = Thumbnail::open($dataurl);
global $wgMaxAvatarResolution;
switch ($img->type) {
case IMAGETYPE_GIF:
case IMAGETYPE_PNG:
case IMAGETYPE_JPEG:
break;
default:
$this->displayMessage($this->msg('avatar-invalid'));
return false;
}
// Must be square
if ($img->width !== $img->height) {
$this->displayMessage($this->msg('avatar-notsquare'));
return false;
}
// Check if image is too small
if ($img->width < 32 || $img->height < 32) {
$this->displayMessage($this->msg('avatar-toosmall'));
return false;
}
// Check if image is too big
if ($img->width > $wgMaxAvatarResolution || $img->height > $wgMaxAvatarResolution) {
$this->displayMessage($this->msg('avatar-toolarge'));
return false;
}
$user = $this->getUser();
Avatars::deleteAvatar($user);
// Avatar directories
global $wgAvatarUploadDirectory;
$uploadDir = $wgAvatarUploadDirectory . '/' . $this->getUser()->getId() . '/';
@mkdir($uploadDir, 0777, true);
// We do this to convert format to png
$img->createThumbnail($wgMaxAvatarResolution, $uploadDir . 'original.png');
// We only create thumbnail with default resolution here. Others are generated on demand
global $wgDefaultAvatarRes;
$img->createThumbnail($wgDefaultAvatarRes, $uploadDir . $wgDefaultAvatarRes . '.png');
$img->cleanup();
$this->displayMessage($this->msg('avatar-saved'));
global $wgAvatarLogInRC;
$logEntry = new \ManualLogEntry('avatar', 'upload');
$logEntry->setPerformer($this->getUser());
$logEntry->setTarget($this->getUser()->getUserPage());
$logId = $logEntry->insert();
$logEntry->publish($logId, $wgAvatarLogInRC ? 'rcandudp' : 'udp');
return true;
}