本文整理汇总了PHP中ImageCreateFromString函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageCreateFromString函数的具体用法?PHP ImageCreateFromString怎么用?PHP ImageCreateFromString使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ImageCreateFromString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: copyFromUrl
public static function copyFromUrl($url, $target)
{
if (!@copy($url, $target)) {
$http = new JO_Http();
$http->useCurl(true);
if (($host = JO_Validate::validateHost($url)) !== false) {
$http->setReferrer('http://' . $host);
}
$http->execute($url);
if ($http->error) {
return false;
} else {
$im = @ImageCreateFromString($http->result);
if (!$im) {
return false;
}
return @file_put_contents($target, $im);
}
} else {
return true;
}
}
示例2: getimagesize_remote
function getimagesize_remote($image_url)
{
$handle = fopen($image_url, "rb");
$contents = '';
if ($handle) {
do {
$count += 1;
$data = fread($handle, 8192);
if (strlen($data) == 0) {
break;
}
$contents .= $data;
} while (true);
} else {
return false;
}
fclose($handle);
$im = ImageCreateFromString($contents);
if (!$im) {
return false;
}
$gis[0] = ImageSX($im);
$gis[1] = ImageSY($im);
$gis[3] = "width={$gis[0]} height={$gis[1]}";
ImageDestroy($im);
return $gis;
}
示例3: getimagesize_remote
function getimagesize_remote($image_url)
{
if (($handle = @fopen($image_url, "rb")) != true) {
return;
}
$contents = "";
$count = 0;
if ($handle) {
do {
$count += 1;
$data = fread($handle, 8192);
if (strlen($data) == 0) {
break;
}
$contents .= $data;
} while (true);
} else {
return false;
}
fclose($handle);
$im = ImageCreateFromString($contents);
if (!$im) {
return false;
}
$gis[0] = ImageSX($im);
$gis[1] = ImageSY($im);
// array member 3 is used below to keep with current getimagesize standards
$gis[3] = "width={$gis[0]} height={$gis[1]}";
ImageDestroy($im);
return $gis;
}
示例4: loadImageFromString
function loadImageFromString($string)
{
$this->_imgOrig = @ImageCreateFromString($string);
if (!$this->_imgOrig) {
$this->_debug('loadImageFromString', 'The image could not be loaded.');
return false;
}
return true;
}
示例5: Error
function Error()
{
header('Content-Type: image/gif');
header('Content-Disposition: inline; filename="fakeapple.gif"');
$blank = 'R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
// A transparent 1x1 GIF image
$image = ImageCreateFromString(base64_decode($blank));
ImageGif($image);
ImageDestroy($image);
die;
}
示例6: getImage
public function getImage($objUser)
{
$img = ImageCreateFromString(base64_decode($this->getFrom('imagedata', 'data')));
$objPicture = new clsPicture($this->get('picture_id'));
if (!$objPicture->hasViewed($objUser)) {
$newImage = clsThumbnail::getNewImage();
list($newWidth, $newHeight) = clsThumbnail::getNewSize();
ImageCopyMerge($img, $newImage, $this->get('actual_width') - $newWidth, $this->get('actual_height') - $newHeight, 0, 0, $newWidth, $newHeight, 75);
ImageDestroy($newImage);
}
return $img;
}
示例7: dissimilarityIndexCalculator
function dissimilarityIndexCalculator($str_img, $str_match)
{
//Try to make images from the urls, on fail return false.
$img_source = @ImageCreateFromString($str_img);
$img_match = @ImageCreateFromString($str_match);
if (!$img_source || !$img_match) {
return false;
}
//Get image sizes.
//list($int_img_source_width, $int_img_source_height) = getimagesizefromstring ($str_img);
//list($int_img_match_width, $int_img_match_height) = getimagesizefromstring ($str_match);
$int_img_source_width = imagesx($img_source);
$int_img_source_height = imagesy($img_source);
$int_img_match_width = imagesx($img_match);
$int_img_match_height = imagesy($img_match);
//Resample to 16px each
$compareSize = 16;
$img_16source = imagecreatetruecolor($compareSize, $compareSize);
$bg = imagecolorallocate($img_16source, 96, 96, 96);
imagefilledrectangle($img_16source, 0, 0, $compareSize, $compareSize, $bg);
$img_16match = imagecreatetruecolor($compareSize, $compareSize);
$bg = imagecolorallocate($img_16match, 96, 96, 96);
imagefilledrectangle($img_16match, 0, 0, $compareSize, $compareSize, $bg);
imagecopyresampled($img_16source, $img_source, 0, 0, 0, 0, $compareSize, $compareSize, $int_img_source_width, $int_img_source_width);
imagecopyresampled($img_16match, $img_match, 0, 0, 0, 0, $compareSize, $compareSize, $int_img_match_width, $int_img_match_width);
$difference = 0;
for ($x = 0; $x < $compareSize; $x++) {
for ($y = 0; $y < $compareSize; $y++) {
//Get the color of the resulting image
$arr_img_source_color[$x][$y] = imagecolorsforindex($img_16source, imagecolorat($img_16source, $x, $y));
$arr_img_match_color[$x][$y] = imagecolorsforindex($img_16match, imagecolorat($img_16match, $x, $y));
//Calculate the index
$difference += abs($arr_img_source_color[$x][$y]['red'] - $arr_img_match_color[$x][$y]['red']) + abs($arr_img_source_color[$x][$y]['green'] - $arr_img_match_color[$x][$y]['green']) + abs($arr_img_source_color[$x][$y]['blue'] - $arr_img_match_color[$x][$y]['blue']) + abs($arr_img_source_color[$x][$y]['alpha'] - $arr_img_match_color[$x][$y]['alpha']);
//error_log("[$x,$y], " . $arr_img_source_color[$x][$y]['red'] . ', ' . $arr_img_match_color[$x][$y]['red']);
}
}
$difference = $difference / 256;
//Return an array with the information
$arr_return = array("dissimilarityIndex" => $difference, "sourceImage" => array("width" => $int_img_source_width, "height" => $int_img_source_height), "matchImage" => array("width" => $int_img_match_width, "height" => $int_img_match_height));
/*
imagepng($img_16source, "temp/left-{$compareSize}px.png");
imagepng($img_16match, "temp/right-{$compareSize}px.png");
// */
return $arr_return;
}
示例8: create
function create($data)
{
$this->destroy();
if (file_exists($data)) {
$this->img = @ImageCreateFromJpeg($data);
$this->fileInfo = basename($data);
$this->fullName = $data;
} else {
$this->img = @ImageCreateFromString($data);
}
if (!$this->img) {
$this->destroy();
return false;
} else {
$this->orgX = ImageSX($this->img);
$this->orgY = ImageSY($this->img);
return true;
}
}
示例9: testThisDoesNotWorkAsExpected
function testThisDoesNotWorkAsExpected()
{
$scale = 0.75;
$input_jpeg = new PelJpeg($this->file);
$original = ImageCreateFromString($input_jpeg->getBytes());
$original_w = ImagesX($original);
$original_h = ImagesY($original);
$scaled_w = $original_w * $scale;
$scaled_h = $original_h * $scale;
$scaled = ImageCreateTrueColor($scaled_w, $scaled_h);
ImageCopyResampled($scaled, $original, 0, 0, 0, 0, $scaled_w, $scaled_h, $original_w, $original_h);
$output_jpeg = new PelJpeg($scaled);
$exif = $input_jpeg->getExif();
if ($exif !== null) {
$output_jpeg->setExif($exif);
}
file_put_contents($this->file, $output_jpeg->getBytes());
$jpeg = new PelJpeg($this->file);
$exifin = $jpeg->getExif();
$this->assertEquals($exif, $exifin);
}
示例10: dissimilarityIndexCalculator
function dissimilarityIndexCalculator($str_img, $str_match)
{
//Try to make images from the urls, on fail return false.
$img_source = @ImageCreateFromString($str_img);
$img_match = @ImageCreateFromString($str_match);
if (!$img_source || !$img_match) {
return false;
}
//Get image sizes.
//list($int_img_source_width, $int_img_source_height) = getimagesizefromstring ($str_img);
//list($int_img_match_width, $int_img_match_height) = getimagesizefromstring ($str_match);
$int_img_source_width = imagesx($img_source);
$int_img_source_height = imagesy($img_source);
$int_img_match_width = imagesx($img_match);
$int_img_match_height = imagesy($img_match);
//Resample to 16px each
$img_16source = imagecreatetruecolor(16, 16);
$img_16match = imagecreatetruecolor(16, 16);
imagecopyresampled($img_16source, $img_source, 0, 0, 0, 0, 16, 16, $int_img_source_width, $int_img_source_width);
imagecopyresampled($img_16match, $img_match, 0, 0, 0, 0, 16, 16, $int_img_match_width, $int_img_match_width);
$difference = 0;
for ($x = 0; $x < 16; $x++) {
for ($y = 0; $y < 16; $y++) {
//Get the color of the resulting image
$arr_img_source_color[$x][$y] = imagecolorsforindex($img_16source, imagecolorat($img_16source, $x, $y));
$arr_img_match_color[$x][$y] = imagecolorsforindex($img_16match, imagecolorat($img_16match, $x, $y));
//Calculate the index
//echo $arr_img_source_color[$x][$y]['red'] ." - ". $arr_img_match_color['red'] ."\n";
$difference += abs($arr_img_source_color[$x][$y]['red'] - $arr_img_match_color[$x][$y]['red']) + abs($arr_img_source_color[$x][$y]['green'] - $arr_img_match_color[$x][$y]['green']) + abs($arr_img_source_color[$x][$y]['blue'] - $arr_img_match_color[$x][$y]['blue']);
}
}
$difference = $difference / 256;
//Return an array with the information
$arr_return = array("dissimilarityIndex" => $difference, "sourceImage" => array("width" => $int_img_source_width, "height" => $int_img_source_height), "matchImage" => array("width" => $int_img_match_width, "height" => $int_img_match_height));
return $arr_return;
}
示例11: ImageCreateFromStringReplacement
function ImageCreateFromStringReplacement(&$RawImageData, $DieOnErrors = false)
{
// there are serious bugs in the non-bundled versions of GD which may cause
// PHP to segfault when calling ImageCreateFromString() - avoid if at all possible
// when not using a bundled version of GD2
if (!phpthumb_functions::gd_version()) {
if ($DieOnErrors) {
if (!headers_sent()) {
// base64-encoded error image in GIF format
$ERROR_NOGD = 'R0lGODlhIAAgALMAAAAAABQUFCQkJDY2NkZGRldXV2ZmZnJycoaGhpSUlKWlpbe3t8XFxdXV1eTk5P7+/iwAAAAAIAAgAAAE/vDJSau9WILtTAACUinDNijZtAHfCojS4W5H+qxD8xibIDE9h0OwWaRWDIljJSkUJYsN4bihMB8th3IToAKs1VtYM75cyV8sZ8vygtOE5yMKmGbO4jRdICQCjHdlZzwzNW4qZSQmKDaNjhUMBX4BBAlmMywFSRWEmAI6b5gAlhNxokGhooAIK5o/pi9vEw4Lfj4OLTAUpj6IabMtCwlSFw0DCKBoFqwAB04AjI54PyZ+yY3TD0ss2YcVmN/gvpcu4TOyFivWqYJlbAHPpOntvxNAACcmGHjZzAZqzSzcq5fNjxFmAFw9iFRunD1epU6tsIPmFCAJnWYE0FURk7wJDA0MTKpEzoWAAskiAAA7';
header('Content-Type: image/gif');
echo base64_decode($ERROR_NOGD);
} else {
echo '*** ERROR: No PHP-GD support available ***';
}
exit;
} else {
$this->DebugMessage('ImageCreateFromStringReplacement() failed: gd_version says "' . phpthumb_functions::gd_version() . '"', __FILE__, __LINE__);
return false;
}
}
if (phpthumb_functions::gd_is_bundled()) {
$this->DebugMessage('ImageCreateFromStringReplacement() calling built-in ImageCreateFromString()', __FILE__, __LINE__);
return @ImageCreateFromString($RawImageData);
}
if ($this->issafemode) {
$this->DebugMessage('ImageCreateFromStringReplacement() failed: cannot create temp file in SAFE_MODE', __FILE__, __LINE__);
return false;
}
switch (substr($RawImageData, 0, 3)) {
case 'GIF':
$ICFSreplacementFunctionName = 'ImageCreateFromGIF';
break;
case "ÿØÿ":
$ICFSreplacementFunctionName = 'ImageCreateFromJPEG';
break;
case "‰" . 'PN':
$ICFSreplacementFunctionName = 'ImageCreateFromPNG';
break;
default:
$this->DebugMessage('ImageCreateFromStringReplacement() failed: unknown fileformat signature "' . phpthumb_functions::HexCharDisplay(substr($RawImageData, 0, 3)) . '"', __FILE__, __LINE__);
return false;
break;
}
if ($tempnam = $this->phpThumb_tempnam()) {
if ($fp_tempnam = @fopen($tempnam, 'wb')) {
fwrite($fp_tempnam, $RawImageData);
fclose($fp_tempnam);
if ($ICFSreplacementFunctionName == 'ImageCreateFromGIF' && !function_exists($ICFSreplacementFunctionName)) {
// Need to create from GIF file, but ImageCreateFromGIF does not exist
ob_start();
if (!@(include_once dirname(__FILE__) . '/phpthumb.gif.php')) {
$ErrorMessage = 'Failed to include required file "' . dirname(__FILE__) . '/phpthumb.gif.php" in ' . __FILE__ . ' on line ' . __LINE__;
$this->DebugMessage($ErrorMessage, __FILE__, __LINE__);
}
ob_end_clean();
// gif_loadFileToGDimageResource() cannot read from raw data, write to file first
if ($tempfilename = $this->phpThumb_tempnam()) {
if ($fp_tempfile = @fopen($tempfilename, 'wb')) {
fwrite($fp_tempfile, $RawImageData);
fclose($fp_tempfile);
$gdimg_source = gif_loadFileToGDimageResource($tempfilename);
$this->DebugMessage('gif_loadFileToGDimageResource(' . $tempfilename . ') completed', __FILE__, __LINE__);
$this->DebugMessage('deleting "' . $tempfilename . '"', __FILE__, __LINE__);
unlink($tempfilename);
return $gdimg_source;
// break;
} else {
$ErrorMessage = 'Failed to open tempfile in ' . __FILE__ . ' on line ' . __LINE__;
$this->DebugMessage($ErrorMessage, __FILE__, __LINE__);
}
} else {
$ErrorMessage = 'Failed to open generate tempfile name in ' . __FILE__ . ' on line ' . __LINE__;
$this->DebugMessage($ErrorMessage, __FILE__, __LINE__);
}
} elseif (function_exists($ICFSreplacementFunctionName) && ($gdimg_source = @$ICFSreplacementFunctionName($tempnam))) {
// great
$this->DebugMessage($ICFSreplacementFunctionName . '(' . $tempnam . ') succeeded', __FILE__, __LINE__);
$this->DebugMessage('deleting "' . $tempnam . '"', __FILE__, __LINE__);
unlink($tempnam);
return $gdimg_source;
} else {
// GD functions not available, or failed to create image
$this->DebugMessage($ICFSreplacementFunctionName . '(' . $tempnam . ') ' . (function_exists($ICFSreplacementFunctionName) ? 'failed' : 'does not exist'), __FILE__, __LINE__);
if (isset($_GET['phpThumbDebug'])) {
$this->phpThumbDebug();
}
}
} else {
$ErrorMessage = 'Failed to fopen(' . $tempnam . ', "wb") in ' . __FILE__ . ' on line ' . __LINE__ . "\n" . 'You may need to set $PHPTHUMB_CONFIG[temp_directory] in phpThumb.config.php';
if ($this->issafemode) {
$ErrorMessage = 'ImageCreateFromStringReplacement() failed in ' . __FILE__ . ' on line ' . __LINE__ . ': cannot create temp file in SAFE_MODE';
}
$this->DebugMessage($ErrorMessage, __FILE__, __LINE__);
}
$this->DebugMessage('deleting "' . $tempnam . '"', __FILE__, __LINE__);
@unlink($tempnam);
} else {
$ErrorMessage = 'Failed to generate phpThumb_tempnam() in ' . __FILE__ . ' on line ' . __LINE__ . "\n" . 'You may need to set $PHPTHUMB_CONFIG[temp_directory] in phpThumb.config.php';
if ($this->issafemode) {
//.........这里部分代码省略.........
示例12: calculate_image_luminance
function calculate_image_luminance($image_url)
{
if (!function_exists('ImageCreateFromString')) {
return 1;
}
// Get original image dimensions
$size = getimagesize($image_url);
// Create image resource from source image
$image = ImageCreateFromString(file_get_contents($image_url));
// Allocate image resource
$sample = ImageCreateTrueColor(1, 1);
// Flood fill with a white background (to properly calculate luminance of PNGs with alpha)
ImageFill($sample, 0, 0, ImageColorAllocate($sample, 255, 255, 255));
// Downsample to 1x1 image
ImageCopyResampled($sample, $image, 0, 0, 0, 0, 1, 1, $size[0], $size[1]);
// Get the RGB value of the pixel
$rgb = ImageColorAt($sample, 0, 0);
$red = $rgb >> 16 & 0xff;
$green = $rgb >> 8 & 0xff;
$blue = $rgb & 0xff;
// Calculate relative luminance value (https://en.wikipedia.org/wiki/Relative_luminance)
return 0.2126 * $red + 0.7151999999999999 * $green + 0.0722 * $blue;
}
示例13: createImage
/**
* 根据文件名和类型创建图片
*
* @param string $type 图片的类型,包括gif,jpg,png
* @param string $img_name 图片文件名,包括路径名,例如 " ./mouse.jpg"
* @return string 字符串类型的返回结果
*/
private function createImage($type, $img_name)
{
if (!$type) {
$type = $this->get_type($img_name);
}
switch ($type) {
case 'gif':
if (function_exists('imagecreatefromgif')) {
$tmp_img = @ImageCreateFromGIF($img_name);
}
break;
case 'jpg':
$tmp_img = ImageCreateFromJPEG($img_name);
break;
case 'jpeg':
$tmp_img = ImageCreateFromJPEG($img_name);
break;
case 'png':
$tmp_img = ImageCreateFromPNG($img_name);
break;
default:
$tmp_img = ImageCreateFromString($img_name);
break;
}
return $tmp_img;
}
示例14: getImage
public function getImage($objUser)
{
return ImageCreateFromString(base64_decode($this->getFrom('imagedata', 'data')));
}
示例15: thumbnail
function thumbnail($url, $filename, $width = 120, $height = true)
{
// download and create gd image
$image = ImageCreateFromString(file_get_contents($url));
// calculate resized ratio
// Note: if $height is set to TRUE then we automatically calculate the height based on the ratio
$height = $height === true ? ImageSY($image) * $width / ImageSX($image) : $height;
// create image
$output = ImageCreateTrueColor($width, $height);
ImageCopyResampled($output, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
// save image
ImageJPEG($output, $filename, 95);
// return resized image
return $output;
// if you need to use it
}