本文整理匯總了PHP中Imagick::getImageOrientation方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::getImageOrientation方法的具體用法?PHP Imagick::getImageOrientation怎麽用?PHP Imagick::getImageOrientation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::getImageOrientation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: convertExifToJFIF
/**
* 入力された畫像がExifであればエラーを記録し、JFIFに変換します。
* @param \Imagick $imagick JFIFかExif。
*/
protected function convertExifToJFIF(\Imagick $imagick)
{
if ($imagick->getImageProperties('exif:*')) {
$this->logger->error(sprintf(_('「%s」はExif形式です。'), $this->filename));
switch ($imagick->getImageOrientation()) {
case \Imagick::ORIENTATION_TOPRIGHT:
$imagick->flopImage();
break;
case \Imagick::ORIENTATION_BOTTOMRIGHT:
$imagick->rotateImage('none', 180);
break;
case \Imagick::ORIENTATION_BOTTOMLEFT:
$imagick->rotateImage('none', 180);
$imagick->flopImage();
break;
case \Imagick::ORIENTATION_LEFTTOP:
$imagick->rotateImage('none', 90);
$imagick->flopImage();
break;
case \Imagick::ORIENTATION_RIGHTTOP:
$imagick->rotateImage('none', 90);
break;
case \Imagick::ORIENTATION_RIGHTBOTTOM:
$imagick->rotateImage('none', 270);
$imagick->flopImage();
break;
case \Imagick::ORIENTATION_LEFTBOTTOM:
$imagick->rotateImage('none', 270);
break;
}
$imagick->stripImage();
}
}
示例2: fixImageRotation
static function fixImageRotation($file)
{
if (class_exists("\\Imagick")) {
$image = new \Imagick($file);
$orientation = $image->getImageOrientation();
switch ($orientation) {
case \imagick::ORIENTATION_BOTTOMRIGHT:
$image->rotateimage("#000", 180);
// rotate 180 degrees
break;
case \imagick::ORIENTATION_RIGHTTOP:
$image->rotateimage("#000", 90);
// rotate 90 degrees CW
break;
case \imagick::ORIENTATION_LEFTBOTTOM:
$image->rotateimage("#000", -90);
// rotate 90 degrees CCW
break;
}
// Now that it's auto-rotated, make sure the EXIF data is correct in case the EXIF gets saved with the image!
$image->setImageOrientation(\imagick::ORIENTATION_TOPLEFT);
$image->writeImage($file);
} else {
return false;
}
}
示例3: clearAndApplyExifRotation
/**
* @return $this
*/
public function clearAndApplyExifRotation()
{
$orientation = $this->_imagick->getImageOrientation();
switch ($orientation) {
case Imagick::ORIENTATION_TOPRIGHT:
// flipped
// flipped
case Imagick::ORIENTATION_UNDEFINED:
// undefined
// undefined
case Imagick::ORIENTATION_TOPLEFT:
// normal
break;
case Imagick::ORIENTATION_BOTTOMLEFT:
// 180° flipped
// 180° flipped
case Imagick::ORIENTATION_BOTTOMRIGHT:
// 180°
$this->rotate(-180);
$this->_imagick->setImageOrientation(1);
break;
case Imagick::ORIENTATION_LEFTTOP:
// 270° flipped
// 270° flipped
case Imagick::ORIENTATION_RIGHTTOP:
// 270°
$this->rotate(-270);
$this->_imagick->setImageOrientation(1);
break;
case Imagick::ORIENTATION_RIGHTBOTTOM:
// 90° flipped
// 90° flipped
case Imagick::ORIENTATION_LEFTBOTTOM:
// 90°
$this->rotate(-90);
$this->_imagick->setImageOrientation(1);
break;
}
return $this;
}
示例4: handleSave
/**
* @param Asset $asset
* @return string
*/
public function handleSave(Asset $asset)
{
$newImage = new \Imagick($asset->getUploadedFile()->getRealPath());
$asset->setHeight($newImage->getImageHeight());
$asset->setWidth($newImage->getImageWidth());
/** @var array $requiredImage */
foreach ($this->requiredImages as $requiredImage) {
$newImage = new \Imagick($asset->getUploadedFile()->getRealPath());
$newFilename = pathinfo($asset->getFilename(), PATHINFO_FILENAME) . '-' . $requiredImage['name'] . '.' . pathinfo($asset->getFilename(), PATHINFO_EXTENSION);
$imageWidth = $newImage->getImageWidth();
$imageHeight = $newImage->getImageHeight();
$isLandscapeFormat = $imageWidth > $imageHeight;
$orientation = $newImage->getImageOrientation();
$newImage->setCompression(\Imagick::COMPRESSION_JPEG);
$newImage->setImageCompressionQuality($requiredImage['quality']);
if ($isLandscapeFormat) {
$desiredWidth = $requiredImage['long'];
$newImage->resizeImage($desiredWidth, 0, \Imagick::FILTER_LANCZOS, 1);
if (isset($requiredImage['short']) && boolval($requiredImage['crop']) == true) {
$newImage->cropImage($desiredWidth, $requiredImage['short'], 0, 0);
} else {
$newImage->resizeImage(0, $requiredImage['short'], \Imagick::FILTER_LANCZOS, 1);
}
} else {
$desiredHeight = $requiredImage['long'];
$newImage->resizeImage(0, $desiredHeight, \Imagick::FILTER_LANCZOS, 1);
if (isset($requiredImage['short']) && boolval($requiredImage['crop']) == true) {
$newImage->cropImage($requiredImage['short'], $desiredHeight, 0, 0);
} else {
$newImage->resizeImage($requiredImage['short'], 0, \Imagick::FILTER_LANCZOS, 1);
}
}
/**
* This unfortunately kills the orientation. Leave EXIF-Info for now.
*
* $newImage->stripImage();
* $newImage->setImageOrientation($orientation);
*/
$this->assetStorage->uploadFile($newFilename, $newImage);
$subAsset = new SubAsset();
$subAsset->setFilename($newFilename);
$subAsset->setType($requiredImage['name']);
$subAsset->setHeight($newImage->getImageHeight());
$subAsset->setWidth($newImage->getImageWidth());
$asset->addSubAsset($subAsset);
}
}
示例5: fixImageOrientation
/**
* @ref http://www.b-prep.com/blog/?p=1764
*
* @param \Imagick $image
* @return \Imagick
*/
private function fixImageOrientation($image)
{
$orientation = $image->getImageOrientation();
switch ($orientation) {
case \Imagick::ORIENTATION_UNDEFINED:
break;
case \Imagick::ORIENTATION_TOPLEFT:
break;
case \Imagick::ORIENTATION_TOPRIGHT:
$image->flopImage();
$image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
break;
case \Imagick::ORIENTATION_BOTTOMRIGHT:
$image->rotateImage(new \ImagickPixel(), 180);
$image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
break;
case \Imagick::ORIENTATION_BOTTOMLEFT:
$image->rotateImage(new \ImagickPixel(), 180);
$image->flopImage();
$image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
break;
case \Imagick::ORIENTATION_LEFTTOP:
$image->rotateImage(new \ImagickPixel(), 90);
$image->flopImage();
$image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
break;
case \Imagick::ORIENTATION_RIGHTTOP:
$image->rotateImage(new \ImagickPixel(), 90);
$image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
break;
case \Imagick::ORIENTATION_RIGHTBOTTOM:
$image->rotateImage(new \ImagickPixel(), 270);
$image->flopImage();
$image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
break;
case \Imagick::ORIENTATION_LEFTBOTTOM:
$image->rotateImage(new \ImagickPixel(), 270);
$image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
break;
}
return $image;
}
示例6: autoOrient
/**
* Applies EXIF orientation metadata to pixel data and removes the EXIF rotation
*
* @access protected
*/
protected function autoOrient()
{
// apply EXIF orientation to pixel data
switch ($this->originalImage->getImageOrientation()) {
case \Imagick::ORIENTATION_BOTTOMRIGHT:
$this->originalImage->rotateimage('#000', 180);
// rotate 180 degrees
break;
case \Imagick::ORIENTATION_RIGHTTOP:
$this->originalImage->rotateimage('#000', 90);
// rotate 90 degrees CW
break;
case \Imagick::ORIENTATION_LEFTBOTTOM:
$this->originalImage->rotateimage('#000', -90);
// rotate 90 degrees CCW
break;
}
// reset EXIF orientation
$this->originalImage->setImageOrientation(\Imagick::ORIENTATION_TOPLEFT);
}
示例7: createMediaFromJSON
public function createMediaFromJSON($glob)
{
$path = $glob->path;
$filename = $glob->filename;
$data = $glob->data;
$resizeTo = isset($glob->resizeTo) ? $glob->resizeTo : null;
$gameMediaDirectory = Media::getMediaDirectory($path)->data;
$md5 = md5((string) microtime() . $filename);
$ext = strtolower(substr($filename, -3));
$newMediaFileName = 'aris' . $md5 . '.' . $ext;
$resizedMediaFileName = 'aris' . $md5 . '_128.' . $ext;
if ($ext != "jpg" && $ext != "png" && $ext != "gif" && $ext != "mp4" && $ext != "mov" && $ext != "m4v" && $ext != "3gp" && $ext != "caf" && $ext != "mp3" && $ext != "aac" && $ext != "m4a" && $ext != "zip") {
return new returnData(1, NULL, "Invalid filetype:{$ext}");
}
$fullFilePath = $gameMediaDirectory . "/" . $newMediaFileName;
if (isset($resizeTo) && ($ext == "jpg" || $ext == "png" || $ext == "gif")) {
$bigFilePath = $gameMediaDirectory . "/big_" . $newMediaFileName;
$fp = fopen($bigFilePath, 'w');
if (!$fp) {
return new returnData(1, NULL, "Couldn't open file:{$bigFilePath}");
}
fwrite($fp, base64_decode($data));
fclose($fp);
$image = new Imagick($bigFilePath);
// Reorient based on EXIF tag
switch ($image->getImageOrientation()) {
case Imagick::ORIENTATION_UNDEFINED:
// We assume normal orientation
break;
case Imagick::ORIENTATION_TOPLEFT:
// All good
break;
case Imagick::ORIENTATION_TOPRIGHT:
$image->flopImage();
break;
case Imagick::ORIENTATION_BOTTOMRIGHT:
$image->rotateImage('#000', 180);
break;
case Imagick::ORIENTATION_BOTTOMLEFT:
$image->rotateImage('#000', 180);
$image->flopImage();
break;
case Imagick::ORIENTATION_LEFTTOP:
$image->rotateImage('#000', 90);
$image->flopImage();
break;
case Imagick::ORIENTATION_RIGHTTOP:
$image->rotateImage('#000', 90);
break;
case Imagick::ORIENTATION_RIGHTBOTTOM:
$image->rotateImage('#000', -90);
$image->flopImage();
break;
case Imagick::ORIENTATION_LEFTBOTTOM:
$image->rotateImage('#000', -90);
break;
}
$image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
// Resize image proportionally so min(width, height) == $resizeTo
if ($image->getImageWidth() < $image->getImageHeight()) {
$image->resizeImage($resizeTo, 0, Imagick::FILTER_LANCZOS, 1);
} else {
$image->resizeImage(0, $resizeTo, Imagick::FILTER_LANCZOS, 1);
}
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(40);
$image->writeImage($fullFilePath);
unlink($bigFilePath);
} else {
$fp = fopen($fullFilePath, 'w');
if (!$fp) {
return new returnData(1, NULL, "Couldn't open file:{$fullFilePath}");
}
fwrite($fp, base64_decode($data));
fclose($fp);
}
if ($ext == "jpg" || $ext == "png" || $ext == "gif") {
$img = WideImage::load($fullFilePath);
$img = $img->resize(128, 128, 'outside');
$img = $img->crop('center', 'center', 128, 128);
$img->saveToFile($gameMediaDirectory . "/" . $resizedMediaFileName);
} else {
if ($ext == "mp4") {
/*
$ffmpeg = '../../libraries/ffmpeg';
$videoFilePath = $gameMediaDirectory."/".$newMediaFileName;
$tempImageFilePath = $gameMediaDirectory."/temp_".$resizedMediaFileName;
$imageFilePath = $gameMediaDirectory."/".$resizedMediaFileName;
$cmd = "$ffmpeg -i $videoFilePath 2>&1";
$thumbTime = 1;
if(preg_match('/Duration: ((\d+):(\d+):(\d+))/s', shell_exec($cmd), $videoLength))
$thumbTime = (($videoLength[2] * 3600) + ($videoLength[3] * 60) + $videoLength[4])/2;
$cmd = "$ffmpeg -i $videoFilePath -deinterlace -an -ss $thumbTime -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $tempImageFilePath 2>&1";
shell_exec($cmd);
$img = WideImage::load($tempImageFilePath);
$img = $img->resize(128, 128, 'outside');
$img = $img->crop('center','center',128,128);
$img->saveToFile($imageFilePath);
*/
//.........這裏部分代碼省略.........
示例8: ImagickAutoRotateImage
/**
* Automatic rotation fix
*
* @param \Imagick $image
*/
public function ImagickAutoRotateImage(\Imagick $image)
{
$orientation = $image->getImageOrientation();
switch ($orientation) {
case \imagick::ORIENTATION_BOTTOMRIGHT:
$image->rotateimage("#000", 180);
// rotate 180 degrees
break;
case \imagick::ORIENTATION_RIGHTTOP:
$image->rotateimage("#000", 90);
// rotate 90 degrees CW
break;
case \imagick::ORIENTATION_LEFTBOTTOM:
$image->rotateimage("#000", -90);
// rotate 90 degrees CCW
break;
}
$image->setImageOrientation(\imagick::ORIENTATION_TOPLEFT);
}
示例9: thumbnail
//.........這裏部分代碼省略.........
}
}
$handle->image_border_color = '#FFFFFF';
$handle->image_border_opacity = 0;
} else {
// the image size is bigger than the requested width / height, we must resize it
$handle->image_default_color = '#FFFFFF';
$handle->image_resize = true;
$handle->image_ratio_fill = true;
}
if ($border == 0) {
$handle->image_border = false;
$handle->image_ratio_no_zoom_in = false;
if (!empty($item->focalpoint) && $handle->image_src_x > 0) {
$focalpoint = explode('#', $item->focalpoint);
$crop = array('top' => 0, 'right' => 0, 'bottom' => 0, 'left' => 0);
// calculate how the file will be scaled, by width or by height
if ($handle->image_src_x / $handle->image_x > $handle->image_src_y / $handle->image_y) {
// Y is ok, now crop extra space on X
$ratio = $handle->image_y / $handle->image_src_y;
$image_scaled_x = intval($handle->image_src_x * $ratio);
$crop['left'] = max(0, round(($image_scaled_x * ($focalpoint[1] / 100) - $handle->image_x / 2) / $ratio));
$crop['right'] = max(0, round(($image_scaled_x * ((100 - $focalpoint[1]) / 100) - $handle->image_x / 2) / $ratio));
} else {
// X is ok, now crop extra space on Y
$ratio = $handle->image_x / $handle->image_src_x;
$image_scaled_y = intval($handle->image_src_y * $ratio);
$crop['top'] = max(0, round(($image_scaled_y * ($focalpoint[0] / 100) - $handle->image_y / 2) / $ratio));
$crop['bottom'] = max(0, round(($image_scaled_y * ((100 - $focalpoint[0]) / 100) - $handle->image_y / 2) / $ratio));
}
$handle->image_precrop = array($crop['top'], $crop['right'], $crop['bottom'], $crop['left']);
}
$handle->image_ratio_crop = true;
$handle->image_ratio_fill = true;
}
$handle->png_compression = 9;
$handle->process(dirname($thumbnail));
rename($handle->file_dst_pathname, $thumbnail);
clearstatcache(true, $thumbnail);
if (!file_exists($thumbnail) || filesize($thumbnail) < 1) {
return NULL;
}
// try to recompress the png thumbnail file to achieve the minimum file size,
// only if some extra apps are available
if (extension_loaded('imagick')) {
$im = new Imagick($thumbnail);
$image_alpha_range = $im->getImageChannelRange(Imagick::CHANNEL_ALPHA);
//$image_alpha_mean = $im->getImageChannelMean(Imagick::CHANNEL_ALPHA);
$image_is_opaque = $image_alpha_range['minima'] == 0 && $image_alpha_range['maxima'] == 0;
// autorotate image based on EXIF data
$im_original = new Imagick($original);
$orientation = $im_original->getImageOrientation();
$im_original->clear();
switch ($orientation) {
case imagick::ORIENTATION_BOTTOMRIGHT:
$im->rotateimage(new ImagickPixel('transparent'), 180);
// rotate 180 degrees
break;
case imagick::ORIENTATION_RIGHTTOP:
$im->rotateimage(new ImagickPixel('transparent'), 90);
// rotate 90 degrees CW
break;
case imagick::ORIENTATION_LEFTBOTTOM:
$im->rotateimage(new ImagickPixel('transparent'), -90);
// rotate 90 degrees CCW
break;
}
// Now that it's auto-rotated, make sure the EXIF data is correct in case the EXIF gets saved with the image!
$im->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
if (!$image_is_opaque) {
$im->setImageFormat('PNG32');
// Force a full RGBA image format with full semi-transparency.
$im->setBackgroundColor(new ImagickPixel('transparent'));
$im->setImageCompression(Imagick::COMPRESSION_UNDEFINED);
$im->setImageCompressionQuality(0);
$im->writeimage($thumbnail);
} else {
$im->setImageFormat('JPG');
// create an OPAQUE JPG file with the given quality (default 95%)
$im->setImageCompressionQuality($quality);
$im->writeimage($thumbnail_path_jpg);
@unlink($thumbnail);
$thumbnail = $thumbnail_path_jpg;
}
}
/*
if(command_exists('pngquant')) // PNG Optimization: 8 bit with transparency
{
@shell_exec('pngquant -s1 --ext .pngquant '.$thumbnail);
if(file_exists($thumbnail.'.pngquant'))
{
unlink($thumbnail);
rename($thumbnail.'.pngquant', $thumbnail);
}
}
else*/
}
clearstatcache(true, $thumbnail);
return $thumbnail;
}
示例10: imgRotate
function imgRotate($imgFile)
{
$imagick = new \Imagick();
$imagick->readImage($imgFile);
$format = strtolower($imagick->getImageFormat());
if ($format === 'jpeg') {
$orientation = $imagick->getImageOrientation();
$isRotated = false;
if ($orientation === \Imagick::ORIENTATION_RIGHTTOP) {
$imagick->rotateImage('none', 90);
$isRotated = true;
} elseif ($orientation === \Imagick::ORIENTATION_BOTTOMRIGHT) {
$imagick->rotateImage('none', 180);
$isRotated = true;
} elseif ($orientation === \Imagick::ORIENTATION_LEFTBOTTOM) {
$imagick->rotateImage('none', 270);
$isRotated = true;
}
if ($isRotated) {
$imagick->setImageOrientation(\Imagick::ORIENTATION_TOPLEFT);
}
}
}
示例11: _autorotate
/**
* rotate image depending on exif info
*
* @param Imagick $image image handler
* @return void
*/
protected function _autorotate(\Imagick $image)
{
switch ($image->getImageOrientation()) {
case \Imagick::ORIENTATION_TOPRIGHT:
$image->flopImage();
break;
case \Imagick::ORIENTATION_BOTTOMRIGHT:
$image->rotateImage('#000', 180);
break;
case \Imagick::ORIENTATION_BOTTOMLEFT:
$image->flopImage();
$image->rotateImage('#000', 180);
break;
case \Imagick::ORIENTATION_LEFTTOP:
$image->flopImage();
$image->rotateImage('#000', -90);
break;
case \Imagick::ORIENTATION_RIGHTTOP:
$image->rotateImage('#000', 90);
break;
case \Imagick::ORIENTATION_RIGHTBOTTOM:
$image->flopImage();
$image->rotateImage('#000', 90);
break;
case \Imagick::ORIENTATION_LEFTBOTTOM:
$image->rotateImage('#000', -90);
break;
}
$image->setImageOrientation(\Imagick::ORIENTATION_TOPLEFT);
}
示例12: _getImageInfo
private function _getImageInfo()
{
$imageinfo = NULL;
// if($size = @getimagesize($this->tmpfile)) {
// if($size[0] > 0 && $size[1] > 0) {
// $imageinfo['width'] = $size[0];
// $imageinfo['height'] = $size[1];
// //$imageinfo['image_type']=$size[2];
// }
// }
if (!$imageinfo && class_exists('Imagick')) {
$img = new Imagick($this->tmpfile);
$imageinfo['width'] = $img->getImageWidth();
$imageinfo['height'] = $img->getImageHeight();
try {
$imageinfo['orientation'] = $img->getImageOrientation();
} catch (ImagickException $e) {
$imageinfo['orientation'] = 0;
}
//$imageinfo['image_type']=@exif_imagetype($this->tmpfile);
}
return $imageinfo;
}
示例13: rotateImage
/**
* Rotates the specified image based on the EXIF meta data.
*
* @param Imagick $imagick The image object
* @return Imagick The rotated image object
*/
private function rotateImage(\Imagick $imagick)
{
$orientation = $imagick->getImageOrientation();
switch ($orientation) {
case \Imagick::ORIENTATION_BOTTOMRIGHT:
$imagick->rotateImage("#000000", 180);
break;
case \Imagick::ORIENTATION_RIGHTTOP:
$imagick->rotateImage("#000000", 90);
break;
case \Imagick::ORIENTATION_LEFTBOTTOM:
$imagick->rotateImage("#000000", -90);
break;
}
$imagick->setImageOrientation(\Imagick::ORIENTATION_TOPLEFT);
return $imagick;
}
示例14: imagick_orient_image
protected function imagick_orient_image(\Imagick $image)
{
$orientation = $image->getImageOrientation();
$background = new \ImagickPixel('none');
switch ($orientation) {
case \imagick::ORIENTATION_TOPRIGHT:
// 2
$image->flopImage();
// horizontal flop around y-axis
break;
case \imagick::ORIENTATION_BOTTOMRIGHT:
// 3
$image->rotateImage($background, 180);
break;
case \imagick::ORIENTATION_BOTTOMLEFT:
// 4
$image->flipImage();
// vertical flip around x-axis
break;
case \imagick::ORIENTATION_LEFTTOP:
// 5
$image->flopImage();
// horizontal flop around y-axis
$image->rotateImage($background, 270);
break;
case \imagick::ORIENTATION_RIGHTTOP:
// 6
$image->rotateImage($background, 90);
break;
case \imagick::ORIENTATION_RIGHTBOTTOM:
// 7
$image->flipImage();
// vertical flip around x-axis
$image->rotateImage($background, 270);
break;
case \imagick::ORIENTATION_LEFTBOTTOM:
// 8
$image->rotateImage($background, 270);
break;
default:
return false;
}
$image->setImageOrientation(\imagick::ORIENTATION_TOPLEFT);
// 1
return true;
}
示例15: createMedia
public static function createMedia($pack)
{
$pack->auth->permission = "read_write";
if (!users::authenticateUser($pack->auth)) {
return new return_package(6, NULL, "Failed Authentication");
}
$filenameext = strtolower(substr($pack->file_name, strrpos($pack->file_name, '.') + 1));
if ($filenameext == "jpeg") {
$filenameext = "jpg";
}
//sanity
$filename = md5((string) microtime() . $pack->file_name);
$newfilename = 'aris' . $filename . '.' . $filenameext;
$resizedfilename = 'aris' . $filename . '_resized.' . $filenameext;
$newthumbfilename = 'aris' . $filename . '_128.' . $filenameext;
// Make sure playerUploaded requirements keep in sync with this list
if ($filenameext != "jpg" && $filenameext != "png" && $filenameext != "gif" && $filenameext != "mp4" && $filenameext != "mov" && $filenameext != "m4v" && $filenameext != "3gp" && $filenameext != "caf" && $filenameext != "mp3" && $filenameext != "aac" && $filenameext != "m4a") {
return new return_package(1, NULL, "Invalid filetype: '{$filenameext}'");
}
$filefolder = "";
if ($pack->game_id) {
$filefolder = $pack->game_id;
} else {
$filefolder = "players";
}
$fspath = Config::v2_gamedata_folder . "/" . $filefolder . "/" . $newfilename;
$resizedpath = Config::v2_gamedata_folder . "/" . $filefolder . "/" . $resizedfilename;
$fsthumbpath = Config::v2_gamedata_folder . "/" . $filefolder . "/" . $newthumbfilename;
$fp = fopen($fspath, 'w');
if (!$fp) {
return new return_package(1, NULL, "Couldn't open file:{$fspath}");
}
fwrite($fp, base64_decode($pack->data));
fclose($fp);
$did_resize = false;
if ($filenameext == "jpg" || $filenameext == "png" || $filenameext == "gif") {
if (isset($pack->resize)) {
$image = new Imagick($fspath);
// Reorient based on EXIF tag
switch ($image->getImageOrientation()) {
case Imagick::ORIENTATION_UNDEFINED:
// We assume normal orientation
break;
case Imagick::ORIENTATION_TOPLEFT:
// All good
break;
case Imagick::ORIENTATION_TOPRIGHT:
$image->flopImage();
break;
case Imagick::ORIENTATION_BOTTOMRIGHT:
$image->rotateImage('#000', 180);
break;
case Imagick::ORIENTATION_BOTTOMLEFT:
$image->rotateImage('#000', 180);
$image->flopImage();
break;
case Imagick::ORIENTATION_LEFTTOP:
$image->rotateImage('#000', 90);
$image->flopImage();
break;
case Imagick::ORIENTATION_RIGHTTOP:
$image->rotateImage('#000', 90);
break;
case Imagick::ORIENTATION_RIGHTBOTTOM:
$image->rotateImage('#000', -90);
$image->flopImage();
break;
case Imagick::ORIENTATION_LEFTBOTTOM:
$image->rotateImage('#000', -90);
break;
}
$image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
// Resize image proportionally so min(width, height) == $pack->resize
$w = $image->getImageWidth();
$h = $image->getImageHeight();
if ($w < $h) {
$image->resizeImage($pack->resize, $pack->resize / $w * $h, Imagick::FILTER_LANCZOS, 1);
} else {
$image->resizeImage($pack->resize / $h * $w, $pack->resize, Imagick::FILTER_LANCZOS, 1);
}
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(40);
$image->writeImage($resizedpath);
$did_resize = true;
}
$image = new Imagick(isset($pack->resize) ? $resizedpath : $fspath);
//aspect fill to 128x128
$w = $image->getImageWidth();
$h = $image->getImageHeight();
if ($w < $h) {
$image->thumbnailImage(128, 128 / $w * $h, 1, 1);
} else {
$image->thumbnailImage(128 / $h * $w, 128, 1, 1);
}
//crop around center
$w = $image->getImageWidth();
$h = $image->getImageHeight();
$image->cropImage(128, 128, ($w - 128) / 2, ($h - 128) / 2);
$image->writeImage($fsthumbpath);
}
//.........這裏部分代碼省略.........