本文整理汇总了PHP中imagecreatefromxpm函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecreatefromxpm函数的具体用法?PHP imagecreatefromxpm怎么用?PHP imagecreatefromxpm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecreatefromxpm函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _convertFrameToGif
protected function _convertFrameToGif($frame_path)
{
$gif_path = null;
// first try with imagemagick convert as imagemaigk produces better gifs
if ($this->_config->convert) {
$process = new ProcessBuilder('convert', $this->_config);
$exec = $process->add($frame_path)->add($frame_path . '.convert-convert.gif')->getExecBuffer();
$exec->setBlocking(true)->execute();
if ($exec->hasError() === true) {
throw new Exception('When attempting to convert "' . $frame_path . '" to a gif, convert encountered an error. Convert reported: ' . $exec->getLastLine());
}
$gif_path = $frame_path . '.convert-convert.gif';
}
// if we still have no gif path then try with php gd.
if (empty($gif_path) === true) {
if (function_exists('imagegif') === false) {
throw new Exception('PHP GD\'s function `imagegif` is not available, as a result the frame could not be added.');
}
$im = false;
$data = getimagesize($frame_path);
switch ($data['mime']) {
case 'image/jpeg':
$im = @imagecreatefromjpeg($frame_path);
break;
case 'image/png':
$im = @imagecreatefrompng($frame_path);
break;
case 'image/xbm':
$im = @imagecreatefromwbmp($frame_path);
break;
case 'image/xpm':
$im = @imagecreatefromxpm($frame_path);
break;
}
if ($im === false) {
throw new Exception('Unsupported image type.');
}
// save as a gif
$gif_path = $frame_path . '.convert-php.gif';
if (imagegif($im, $gif_path) === false) {
throw new Exception('Unable to convert frame to gif using PHP GD.');
}
imagedestroy($im);
}
if (empty($gif_path) === true) {
throw new Exception('Unable to convert frame to gif.');
} else {
if (is_file($gif_path) === false) {
throw new Exception('Unable to convert frame to gif, however the gif conversion path was set.');
} else {
if (filesize($gif_path) === 0) {
throw new Exception('Unable to convert frame to gif, as a gif was produced, however it was a zero byte file.');
}
}
}
array_push($this->_tidy_up_gifs, $gif_path);
return $gif_path;
}
示例2: resizeImage
/**
* Resize the image *
*
* @param string $sourceFileName
* @param string $destFileName
* @param number $width
* @param number $height
* @param int $quality <p>
* quality is optional, and ranges from 0 (worst
* quality, smaller file) to 100 (best quality, biggest file). The
* default is the default IJG quality value (about 75).
* </p>
* @return boolean true is success
*/
protected function resizeImage($sourceFileName, $destFileName, $width, $height, $quality)
{
if (!function_exists("imagejpeg")) {
return;
}
if ($width == 0) {
$width = $height;
}
if ($height == 0) {
$height = $width;
}
list($origWidth, $origHeight) = getimagesize($sourceFileName);
$origRatio = $origWidth / $origHeight;
if ($width / $height > $origRatio) {
$width = $height * $origRatio;
} else {
$height = $width / $origRatio;
}
$image_p = imagecreatetruecolor($width, $height);
try {
$image = @imagecreatefromjpeg($sourceFileName);
} catch (Exception $e) {
}
try {
if (!$image) {
$image = @imagecreatefrompng($sourceFileName);
}
} catch (Exception $e) {
}
try {
if (!$image) {
$image = @imagecreatefromgif($sourceFileName);
}
} catch (Exception $e) {
}
try {
if (!$image) {
$image = @imagecreatefromwbmp($sourceFileName);
}
} catch (Exception $e) {
}
try {
if (!$image) {
$image = @imagecreatefromxbm($sourceFileName);
}
} catch (Exception $e) {
}
try {
if (!$image) {
$image = @imagecreatefromxpm($sourceFileName);
}
} catch (Exception $e) {
}
if (!$image) {
return;
}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $origWidth, $origHeight);
return imagejpeg($image_p, $destFileName, $quality);
}
示例3: transformAndCache
/**
* transform source image file (given parameters) and cache result
* @param string $src the url of image (myapp/www/):string.[gif|jpeg|jpg|jpe|xpm|xbm|wbmp|png]
* @param string image's hashname
* @param array $params parameters specifying transformations
**/
protected static function transformAndCache($src, $cacheName, $params)
{
$mimes = array('gif' => 'image/gif', 'png' => 'image/png', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'xpm' => 'image/x-xpixmap', 'xbm' => 'image/x-xbitmap', 'wbmp' => 'image/vnd.wap.wbmp');
global $gJConfig;
$srcUri = 'http' . (empty($_SERVER['HTTPS']) ? '' : 's') . '://' . $_SERVER['HTTP_HOST'] . $gJConfig->urlengine['basePath'] . $src;
$srcFs = JELIX_APP_WWW_PATH . $src;
$path_parts = pathinfo($srcUri);
$mimeType = $mimes[strtolower($path_parts['extension'])];
$quality = !empty($params['quality']) ? $params['quality'] : 100;
// Creating an image
switch ($mimeType) {
case 'image/gif':
$image = imagecreatefromgif($srcFs);
break;
case 'image/jpeg':
$image = imagecreatefromjpeg($srcFs);
break;
case 'image/png':
$image = imagecreatefrompng($srcFs);
break;
case 'image/vnd.wap.wbmp':
$image = imagecreatefromwbmp($srcFs);
break;
case 'image/image/x-xbitmap':
$image = imagecreatefromxbm($srcFs);
break;
case 'image/x-xpixmap':
$image = imagecreatefromxpm($srcFs);
break;
default:
return;
}
if (!empty($params['maxwidth']) && !empty($params['maxheight'])) {
$origWidth = imagesx($image);
$origHeight = imagesy($image);
$constWidth = $params['maxwidth'];
$constHeight = $params['maxheight'];
$ratio = imagesx($image) / imagesy($image);
if ($origWidth < $constWidth && $origHeight < $constHeight) {
$params['width'] = $origWidth;
$params['height'] = $origHeight;
} else {
$ratioHeight = $constWidth / $ratio;
$ratioWidth = $constHeight * $ratio;
if ($ratioWidth > $constWidth) {
$constHeight = $ratioHeight;
} else {
if ($ratioHeight > $constHeight) {
$constWidth = $ratioWidth;
}
}
$params['width'] = $constWidth;
$params['height'] = $constHeight;
}
}
if (!empty($params['width']) || !empty($params['height'])) {
$ancienimage = $image;
$resampleheight = imagesy($ancienimage);
$resamplewidth = imagesx($ancienimage);
$posx = 0;
$posy = 0;
if (empty($params['width'])) {
$finalheight = $params['height'];
$finalwidth = $finalheight * imagesx($ancienimage) / imagesy($ancienimage);
} else {
if (empty($params['height'])) {
$finalwidth = $params['width'];
$finalheight = $finalwidth * imagesy($ancienimage) / imagesx($ancienimage);
} else {
$finalwidth = $params['width'];
$finalheight = $params['height'];
if (!empty($params['omo']) && $params['omo'] == 'true') {
if ($params['width'] >= $params['height']) {
$resampleheight = $resamplewidth * $params['height'] / $params['width'];
} else {
$resamplewidth = $resampleheight * $params['width'] / $params['height'];
}
}
}
}
if (!empty($params['zoom'])) {
$resampleheight /= 100 / $params['zoom'];
$resamplewidth /= 100 / $params['zoom'];
}
$posx = imagesx($ancienimage) / 2 - $resamplewidth / 2;
$posy = imagesy($ancienimage) / 2 - $resampleheight / 2;
if (!empty($params['alignh'])) {
if ($params['alignh'] == 'left') {
$posx = 0;
} else {
if ($params['alignh'] == 'right') {
$posx = -($resamplewidth - imagesx($ancienimage));
} else {
if ($params['alignh'] != 'center') {
//.........这里部分代码省略.........
示例4: createResource
/**
* Returns the GD image resource
*
* @param *string $data The raw image data
* @param *string $path Whether if this raw data is a file path
*
* @return [RESOURCE]
*/
protected function createResource($data, $path)
{
//if the GD Library is not installed
if (!function_exists('gd_info')) {
//throw error
throw ImageException::forGDNotInstalled();
}
# imagecreatefromgd — Create a new image from GD file or URL
# imagecreatefromgif — Create a new image from file or URL
# imagecreatefromjpeg — Create a new image from file or URL
# imagecreatefrompng — Create a new image from file or URL
# imagecreatefromstring — Create a new image from the image stream in the string
# imagecreatefromwbmp — Create a new image from file or URL
# imagecreatefromxbm — Create a new image from file or URL
# imagecreatefromxpm — Create a new image from file or URL
$resource = false;
if (!$path) {
return imagecreatefromstring($data);
}
//depending on the extension lets load
//the file using the right GD loader
switch ($this->type) {
case 'gd':
$resource = imagecreatefromgd($data);
break;
case 'gif':
$resource = imagecreatefromgif($data);
break;
case 'jpg':
case 'jpeg':
case 'pjpeg':
$resource = imagecreatefromjpeg($data);
break;
case 'png':
$resource = imagecreatefrompng($data);
break;
case 'bmp':
case 'wbmp':
$resource = imagecreatefromwbmp($data);
break;
case 'xbm':
$resource = imagecreatefromxbm($data);
break;
case 'xpm':
$resource = imagecreatefromxpm($data);
break;
}
//if there is no resource still
if (!$resource) {
//throw error
ImageException::forInvalidImageFile($path);
}
return $resource;
}
示例5: _getResource
protected function _getResource($data, $path)
{
//if the GD Library is not installed
if (!function_exists('gd_info')) {
//throw error
Eden_Image_Error::i(Eden_Image_Error::GD_NOT_INSTALLED)->trigger();
}
# imagecreatefromgd — Create a new image from GD file or URL
# imagecreatefromgif — Create a new image from file or URL
# imagecreatefromjpeg — Create a new image from file or URL
# imagecreatefrompng — Create a new image from file or URL
# imagecreatefromstring — Create a new image from the image stream in the string
# imagecreatefromwbmp — Create a new image from file or URL
# imagecreatefromxbm — Create a new image from file or URL
# imagecreatefromxpm — Create a new image from file or URL
$resource = false;
if (!$path) {
return imagecreatefromstring($data);
}
//depending on the extension lets load
//the file using the right GD loader
switch ($this->_type) {
case 'gd':
$resource = imagecreatefromgd($data);
break;
case 'gif':
$resource = imagecreatefromgif($data);
break;
case 'jpg':
case 'jpeg':
case 'pjpeg':
$resource = imagecreatefromjpeg($data);
break;
case 'png':
$resource = imagecreatefrompng($data);
break;
case 'bmp':
case 'wbmp':
$resource = imagecreatefromwbmp($data);
break;
case 'xbm':
$resource = imagecreatefromxbm($data);
break;
case 'xpm':
$resource = imagecreatefromxpm($data);
break;
}
//if there is no resource still
if (!$resource) {
//throw error
Eden_Image_Error::i()->setMessage(Eden_Image_Error::NOT_VALID_IMAGE_FILE)->addVariable($path);
}
return $resource;
}
示例6: dirname
<?php
$cwd = dirname(__FILE__);
echo "XPM to PNG conversion: ";
echo imagepng(imagecreatefromxpm($cwd . "/conv_test.xpm"), $cwd . "/test_xpm.png") ? 'ok' : 'failed';
echo "\n";
@unlink($cwd . "/test_xpm.png");
示例7: open
public static function open($file, $type)
{
// @rule: Test for JPG image extensions
if (function_exists('imagecreatefromjpeg') && ($type == 'image/jpg' || $type == 'image/jpeg' || $type == 'image/pjpeg')) {
$im = @imagecreatefromjpeg($file);
if ($im !== false) {
return $im;
}
}
// @rule: Test for png image extensions
if (function_exists('imagecreatefrompng') && ($type == 'image/png' || $type == 'image/x-png')) {
$im = @imagecreatefrompng($file);
if ($im !== false) {
return $im;
}
}
// @rule: Test for png image extensions
if (function_exists('imagecreatefromgif') && $type == 'image/gif') {
$im = @imagecreatefromgif($file);
if ($im !== false) {
return $im;
}
}
if (function_exists('imagecreatefromgd')) {
# GD File:
$im = @imagecreatefromgd($file);
if ($im !== false) {
return true;
}
}
if (function_exists('imagecreatefromgd2')) {
# GD2 File:
$im = @imagecreatefromgd2($file);
if ($im !== false) {
return true;
}
}
if (function_exists('imagecreatefromwbmp')) {
# WBMP:
$im = @imagecreatefromwbmp($file);
if ($im !== false) {
return true;
}
}
if (function_exists('imagecreatefromxbm')) {
# XBM:
$im = @imagecreatefromxbm($file);
if ($im !== false) {
return true;
}
}
if (function_exists('imagecreatefromxpm')) {
# XPM:
$im = @imagecreatefromxpm($file);
if ($im !== false) {
return true;
}
}
// If all failed, this photo is invalid
return false;
}
示例8: open_image
function open_image($file)
{
$im = @imagecreatefromjpeg($file);
if ($im !== false) {
return $im;
}
$im = @imagecreatefromgif($file);
if ($im !== false) {
return $im;
}
$im = @imagecreatefrompng($file);
if ($im !== false) {
return $im;
}
$im = @imagecreatefromgd($file);
if ($im !== false) {
return $im;
}
$im = @imagecreatefromgd2($file);
if ($im !== false) {
return $im;
}
$im = @imagecreatefromwbmp($file);
if ($im !== false) {
return $im;
}
$im = @imagecreatefromxbm($file);
if ($im !== false) {
return $im;
}
$im = @imagecreatefromxpm($file);
if ($im !== false) {
return $im;
}
$im = @imagecreatefromstring(file_get_contents($file));
if ($im !== false) {
return $im;
}
return false;
}
示例9: createFrom
public function createFrom(string $type, string $source, array $settings = NULL)
{
$type = strtolower($type);
switch ($type) {
case 'gd2':
$return = imagecreatefromgd2($source);
break;
case 'gd':
$return = imagecreatefromgd($source);
break;
case 'gif':
$return = imagecreatefromgif($source);
break;
case 'jpeg':
$return = imagecreatefromjpeg($source);
break;
case 'png':
$return = imagecreatefrompng($source);
break;
case 'string':
$return = imagecreatefromstring($source);
break;
case 'wbmp':
$return = imagecreatefromwbmp($source);
break;
case 'webp':
$return = imagecreatefromwebp($source);
break;
case 'xbm':
$return = imagecreatefromxbm($source);
break;
case 'xpm':
$return = imagecreatefromxpm($source);
break;
case 'gd2p':
$return = imagecreatefromgd2part($source, isset($settings['x']) ? $settings['x'] : NULL, isset($settings['y']) ? $settings['y'] : NULL, isset($settings['width']) ? $settings['width'] : NULL, isset($settings['height']) ? $settings['height'] : NULL);
}
return $return;
}
示例10: createFrom
public function createFrom($type = '', $source = '', $x = '', $y = '', $width = '', $height = '')
{
if (!is_string($type) || !is_string($source)) {
return Error::set(lang('Error', 'stringParameter', '1.(type) & 2.(source)'));
}
$type = strtolower($type);
switch ($type) {
case 'gd2':
$return = imagecreatefromgd2($source);
break;
case 'gd':
$return = imagecreatefromgd($source);
break;
case 'gif':
$return = imagecreatefromgif($source);
break;
case 'jpeg':
$return = imagecreatefromjpeg($source);
break;
case 'png':
$return = imagecreatefrompng($source);
break;
case 'string':
$return = imagecreatefromstring($source);
break;
case 'wbmp':
$return = imagecreatefromwbmp($source);
break;
case 'webp':
$return = imagecreatefromwebp($source);
break;
case 'xbm':
$return = imagecreatefromxbm($source);
break;
case 'xpm':
$return = imagecreatefromxpm($source);
break;
case 'gd2p':
$return = imagecreatefromgd2part($source, $x, $y, $width, $height);
}
return $return;
}
示例11: _getResource
protected function _getResource($data, $path)
{
if (!function_exists('gd_info')) {
Eden_Image_Error::i(Eden_Image_Error::GD_NOT_INSTALLED)->trigger();
}
$resource = false;
if (!$path) {
return imagecreatefromstring($data);
}
switch ($this->_type) {
case 'gd':
$resource = imagecreatefromgd($data);
break;
case 'gif':
$resource = imagecreatefromgif($data);
break;
case 'jpg':
case 'jpeg':
case 'pjpeg':
$resource = imagecreatefromjpeg($data);
break;
case 'png':
$resource = imagecreatefrompng($data);
break;
case 'bmp':
case 'wbmp':
$resource = imagecreatefromwbmp($data);
break;
case 'xbm':
$resource = imagecreatefromxbm($data);
break;
case 'xpm':
$resource = imagecreatefromxpm($data);
break;
}
if (!$resource) {
Eden_Image_Error::i()->setMessage(Eden_Image_Error::NOT_VALID_IMAGE_FILE)->addVariable($path);
}
return $resource;
}
示例12: isValid
public static function isValid( $file )
{
require_once(JPATH_SITE.DS.'components'.DS.'com_community'.DS.'libraries'.DS.'core.php');
$config =& CFactory::getConfig();
// Use imagemagick if available
$imageEngine = $config->get('imageengine');
$magickPath = $config->get( 'magickPath' );
if( class_exists('Imagick') && ($imageEngine == 'auto' || $imageEngine == 'imagick' ) )
{
$thumb = new Imagick();
$imageOk = $thumb->readImage($file);
$thumb->destroy();
return $imageOk;
}
else if( !empty( $magickPath ) && !class_exists( 'Imagick' ) )
{
// Execute the command to resize. In windows, the commands are executed differently.
if( JString::strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' )
{
$identifyFile = rtrim( $config->get( 'magickPath' ) , '/' ) . DS . 'identify.exe';
$command = '""' . rtrim( $config->get( 'magickPath' ) , '/' ) . DS . 'identify.exe" -ping "' . $file . '""';
}
else
{
$identifyFile = rtrim( $config->get( 'magickPath' ) , '/' ) . DS . 'identify';
$command = '"' . rtrim( $config->get( 'magickPath' ) , '/' ) . DS . 'identify" -ping "' . $file . '"';
}
if( JFile::exists( $identifyFile ) && function_exists( 'exec') )
{
$output = exec( $command );
// Test if there's any output, otherwise we know the exec failed.
if( !empty( $output ) )
{
return true;
}
}
}
# JPEG:
if( function_exists( 'imagecreatefromjpeg' ) )
{
$im = @imagecreatefromjpeg($file);
if ($im !== false){ return true; }
}
if( function_exists( 'imagecreatefromgif' ) )
{
# GIF:
$im = @imagecreatefromgif($file);
if ($im !== false) { return true; }
}
if( function_exists( 'imagecreatefrompng' ) )
{
# PNG:
$im = @imagecreatefrompng($file);
if ($im !== false) { return true; }
}
if( function_exists( 'imagecreatefromgd' ) )
{
# GD File:
$im = @imagecreatefromgd($file);
if ($im !== false) { return true; }
}
if( function_exists( 'imagecreatefromgd2' ) )
{
# GD2 File:
$im = @imagecreatefromgd2($file);
if ($im !== false) { return true; }
}
if( function_exists( 'imagecreatefromwbmp' ) )
{
# WBMP:
$im = @imagecreatefromwbmp($file);
if ($im !== false) { return true; }
}
if( function_exists( 'imagecreatefromxbm' ) )
{
# XBM:
$im = @imagecreatefromxbm($file);
if ($im !== false) { return true; }
}
if( function_exists( 'imagecreatefromxpm' ) )
{
# XPM:
$im = @imagecreatefromxpm($file);
if ($im !== false) { return true; }
}
//.........这里部分代码省略.........
示例13: create
/**
* Create image ressource from filename.
*
* @param string Path to the image.
* @return void
**/
protected function create($filename)
{
$this->filename = $filename;
// if is not a string, not an existing file or not a file ressource
if (!is_string($this->filename) || !file_exists($this->filename) || !is_file($this->filename)) {
throw new \InvalidArgumentException('Filename is not a valid ressource.');
}
switch (exif_imagetype($this->filename)) {
case IMAGETYPE_GIF:
if (!function_exists('imagecreatefromgif')) {
throw new CapabilityException('GIF is not supported.');
}
$this->image = imagecreatefromgif($this->filename);
break;
case IMAGETYPE_JPEG:
if (!function_exists('imagecreatefromjpeg')) {
throw new CapabilityException('JPEG is not supported.');
}
$this->image = imagecreatefromjpeg($this->filename);
break;
case IMAGETYPE_PNG:
if (!function_exists('imagecreatefrompng')) {
throw new CapabilityException('PNG is not supported.');
}
$this->image = imagecreatefrompng($this->filename);
break;
case IMAGETYPE_WBMP:
if (!function_exists('imagecreatefromwbmp')) {
throw new CapabilityException('WBMP is not supported.');
}
$this->image = imagecreatefromwbmp($this->filename);
break;
// Not supported yet in PHP 5.5. WebP is supported since in PHP 5.5 (https://bugs.php.net/bug.php?id=65038)
// Not supported yet in PHP 5.5. WebP is supported since in PHP 5.5 (https://bugs.php.net/bug.php?id=65038)
case defined('IMAGETYPE_WEBP') && IMAGETYPE_WEBP:
if (!function_exists('imagecreatefromwebp')) {
throw new CapabilityException('WebP is not supported.');
}
$this->image = imagecreatefromwebp($this->filename);
break;
case IMAGETYPE_XBM:
if (!function_exists('imagecreatefromxbm')) {
throw new CapabilityException('XBM is not supported.');
}
$this->image = imagecreatefromxbm($this->filename);
break;
case defined('IMAGETYPE_WEBP') && IMAGETYPE_XPM:
if (!function_exists('imagecreatefromxpm')) {
throw new CapabilityException('XPM is not supported.');
}
$this->image = imagecreatefromxpm($this->filename);
break;
default:
throw new CapabilityException('Unsupported input file type.');
break;
}
$this->setWidth(imagesx($this->image));
$this->setHeight(imagesy($this->image));
}
示例14: showThumb
function showThumb($src, $thumbWidth, $thumbHeight, $dest = "")
{
$info = pathinfo($src);
// load image and get image size
//$src = str_replace("%20", "", $src);
//$src = "http://google.com";
//echo file_get_contents($src);
//exit();
if (strpos($src, "http://" . $_SERVER['HTTP_HOST'] . "/media/") === 0) {
$p = urldecode($_GET['p']);
$src = str_replace("http://" . $_SERVER['HTTP_HOST'] . "/media/", dirname(__FILE__) . "/", $p);
}
if ($_GET['showsrc']) {
echo $src;
exit;
}
$img = @imagecreatefromjpeg($src);
if (!$img) {
$img = @imagecreatefrompng($src);
}
if (!$img) {
$img = @imagecreatefromgif($src);
}
if (!$img) {
$img = @imagecreatefromwbmp($src);
}
if (!$img) {
$img = @imagecreatefromgd2($src);
}
if (!$img) {
$img = @imagecreatefromgd2part($src);
}
if (!$img) {
$img = @imagecreatefromgd($src);
}
if (!$img) {
$img = @imagecreatefromstring($src);
}
if (!$img) {
$img = @imagecreatefromxbm($src);
}
if (!$img) {
$img = @imagecreatefromxpm($src);
}
if (!$img) {
return false;
}
$width = imagesx($img);
$height = imagesy($img);
$new_width = $width;
$new_height = $height;
// calculate thumbnail size
if ($width > $height) {
if ($thumbWidth < $width) {
$new_width = $thumbWidth;
$new_height = floor($height * ($thumbWidth / $width));
}
} else {
if ($thumbHeight < $height) {
$new_height = $thumbHeight;
$new_width = floor($width * ($thumbHeight / $height));
}
}
if ($_GET['square']) {
if ($new_width > $new_height) {
$side = $new_width;
} else {
$side = $new_height;
}
$tmp_img = imagecreatetruecolor($side, $side);
$white = imagecolorallocate($tmp_img, 255, 255, 255);
imagefill($tmp_img, 0, 0, $white);
imagecopyresampled($tmp_img, $img, ($side - $new_width) / 2, ($side - $new_height) / 2, 0, 0, $new_width, $new_height, $width, $height);
} else {
// create a new temporary image
$tmp_img = imagecreatetruecolor($new_width, $new_height);
$white = imagecolorallocate($tmp_img, 255, 255, 255);
imagefill($tmp_img, 0, 0, $white);
// copy and resize old image into new image
imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
}
if (!trim($dest)) {
imagepng($tmp_img, null, 0);
} else {
@imagepng($tmp_img, $dest, 0);
imagepng($tmp_img, null, 0);
}
// save thumbnail into a file
}
示例15: loaddata
function loaddata()
{
$tmp = explode(".", $this->filename);
$ext = strtolower($tmp[count($tmp) - 1]);
switch ($ext) {
case "bmp":
die("Windows BitMaP file not supported.");
break;
case "gif":
$img = imagecreatefromgif($this->filename);
break;
case "jpg":
case "jpeg":
$img = imagecreatefromjpeg($this->filename);
break;
case "png":
$img = imagecreatefrompng($this->filename);
break;
case "xbm":
$img = imagecreatefromxbm($this->filename);
break;
case "xpm":
$img = imagecreatefromxpm($this->filename);
break;
default:
die("Invalid / unknown filetype (extension).");
break;
}
$this->imagewidth = imagesx($img);
$this->imageheight = imagesy($img);
$y = $this->imageheight;
while ($y > 0) {
$y--;
$this->scanimgline($img, $y, $this->imagewidth, $this->bgcolorrgb);
}
imagedestroy($img);
}