本文整理汇总了PHP中image::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP image::factory方法的具体用法?PHP image::factory怎么用?PHP image::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image
的用法示例。
在下文中一共展示了image::factory方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkFile
public function checkFile($file, array $config)
{
$driver = isset($config['imageDriversPriority']) ? image::getDriver(explode(" ", $config['imageDriversPriority'])) : "gd";
$img = image::factory($driver, $file);
if ($img->initError) {
return "Unknown image format/encoding.";
}
return true;
}
示例2: makeThumb
protected function makeThumb($file, $overwrite = true)
{
$img = image::factory($this->imageDriver, $file);
// Drop files which are not images
if ($img->initError) {
return true;
}
$fimg = new fastImage($file);
$type = $fimg->getType();
$fimg->close();
if ($type === false) {
return true;
}
$thumb = substr($file, strlen($this->config['uploadDir']));
$thumb = $this->config['uploadDir'] . "/" . $this->config['thumbsDir'] . "/" . $thumb;
$thumb = path::normalize($thumb);
$thumbDir = dirname($thumb);
if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) {
return false;
}
if (!$overwrite && is_file($thumb)) {
return true;
}
// Images with smaller resolutions than thumbnails
if ($img->width <= $this->config['thumbWidth'] && $img->height <= $this->config['thumbHeight']) {
// Drop only browsable types
if (in_array($type, array("gif", "jpeg", "png"))) {
return true;
}
// Resize image
} elseif (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight'])) {
return false;
}
// Save thumbnail
$options = array('file' => $thumb);
if ($type == "gif") {
$type = "jpeg";
}
if ($type == "jpeg") {
$options['quality'] = $this->config['jpegQuality'];
}
return $img->output($type, $options);
}
示例3: makeThumb
protected function makeThumb($file, $overwrite = true)
{
$img = image::factory($this->imageDriver, $file);
// Drop files which are not images
if ($img->initError) {
return true;
}
$thumb = substr($file, strlen($this->config['uploadDir']));
$thumb = $this->config['uploadDir'] . "/" . $this->config['thumbsDir'] . "/" . $thumb;
$thumb = path::normalize($thumb);
$thumbDir = dirname($thumb);
if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) {
return false;
}
if (!$overwrite && is_file($thumb)) {
return true;
}
// Images with smaller resolutions than thumbnails
if ($img->width <= $this->config['thumbWidth'] && $img->height <= $this->config['thumbHeight']) {
list($tmp, $tmp, $type) = @getimagesize($file);
// Drop only browsable types
if (in_array($type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
return true;
}
// Resize image
} elseif (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight'])) {
return false;
}
// Save thumbnail
return $img->output("jpeg", array('file' => $thumb, 'quality' => $this->config['jpegQuality']));
}
示例4: act_thumb
protected function act_thumb()
{
$this->getDir($this->get['dir'], true);
if (!isset($this->get['file']) || !isset($this->get['dir'])) {
$this->sendDefaultThumb();
}
$file = $this->get['file'];
if (basename($file) != $file) {
$this->sendDefaultThumb();
}
$file = "{$this->thumbsDir}/{$this->type}/{$this->get['dir']}/{$file}";
if (!is_file($file) || !is_readable($file)) {
$file = "{$this->config['uploadDir']}/{$this->type}/{$this->get['dir']}/" . basename($file);
if (!is_file($file) || !is_readable($file)) {
$this->sendDefaultThumb($file);
}
$image = image::factory($this->imageDriver, $file);
if ($image->initError) {
$this->sendDefaultThumb($file);
}
list($tmp, $tmp, $type) = getimagesize($file);
if (in_array($type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)) && $image->width <= $this->config['thumbWidth'] && $image->height <= $this->config['thumbHeight']) {
$mime = $type == IMAGETYPE_GIF ? "gif" : ($type == IMAGETYPE_PNG ? "png" : "jpeg");
$mime = "image/{$mime}";
httpCache::file($file, $mime);
} else {
$this->sendDefaultThumb($file);
}
}
httpCache::file($file, "image/jpeg");
}
示例5: act_thumb
protected function act_thumb()
{
if (!isset($_GET['file']) || !isset($_GET['dir']) || !$this->checkFilename($_GET['file'])) {
$this->sendDefaultThumb();
}
$dir = $this->getDir();
$file = "{$this->thumbsTypeDir}/{$_GET['dir']}/{$_GET['file']}";
// Create thumbnail
if (!is_file($file) || !is_readable($file)) {
$file = "{$dir}/{$_GET['file']}";
if (!is_file($file) || !is_readable($file)) {
$this->sendDefaultThumb($file);
}
$image = image::factory($this->imageDriver, $file);
if ($image->initError) {
$this->sendDefaultThumb($file);
}
$img = new fastImage($file);
$type = $img->getType();
$img->close();
if (in_array($type, array("gif", "jpeg", "png")) && $image->width <= $this->config['thumbWidth'] && $image->height <= $this->config['thumbHeight']) {
$mime = "image/{$type}";
httpCache::file($file, $mime);
} else {
$this->sendDefaultThumb($file);
}
// Get type from already-existing thumbnail
} else {
$img = new fastImage($file);
$type = $img->getType();
$img->close();
}
httpCache::file($file, "image/{$type}");
}