本文整理汇总了PHP中getImagesize函数的典型用法代码示例。如果您正苦于以下问题:PHP getImagesize函数的具体用法?PHP getImagesize怎么用?PHP getImagesize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getImagesize函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSQLValue
public function getSQLValue($name = '')
{
global $PCRE_RES_REF;
$text = $this->getValue($name);
if (preg_match_all('/href="' . $PCRE_RES_REF . '\\/[\\S]*\\.(jpg|gif|png)+"/', $text, $matches)) {
foreach ($matches[0] as $m) {
$tmp = substr($m, 6, strlen($m) - 7);
$width = 50;
$height = 50;
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $tmp)) {
$size = getImagesize($_SERVER['DOCUMENT_ROOT'] . $tmp);
$width = $size[0];
$height = $size[1];
}
$text = str_replace($m, 'href="#" onClick="newWin(\'' . $tmp . '\',' . $width . ',' . $height . '); return false;"', $text);
}
}
if (preg_match_all('/href="' . $PCRE_RES_REF . '\\/[\\S]*\\.(html)"/', $text, $matches)) {
preg_replace('/onclick=".+; return false;"/', '', $text);
foreach ($matches[0] as $m) {
$tmp = substr($m, 6, strlen($m) - 7);
$width = 640;
$height = 480;
$text = str_replace($m, 'href="#" onClick="newWinHtml(\'' . $tmp . '\',' . $width . ',' . $height . '); return false;"', $text);
}
}
return addslashes(str_replace('&', '&', $text));
}
示例2: getImgSize
function getImgSize()
{
$this->img_info = @getImagesize($this->path);
$this->w = $this->img_info[0];
$this->h = $this->img_info[1];
switch ($this->img_info[2]) {
case 1:
$this->t = 'gif';
break;
case 2:
$this->t = 'jpg';
break;
case 3:
$this->t = 'png';
break;
}
}
示例3: upload_file
/**
* Uploads the file
* @access public
* @params
* $uploaddir : Directory Name in which uploaded file is placed
* $name : file input type field name
* $rename : you may pass string or boolean
true : rename the file if it already exists and returns the renamed file name.
* String : rename the file to given string.
* $replace =true : replace the file if it is already existing
* $file_max_size : file size in bytes. 0 for default
* $check_type : checks file type exp ."(jpg|gif|jpeg)"
* Example upload_file("temp","file",true,true,0,"jpg|jpeg|bmp|gif")
* return : On success it will return file name else return (boolean)false
*/
public function upload_file($uploaddir, $name, $rename = null, $replace = false, $check_type = "")
{
$this->set_file_size($_FILES[$name]['size']);
$this->error = $_FILES[$name]['error'];
$this->set_temp_name($_FILES[$name]['tmp_name']);
$this->set_directory($uploaddir);
$this->check_for_directory();
$this->set_file_name($_FILES[$name]['name']);
$file_size = $this->file_type_info[$check_type]['max_file_size'] / 1000000;
if ($this->error == 1) {
$this->error = sprintf(__("Your file is too large for the web server. The largest file you can upload here is %.1fM. If this is too small, please ask the administrator to increase the <code>upload_max_filesize</code> directive in <code>php.ini</code>."), floatval(parse_file_size_string(ini_get("upload_max_filesize"))) / 1048576.0);
} elseif ($this->error == 3) {
$this->error = __('The uploaded file was only partially uploaded.');
} elseif ($this->error == 4) {
$this->error = __('No file was uploaded');
} elseif (!is_uploaded_file($this->tmp_name)) {
$this->error = "File " . $this->tmp_name . " is not uploaded correctly.";
}
if (empty($this->file_name)) {
$this->error = "File is not uploaded correctly.";
}
if ($this->error != "") {
return false;
}
//check here for valid file
if (!empty($check_type)) {
// set max upload size
if (array_key_exists($check_type, $this->file_type_info)) {
$this->set_max_size($this->file_type_info[$check_type]['max_file_size']);
}
// check file size against maximum
if ($this->file_size > $this->max_filesize) {
$this->error = sprintf(__("File too large; %s file uploads are limited to %s. If this is too small, please ask the administrator to increase the limit."), $check_type, format_file_size($this->max_filesize));
return false;
}
//if $check_type is just image then we can check it via getImagesize() function if the file is valid or not
// does this check always for image
if ($check_type == 'image') {
$sizeCheck = @getImagesize($this->tmp_name);
if (!$sizeCheck) {
$this->error = __("Invalid image file.");
return false;
}
//additional check to see if the image has any extension
$ext = explode('.', $this->file_name);
$ext = strtolower(end($ext));
$img_mime = explode('/', $sizeCheck['mime']);
$img_mime = strtolower(end($img_mime));
//jpeg and jpg may have different extension and mime so handled specially
if ($ext == 'jpg' || $ext == 'jpeg') {
} else {
if ($ext != $img_mime) {
//means there is no image extension so lets add it
$this->file_name .= '.' . $img_mime;
}
}
}
//check for other media types
// can be turned of from config.inc define('CHECK_MIME_TYPE',0);
if ($check_type == 'audio' || $check_type == 'video') {
if (CHECK_MIME_TYPE == 1) {
$mime_type = exec('file -bi ' . $this->tmp_name);
// TO DO:: enalbe for audio/video //application/octet-stream
if (empty($mime_type)) {
$this->error = __("Invalid media file.");
return false;
}
if (strstr($mime_type, $check_type)) {
} else {
if (strstr($mime_type, 'media')) {
} else {
if (strstr($mime_type, 'octet-stream')) {
// Temporarily added for .wav file -- need to do something else
} else {
$this->error = __("Invalid media file.");
return false;
}
}
}
}
}
//special treatment for doc types
if ($check_type == 'doc') {
if (CHECK_MIME_TYPE == 1) {
$mime_type = exec('file -bi ' . $this->tmp_name);
//.........这里部分代码省略.........
示例4: ext_getTSCE_config_image
/**
* [Describe function...]
*
* @param [type] $imgConf: ...
* @return [type] ...
* @todo Define visibility
*/
public function ext_getTSCE_config_image($imgConf)
{
if (substr($imgConf, 0, 4) == 'gfx/') {
$iFile = $this->ext_localGfxPrefix . $imgConf;
$tFile = $this->ext_localWebGfxPrefix . $imgConf;
} elseif (substr($imgConf, 0, 4) == 'EXT:') {
$iFile = GeneralUtility::getFileAbsFileName($imgConf);
if ($iFile) {
$f = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($iFile);
$tFile = $GLOBALS['BACK_PATH'] . '../' . $f;
}
}
$imageInfo = @getImagesize($iFile);
return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
}
示例5: MyDate
}
}
}
$filename = "{$adminid}_" . MyDate("His", $uptime) . mt_rand(100, 999) . $i;
$fs = explode(".", ${"upfile" . $i . "_name"});
$filename = $filename . "." . $fs[count($fs) - 1];
$filename = $savePath . "/" . $filename;
if (!is_dir($cfg_basedir . $savePath)) {
MkdirAll($cfg_basedir . $savePath, 777);
CloseFtp();
}
$fullfilename = $cfg_basedir . $filename;
if ($mediatype == 1) {
@move_uploaded_file(${"upfile" . $i}, $fullfilename);
$info = '';
$data = getImagesize($fullfilename, $info);
$width = $data[0];
$height = $data[1];
if (in_array($upfile_type, $cfg_photo_typenames)) {
WaterImg($fullfilename, 'up');
}
} else {
@move_uploaded_file(${"upfile" . $i}, $fullfilename);
}
if ($i > 1) {
$ntitle = $title . "_" . $i;
} else {
$ntitle = $title;
}
$inquery = "INSERT INTO `#@__uploads`(title,url,mediatype,width,height,playtime,filesize,uptime,mid)\n VALUES ('{$ntitle}','{$filename}','{$mediatype}','{$width}','{$height}','{$playtime}','{$filesize}','{$uptime}','{$adminid}'); ";
$okdd++;
示例6: ext_getTSCE_config_image
/**
* @param string $imgConf
* @return string
*/
public function ext_getTSCE_config_image($imgConf)
{
$iFile = $this->ext_localGfxPrefix . $imgConf;
$tFile = $this->ext_localWebGfxPrefix . $imgConf;
$imageInfo = @getImagesize($iFile);
return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
}
示例7: _parse
/**
* @access protected
*/
function _parse($param = '')
{
$params = explode(" ", $param);
$this->filename = urldecode($params[0]);
if (substr($this->filename, 0, 5) == 'http:' || substr($this->filename, 0, 6) == 'https:') {
$this->fileIsUrl = true;
$fd = fopen($this->filename, "r");
$this->fileIsReadable = $fd !== false ? true : false;
fclose($fd);
} else {
$this->fileIsUrl = false;
$this->fileIsReadable = is_readable($this->filename);
}
if (isset($params[2]) && $params[2] > 0) {
$this->height = $params[2];
}
if (isset($params[1]) && $params[1] > 0) {
$this->width = $params[1];
}
if (isset($params[3]) && $params[3] > 0) {
$this->positionY = $params[3];
}
$_imagesize = getImagesize($this->filename);
if (is_array($_imagesize)) {
$this->imageType = $_imagesize[2];
$this->imageWidth = $_imagesize[0];
$this->imageHeight = $_imagesize[1];
}
}
示例8: ext_getTSCE_config_image
/**
* [Describe function...]
*
* @param [type] $imgConf: ...
* @return [type] ...
*/
function ext_getTSCE_config_image($imgConf)
{
if (substr($imgConf, 0, 4) == 'gfx/') {
$iFile = $this->ext_localGfxPrefix . $imgConf;
$tFile = $this->ext_localWebGfxPrefix . $imgConf;
} elseif (substr($imgConf, 0, 4) == 'EXT:') {
$iFile = t3lib_div::getFileAbsFileName($imgConf);
if ($iFile) {
$f = substr($iFile, strlen(PATH_site));
$tFile = $GLOBALS['BACK_PATH'] . '../' . $f;
}
} else {
$f = 'uploads/tf/' . $this->extractFromResources($this->setup['resources'], $imgConf);
$iFile = PATH_site . $f;
$tFile = $GLOBALS['BACK_PATH'] . '../' . $f;
}
$imageInfo = @getImagesize($iFile);
return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
}
示例9: getImageFunction
/**
* Determine how to process images
*
* Use MIME type of the provided image to detect
* which image handling function to use.This
* increases the performance as compared to i4
* image create from string
*
* @param string $img the path to image upload
* @return array to the specific image-type function to use
*/
private function getImageFunction($tmp)
{
$info = getImagesize($tmp);
switch ($info['mime']) {
case 'image/jpeg':
case 'image/pjpeg':
return array("imagecreatefromjpeg", 'imagejpg');
break;
case 'image/png':
return array("imagecreatefrompng", "imagepng");
break;
case 'image/gif':
return array("imagecreatefromgif", "imagegif");
break;
default:
return FALSE;
break;
}
}
示例10: ext_getTSCE_config_image
/**
* @param string $imgConf
* @return string
*/
public function ext_getTSCE_config_image($imgConf)
{
$iFile = null;
$tFile = null;
if (substr($imgConf, 0, 4) == 'gfx/') {
$iFile = $this->ext_localGfxPrefix . $imgConf;
$tFile = $this->ext_localWebGfxPrefix . $imgConf;
} elseif (substr($imgConf, 0, 4) == 'EXT:') {
$iFile = GeneralUtility::getFileAbsFileName($imgConf);
if ($iFile) {
$tFile = '../' . PathUtility::stripPathSitePrefix($iFile);
}
}
if ($iFile !== null) {
$imageInfo = @getImagesize($iFile);
return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
}
return '';
}
示例11: createThumbnail
/**
* Creates and saves a thumbnail picture.
*/
public function createThumbnail($thumbnailWidth = ATTACHMENT_THUMBNAIL_WIDTH, $thumbnailHeight = ATTACHMENT_THUMBNAIL_HEIGHT, $addSourceInfo = ATTACHMENT_THUMBNAIL_ADD_SOURCE_INFO, $useEmbedded = ATTACHMENT_THUMBNAIL_USE_EMBEDDED)
{
// make thumbnail
$sourceFile = WCF_DIR . 'attachments/attachment-' . $this->attachmentID;
$targetFile = WCF_DIR . 'attachments/thumbnail-' . $this->attachmentID;
$thumbnail = new Thumbnail($sourceFile, $thumbnailWidth, $thumbnailHeight, $addSourceInfo, $this->attachmentName, $useEmbedded);
// get thumbnail
try {
if ($thumbnailData = $thumbnail->makeThumbnail()) {
// save thumbnail
$file = new File($targetFile);
$file->write($thumbnailData);
unset($thumbnailData);
$file->close();
// update database entry
$thumbnailSize = intval(filesize($targetFile));
list($thumbnailWidth, $thumbnailHeight, ) = @getImagesize($targetFile);
$sql = "UPDATE\twcf" . WCF_N . "_attachment\n\t\t\t\t\tSET \tthumbnailType = '" . escapeString($thumbnail->getMimeType()) . "',\n\t\t\t\t\t\tthumbnailSize = " . $thumbnailSize . ",\n\t\t\t\t\t\tthumbnailWidth = " . $thumbnailWidth . ",\n\t\t\t\t\t\tthumbnailHeight = " . $thumbnailHeight . "\n\t\t\t\t\tWHERE \tattachmentID = " . $this->attachmentID;
WCF::getDB()->registerShutdownUpdate($sql);
// update data
$this->data['thumbnailType'] = $thumbnail->getMimeType();
$this->data['thumbnailSize'] = $thumbnailSize;
}
} catch (Exception $e) {
}
}
示例12: fb_image
function fb_image()
{
global $registry;
$image = last_par_url($registry['fbthumb']);
$main_img = $_SERVER['DOCUMENT_ROOT'] . '/img/uploads/news/prev/' . $image . '';
$img = $_SERVER['DOCUMENT_ROOT'] . '/img/uploads/news/fb/' . $image . '';
if (!file_exists($img)) {
$info = getImagesize($main_img);
if ($info['mime'] == 'image/png') {
resizeImagePng($main_img, 472, 246, $img);
} else {
resizeImageJpeg($main_img, 472, 246, $img);
}
}
}
示例13: handleRequest
/**
* Handles a request on the attachment edit form.
* Deletes old or uploads new attachments.
*/
public function handleRequest()
{
// delete uploaded attachments
if (isset($_POST['delete']) && is_array($_POST['delete']) && count($_POST['delete'])) {
// delete selected attachments
$keys = array_keys($_POST['delete']);
$this->delete(intval(array_shift($keys)));
}
// move uploaded attachments
if (isset($_POST['attachmentListPositions']) && is_array($_POST['attachmentListPositions'])) {
$tmpContainerIDArray = count($this->containerIDArray) ? $this->containerIDArray : array(0);
$positionChanged = false;
$positions = ArrayUtil::toIntegerArray($_POST['attachmentListPositions']);
foreach ($positions as $attachmentID => $position) {
$attachmentID = intval($attachmentID);
foreach ($tmpContainerIDArray as $containerID) {
if (isset($this->attachments[$containerID][$attachmentID]) && $this->attachments[$containerID][$attachmentID]->showOrder != $position) {
$this->attachments[$containerID][$attachmentID]->setShowOrder($position);
$positionChanged = true;
}
}
}
if ($positionChanged) {
foreach ($tmpContainerIDArray as $containerID) {
uasort($this->attachments[$containerID], array('self', 'compareAttachments'));
}
}
}
// upload new attachments
$containerID = count($this->containerIDArray) ? reset($this->containerIDArray) : 0;
if (isset($_FILES) && count($_FILES) && isset($_FILES['upload'])) {
// upload new attachments
for ($x = 0, $y = count($_FILES['upload']['name']); $x < $y; $x++) {
$attachmentData = array();
$attachmentData['attachmentName'] = $_FILES['upload']['name'][$x];
if ($attachmentData['attachmentName']) {
$tmpFile = $_FILES['upload']['tmp_name'][$x];
$attachmentData['attachmentSize'] = $_FILES['upload']['size'][$x];
$attachmentData['sha1Hash'] = @sha1_file($tmpFile);
$fileExtension = StringUtil::toLowerCase(StringUtil::substring($attachmentData['attachmentName'], StringUtil::lastIndexOf($attachmentData['attachmentName'], '.') + 1));
$attachmentData['fileType'] = $_FILES['upload']['type'][$x];
$attachmentData['isImage'] = 0;
if (strchr($attachmentData['fileType'], 'image')) {
// check mime
$attachmentData['fileType'] = 'application/octet-stream';
if (($imageData = @getImageSize($tmpFile)) !== false) {
if (strchr($imageData['mime'], 'image')) {
$attachmentData['fileType'] = $imageData['mime'];
if ($attachmentData['fileType'] == 'image/bmp') {
$attachmentData['fileType'] = 'image/x-ms-bmp';
}
$attachmentData['isImage'] = 1;
}
}
}
$attachmentData['showOrder'] = (isset($this->attachments[$containerID]) ? count($this->attachments[$containerID]) : 0) + 1;
if ($this->checkAttachment($tmpFile, $attachmentData['attachmentName'] . ':' . $attachmentData['sha1Hash'], $attachmentData['attachmentName'], $attachmentData['attachmentSize'], $fileExtension, $attachmentData['isImage'])) {
$attachmentData['packageID'] = $this->packageID;
$attachmentData['containerID'] = $containerID;
$attachmentData['containerType'] = $this->containerType;
$attachmentData['idHash'] = $this->idHash;
$attachmentData['userID'] = WCF::getUser()->userID;
$attachmentData['uploadTime'] = TIME_NOW;
$attachmentData['thumbnailType'] = '';
$attachmentData['width'] = $attachmentData['height'] = 0;
if ($attachmentData['isImage']) {
list($width, $height, ) = @getImagesize($tmpFile);
$attachmentData['width'] = $width;
$attachmentData['height'] = $height;
}
// save attachment
if ($attachment = AttachmentEditor::create($tmpFile, $attachmentData)) {
$this->attachmentHashes[count($this->attachmentHashes)] = $attachmentData['attachmentName'] . ':' . $attachmentData['sha1Hash'];
$this->attachments[$containerID][$attachment->attachmentID] = $attachment;
// save thumbnails
if (ATTACHMENT_ENABLE_THUMBNAILS && $attachment->isImage) {
$attachment->createThumbnail($this->thumbnailWidth, $this->thumbnailHeight, $this->addSourceInfo, $this->useEmbedded);
}
}
}
}
}
}
$this->assign();
if (count($this->errors)) {
// throw user exception
throw new UserInputException('attachments', $this->errors);
}
}