本文整理匯總了PHP中Imagick::readimageblob方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::readimageblob方法的具體用法?PHP Imagick::readimageblob怎麽用?PHP Imagick::readimageblob使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::readimageblob方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testImageWorkingType
public function testImageWorkingType()
{
$file100 = Kwf_Media::getOutput('Kwc_ImageResponsive_MediaOutput_Image_TestComponent', 'root_imageabstract1', 'dh-100-ffa94c');
$image = new Imagick();
$image->readimageblob($file100['contents']);
$this->assertEquals(100, $image->getImageWidth());
$file200 = Kwf_Media::getOutput('Kwc_ImageResponsive_MediaOutput_Image_TestComponent', 'root_imageabstract1', 'dh-200-ffa94c');
$image->readimageblob($file200['contents']);
$this->assertEquals(200, $image->getImageWidth());
}
示例2: compareImage
function compareImage(URLToCheck $urlToCheck, $resposeBody, $contentType)
{
$imageType = substr($contentType, strlen('image/'));
$blahblah = str_replace(['?', '&', '/', '='], '_', $urlToCheck->getUrl());
if (strlen($blahblah) >= 100) {
$md5 = md5($blahblah);
$blahblah = substr($blahblah, 0, 100) . $md5;
}
$oututFilename = 'compare/' . $blahblah . '.' . $imageType;
if (file_exists($oututFilename) == false) {
echo "First compare, creating file of {$blahblah}\n";
file_put_contents($oututFilename, $resposeBody);
return;
}
$imagickNew = new Imagick();
$imagickNew->readimageblob($resposeBody);
$imagickCompare = new Imagick($oututFilename);
$result = $imagickCompare->compareImages($imagickNew, \Imagick::LAYERMETHOD_COMPAREANY);
list($imagickDifference, $distance) = $result;
if ($distance > 0.01) {
echo "Differrence detected in {$blahblah} \n";
/** @var $imagickDifference Imagick */
$imagickDifference->writeimage($blahblah . "diff" . time() . '.' . $imageType);
}
}
示例3: convertPdfToImage
function convertPdfToImage($pdfData)
{
$imageData = new \Imagick();
$imageData->readimageblob($pdfData);
$imageData->setImageFormat('png');
// $imageData->extentImage($this->options['width'],$this->options['height'],0,0);
$this->phpimage = $imageData;
}
示例4: getBlurred
public function getBlurred($url)
{
$image = new Imagick();
$imagenblob = file_get_contents($url);
$image->readimageblob($imagenblob);
$image->blurImage(5, 3);
return $image;
}
示例5: takeScreenshot
public function takeScreenshot($jqueryIdentifier = "body")
{
$image = new \Imagick();
$image->readimageblob($this->webDriver->takeScreenshot());
$coords = $this->getCoordinates($jqueryIdentifier);
$image->cropImage($coords['width'], $coords['height'], $coords['offset_x'], $coords['offset_y']);
return $image;
}
示例6: getImage
public function getImage($identifier)
{
// @todo use curl
$imageFile = $this->getStorageFile($identifier);
$imageContent = file_get_contents($imageFile);
$image = new \Imagick();
$image->readimageblob($imageContent);
return $image;
}
示例7: switch
function __construct($imgsource, $sourcetype = QrReader::SOURCE_TYPE_FILE, $isUseImagickIfAvailable = true)
{
try {
switch ($sourcetype) {
case QrReader::SOURCE_TYPE_FILE:
if ($isUseImagickIfAvailable && extension_loaded('imagick')) {
$im = new Imagick();
$im->readImage($imgsource);
} else {
$image = file_get_contents($imgsource);
$im = imagecreatefromstring($image);
}
break;
case QrReader::SOURCE_TYPE_BLOB:
if ($isUseImagickIfAvailable && extension_loaded('imagick')) {
$im = new Imagick();
$im->readimageblob($imgsource);
} else {
$im = imagecreatefromstring($imgsource);
}
break;
case QrReader::SOURCE_TYPE_RESOURCE:
$im = $imgsource;
if ($isUseImagickIfAvailable && extension_loaded('imagick')) {
$isUseImagickIfAvailable = true;
} else {
$isUseImagickIfAvailable = false;
}
break;
}
if ($isUseImagickIfAvailable && extension_loaded('imagick')) {
$width = $im->getImageWidth();
$height = $im->getImageHeight();
$source = new \Zxing\IMagickLuminanceSource($im, $width, $height);
} else {
$width = imagesx($im);
$height = imagesy($im);
$source = new \Zxing\GDLuminanceSource($im, $width, $height);
}
$histo = new \Zxing\Common\HybridBinarizer($source);
$bitmap = new \Zxing\BinaryBitmap($histo);
$reader = new \Zxing\Qrcode\QRCodeReader();
$this->result = $reader->decode($bitmap);
} catch (\Zxing\NotFoundException $er) {
$this->result = false;
} catch (\Zxing\FormatException $er) {
$this->result = false;
} catch (\Zxing\ChecksumException $er) {
$this->result = false;
}
$im->clear();
}
示例8: testScreenshot
public function testScreenshot()
{
if (!class_exists('Imagick')) {
$this->markTestSkipped('Imagick is not installed');
}
$browser = $this->getBrowser();
$browser->open($this->getUrl('index.php'));
$data = $browser->screenshot();
$image = new \Imagick();
$image->readimageblob($data);
$this->assertGreaterThan(100, $image->getImageWidth());
$this->assertGreaterThan(100, $image->getImageHeight());
}
示例9: parseItems
protected function parseItems($xpath, $html, &$items)
{
$crawler = new Crawler();
$crawler->addHtmlContent($html);
foreach ($crawler->filterXPath($xpath) as $tr) {
$item = array();
$tds = $tr->getElementsByTagName('td');
if (0 == $tds->length) {
continue;
}
$item['id'] = (int) ($item['value'] = str_replace(array("\n", "'"), '', $tds->item(1)->nodeValue));
$name = $tds->item(3);
$sup = $name->getElementsByTagName('sup')->item(0);
if (null !== $sup) {
$name->removeChild($sup);
}
$item['name'] = $item['label'] = str_replace(array("\n", "'"), '', $name->nodeValue);
/** @var \DOMElement $tds */
if ($tds->item(4)->getElementsByTagName('a')->length > 0) {
$title = $tds->item(4)->getElementsByTagName('a')->item(0)->getAttribute('title');
} else {
continue;
}
$item['title'] = $title;
if ($tds->item(0)->childNodes->length != 0 && $tds->item(0)->childNodes->item(0)->nodeName == 'a' && $tds->item(0)->childNodes->item(0)->childNodes->item(0)->nodeName == 'img') {
$image = file_get_contents($tds->item(0)->childNodes->item(0)->childNodes->item(0)->getAttribute('src'));
$storepath = sprintf('/var/www/MControl/images/%s.png', str_replace(':', '_', $item['name']));
/** @var \Imagick $croppedImage */
$croppedImage = new \Imagick();
$croppedImage->readimageblob($image);
$croppedImage->cropimage(25, 12, 0, 0);
$croppedImage->writeimage($storepath);
$palette = $this->colorPalette($storepath, 2);
$item['color'] = str_split($palette[1], 2);
} else {
$item['color'] = null;
}
$items[] = $item;
}
return $items;
}
示例10: resizeImage
/**
* Function to scale an image maintaining the aspect ratio.
*
* @param string $image The image
* @param int $width New width
* @param int $height New height
* @return string The resized image
*/
function resizeImage($image, $width, $height)
{
$img = new Imagick();
$img->readimageblob($image);
$img->setImageFormat('png');
$original_width = $img->getImageWidth();
$original_height = $img->getImageHeight();
if ($width > 0 && $height == 0) {
// Use width to scale
if ($width < $original_width) {
$new_width = $width;
$new_height = $original_height / $original_width * $width;
$new_height > 0 ? $new_height : ($new_height = 1);
// Must be 1 at least
$img->resizeImage($new_width, $new_height, Imagick::FILTER_LANCZOS, 1);
return $img->getImageBlob();
}
} else {
if ($width == 0 && $height > 0) {
// Use height to scale
if ($height < $original_height) {
$new_width = $original_width / $original_height * $height;
$new_width > 0 ? $new_width : ($new_width = 1);
// Must be 1 at least
$new_height = $height;
$img->resizeImage($new_width, $new_height, Imagick::FILTER_LANCZOS, 1);
return $img->getImageBlob();
}
} else {
if ($width > 0 && $height > 0) {
// No need to keep aspect ratio
$img->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1);
return $img->getImageBlob();
} else {
// No need to resize, return the original image
return $image;
}
}
}
}
示例11: testWithSmallImageUploadedHtml
public function testWithSmallImageUploadedHtml()
{
$html = $this->_root->getComponentById(1802)->render();
$doc = new DOMDocument();
$doc->strictErrorChecking = FALSE;
$doc->loadHTML($html);
$xml = simplexml_import_dom($doc);
$img = $xml->xpath("//img");
$this->assertEquals(1, count($img));
$this->assertEquals(10, (string) $img[0]['width']);
$this->assertEquals(10, (string) $img[0]['height']);
$this->assertTrue(!!preg_match('#^/media/([^/]+)/([^/]+)/([^/]+)#', (string) $img[0]['src'], $m));
$o = call_user_func(array($m[1], 'getMediaOutput'), $m[2], $m[3], $m[1]);
$this->assertEquals('image/gif', $o['mimeType']);
$im = new Imagick();
if (isset($o['contents'])) {
$contents = $o['contents'];
} else {
$contents = file_get_contents($o['file']);
}
$im->readImageBlob($contents);
$this->assertEquals(10, $im->getImageWidth());
$this->assertEquals(10, $im->getImageHeight());
$this->assertEquals(Kwf_Media_Image::scale(Kwf_Model_Abstract::getInstance('Kwc_Basic_ImageEnlarge_UploadsModel')->getRow('2')->getFileSource(), array(10, 10, 'cover' => true), 2), $contents);
$a = $xml->xpath("//a");
$this->assertEquals(1, count($a));
$this->assertEquals('{"width":210,"height":70,"style":"CenterBox","adaptHeight":true,"lightboxUrl":"\\/foo3\\/image"}', (string) $a[0]['data-kwc-lightbox']);
$this->assertContains('/media/Kwc_Basic_ImageEnlarge_EnlargeTag_TestComponent/1802-linkTag/', (string) $a[0]['href']);
$html = $this->_root->getComponentById('1802-linkTag_imagePage')->render();
$doc = new DOMDocument();
$doc->strictErrorChecking = FALSE;
$doc->loadHTML($html);
$xml = simplexml_import_dom($doc);
$img = $xml->xpath("//img");
$this->assertEquals(1, count($img));
$this->assertTrue(!!preg_match('#^/media/([^/]+)/([^/]+)/([^/]+)#', (string) $img[0]['src'], $m));
$o = call_user_func(array($m[1], 'getMediaOutput'), $m[2], $m[3], $m[1]);
$this->assertEquals('image/gif', $o['mimeType']);
$im = new Imagick();
if (isset($o['contents'])) {
$contents = $o['contents'];
} else {
$contents = file_get_contents($o['file']);
}
$im->readImageBlob($contents);
// crop is set, because show_selection is set and else compare will fail
$content = Kwf_Media_Image::scale(Kwf_Model_Abstract::getInstance('Kwc_Basic_ImageEnlarge_UploadsModel')->getRow('2')->getFileSource(), array(210, 70, 'cover' => false, 'crop' => array('height' => 70, 'width' => 210, 'x' => 0, 'y' => 0)));
$image = new Imagick();
$image->readimageblob($content);
$this->assertEquals(210, $im->getImageWidth());
$this->assertEquals(70, $im->getImageHeight());
$this->assertEquals($content, $contents);
}
示例12: ImagickDraw
}
$start_interval = $current;
$end_interval = $start_interval + $step;
$sql = "SELECT img_id, image, timestamp, RG_start FROM SE90_060_WTH_IM_S1_8000_JET_M6_ST3600" . " WHERE timestamp >= " . $start_interval . " AND timestamp < " . $end_interval;
$stmt = $conn->query($sql);
$row = $stmt->fetchObject();
if ($row == false) {
$im->newImage($width, $height, "transparent");
} else {
if (is_null($row->image)) {
$im->newImage($width, $height, "transparent");
} else {
$range_start = $row->RG_start;
$height_bot = $height / 8000 * $range_start;
$height_top = $height - $height_bot;
$image_top->readimageblob($row->image);
$image_top->resizeImage($width, $height_top, Imagick::FILTER_LANCZOS, 1);
$image_bot->newImage($width, $height_bot, "transparent");
$image_bot->setImageFormat('png');
$image_tmp->addImage($image_top);
$image_tmp->addImage($image_bot);
$image_tmp->resetIterator();
$im = $image_tmp->appendImages(true);
$im->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1);
}
}
$tick = new ImagickDraw();
$tick->setStrokeWidth(10);
$tick->setStrokeColor($color);
$tick->setFillColor($color);
$tick->line(0, 0, 0, 20);
示例13: Imagick
POST->image[base64 encoded pdf](local out.pdf test)
GET->format[png jpg eps etc.](png)
GET->show[](prints image header for browser display if present)
GET->debug[](prints debug info if present)
GET->dpi[a number](300)
</pre>';
}
$image = new Imagick();
$dpi = 300;
if (isset($_GET['dpi'])) {
$dpi = (double) $_GET['dpi'];
}
$image->setResolution($dpi, $dpi);
if (isset($_POST['image'])) {
$decoded = base64_decode($_POST['image']);
$image->readimageblob($decoded);
} else {
if (isset($pdftopng)) {
//todo include pdftopng inline rather than utilizing as a webservice//
$image->readImage($pdftopng);
} else {
$myurl = 'out.pdf';
$image->readImage($myurl);
}
}
$format = "png";
if (isset($_GET['format'])) {
$format = (string) $_GET['format'];
}
if (isset($_GET['show'])) {
header("Content-Type: image/" . $format);
示例14: GetView
function GetView()
{
global $TMP_PATH;
$tmp_file = ADEI::GetTmpFile();
$im = new Imagick();
$tmp = new Imagick();
$image = new Imagick();
$final = new Imagick();
$with_axes = new Imagick();
$output = new Imagick();
$tick = new ImagickDraw();
$ceiling = new ImagickDraw();
$color = new ImagickPixel('#666666');
$background = new ImagickPixel('none');
// Transparent
date_default_timezone_set('UTC');
$servername = "localhost";
$username = "cube";
$password = "cube";
$dbname = "HDCP10";
$req = $this->req->CreateGroupRequest();
$req = $this->req->CreateDataRequest();
$fstart = $req->GetProp("view_pb_start", 0);
$width = $req->GetProp("control_width", 800);
$height = $req->GetProp("control_height", 600);
$height = $height - 180;
// 60px for the xaxis (50px)
$start = 1367366400000000.0;
// GMT: Wed, 01 May 2013 00:00:00 GMT
$end = 1367452800000000.0;
// GMT: Thu, 02 May 2013 00:00:00 GMT
//$end = 1367539200000000; // GMT: Fri, 03 May 2013 00:00:00 GMT
$current = $start;
$step = 3600000000.0;
try {
$conn = new PDO("mysql:host={$servername};dbname={$dbname}", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
while (true) {
if ($current >= $end) {
break;
}
$start_interval = $current;
$end_interval = $start_interval + $step;
$sql = "SELECT img_id, image, timestamp FROM Profiles_060_WTH_STATIC_EL90_Images_Stitch_Im1_3600 WHERE timestamp >= " . $start_interval . " AND timestamp < " . $end_interval;
$stmt = $conn->query($sql);
$row = $stmt->fetchObject();
if ($row == false) {
$im->newImage($width, $height - $height * 20 / 100, "white");
} else {
if (is_null($row->image)) {
$im->newImage($width, $height - $height * 20 / 100, "white");
} else {
$im->readimageblob($row->image);
$im->resizeImage($width, $height - $height * 20 / 100, Imagick::FILTER_LANCZOS, 1);
}
}
#$text = date('H:s', ($current / 1000000));
#$draw = new ImagickDraw();
$tick = new ImagickDraw();
$ceiling = new ImagickDraw();
/* Font properties */
#$draw->setFont('Arial');
#$draw->setFontSize(200);
#$draw->setFillColor($color);
#$draw->setStrokeAntialias(true);
#$draw->setTextAntialias(true);
/* Get font metrics */
#$metrics = $image->queryFontMetrics($draw, $text);
/* Create text */
#$draw->annotation(0, $metrics['ascender']+20, $text);
$tick->setStrokeWidth(10);
$tick->setStrokeColor($color);
$tick->setFillColor($color);
$tick->line(0, 0, 0, 20);
//imageline($image, $width/2, 0, $width/2, 50, $color);
$ceiling->setStrokeColor($color);
$ceiling->setFillColor($color);
$ceiling->line(0, 0, $width, 0);
/* Create image */
$image->newImage($width, 20, $background);
$image->setImageFormat('png');
#$image->drawImage($draw);
$image->drawImage($tick);
$image->drawImage($ceiling);
$im->addImage($image);
$im->resetIterator();
$tmp = $im->appendImages(true);
$final->addImage($tmp);
$current = $end_interval;
$im->clear();
$image->clear();
$tmp->clear();
$tick->clear();
$ceiling->clear();
}
} catch (PDOException $e) {
//echo "Connection failed: " . $e->getMessage();
}
/* Append the images into one */
//.........這裏部分代碼省略.........
示例15: imageProcessImageMagick
private function imageProcessImageMagick()
{
$this->source_image_w = $this->image_info[0];
$this->source_image_h = $this->image_info[1];
$this->source_image_x = 0;
$this->source_image_y = 0;
$dst_x = 0;
$dst_y = 0;
if ($this->clipping != IMAGE_CORE_CM_DEFAULT) {
// clipping method 1: left or top 2: middle 3: right or bottom
$this->source_image_w -= $this->start_x;
$this->source_image_h -= $this->start_y;
if ($this->source_image_w * $this->height > $this->source_image_h * $this->width) {
$match_w = round($this->width * $this->source_image_h / $this->height);
$match_h = $this->source_image_h;
} else {
$match_h = round($this->height * $this->source_image_w / $this->width);
$match_w = $this->source_image_w;
}
switch ($this->clipping) {
case IMAGE_CORE_CM_LEFT_OR_TOP:
$this->source_image_x = 0;
$this->source_image_y = 0;
break;
case IMAGE_CORE_CM_MIDDLE:
$this->source_image_x = round(($this->source_image_w - $match_w) / 2);
$this->source_image_y = round(($this->source_image_h - $match_h) / 2);
break;
case IMAGE_CORE_CM_RIGHT_OR_BOTTOM:
$this->source_image_x = $this->source_image_w - $match_w;
$this->source_image_y = $this->source_image_h - $match_h;
break;
}
$this->source_image_w = $match_w;
$this->source_image_h = $match_h;
$this->source_image_x += $this->start_x;
$this->source_image_y += $this->start_y;
}
$resize_height = $this->height;
$resize_width = $this->width;
if ($this->scale != IMAGE_CORE_SC_NOT_KEEP_SCALE) {
if ($this->scale == IMAGE_CORE_SC_BEST_RESIZE_WIDTH) {
$resize_height = round($this->width * $this->source_image_h / $this->source_image_w);
$resize_width = $this->width;
} else {
if ($this->scale == IMAGE_CORE_SC_BEST_RESIZE_HEIGHT) {
$resize_width = round($this->height * $this->source_image_w / $this->source_image_h);
$resize_height = $this->height;
}
}
}
$im = new Imagick();
$im->readimageblob(file_get_contents($this->source_image));
$im->setCompressionQuality($this->quality);
if ($this->source_image_x or $this->source_image_y) {
$im->cropImage($this->source_image_w, $this->source_image_h, $this->source_image_x, $this->source_image_y);
}
$im->thumbnailImage($resize_width, $resize_height, true);
if ($this->option == IMAGE_CORE_OP_TO_FILE and $this->new_image) {
file_put_contents($this->new_image, $im->getimageblob());
} else {
if ($this->option == IMAGE_CORE_OP_OUTPUT) {
$output = $im->getimageblob();
$outputtype = $im->getFormat();
header("Content-type: {$outputtype}");
echo $output;
die;
}
}
return TRUE;
}