| Server IP : 104.21.31.197 / Your IP : 162.159.108.70 Web Server : nginx/1.20.2 System : Linux 172-104-110-161.ip.linodeusercontent.com 3.10.0-1160.36.2.el7.x86_64 #1 SMP Wed Jul 21 11:57:15 UTC 2021 x86_64 User : www ( 1000) PHP Version : 8.1.9 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /www/wwwroot/specs.drivers-asus.com/framework-4.1.3/system/Images/ |
Upload File : |
<?php
/**
* This file is part of the CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CodeIgniter\Images;
use CodeIgniter\Files\File;
use CodeIgniter\Images\Exceptions\ImageException;
/**
* Encapsulation of an Image file
*/
class Image extends File
{
/**
* The original image width in pixels.
*
* @var integer|float
*/
public $origWidth;
/**
* The original image height in pixels.
*
* @var integer|float
*/
public $origHeight;
/**
* The image type constant.
*
* @see http://php.net/manual/en/image.constants.php
*
* @var integer
*/
public $imageType;
/**
* attributes string with size info:
* 'height="100" width="200"'
*
* @var string
*/
public $sizeStr;
/**
* The image's mime type, i.e. image/jpeg
*
* @var string
*/
public $mime;
/**
* Makes a copy of itself to the new location. If no filename is provided
* it will use the existing filename.
*
* @param string $targetPath The directory to store the file in
* @param string|null $targetName The new name of the copied file.
* @param integer $perms File permissions to be applied after copy.
*
* @return boolean
*/
public function copy(string $targetPath, string $targetName = null, int $perms = 0644): bool
{
$targetPath = rtrim($targetPath, '/ ') . '/';
$targetName = is_null($targetName) ? $this->getFilename() : $targetName;
if (empty($targetName))
{
throw ImageException::forInvalidFile($targetName);
}
if (! is_dir($targetPath))
{
mkdir($targetPath, 0755, true);
}
if (! copy($this->getPathname(), "{$targetPath}{$targetName}"))
{
throw ImageException::forCopyError($targetPath);
}
chmod("{$targetPath}/{$targetName}", $perms);
return true;
}
//--------------------------------------------------------------------
/**
* Get image properties
*
* A helper function that gets info about the file
*
* @param boolean $return
*
* @return array|boolean
*/
public function getProperties(bool $return = false)
{
$path = $this->getPathname();
if (! $vals = getimagesize($path))
{
throw ImageException::forFileNotSupported();
}
$types = [
IMAGETYPE_GIF => 'gif',
IMAGETYPE_JPEG => 'jpeg',
IMAGETYPE_PNG => 'png',
IMAGETYPE_WEBP => 'webp',
];
$mime = 'image/' . ($types[$vals[2]] ?? 'jpg');
if ($return === true)
{
return [
'width' => $vals[0],
'height' => $vals[1],
'image_type' => $vals[2],
'size_str' => $vals[3],
'mime_type' => $mime,
];
}
$this->origWidth = $vals[0];
$this->origHeight = $vals[1];
$this->imageType = $vals[2];
$this->sizeStr = $vals[3];
$this->mime = $mime;
return true;
}
//--------------------------------------------------------------------
}