public function making($dst_w, $dst_h) { $thumb_img = imagecreatetruecolor($dst_w, $dst_h); imagecopyresampled($thumb_img, $this->image, 0, 0, 0, 0, $dst_w, $dst_h, $this->width, $this->height); ob_start(); switch ($this->_mimetype) { case "gd2": imagegd2($thumb_img, null, 100); break; case "gd": imagegd($thumb_img, null, 100); break; case "gif": imagegif($thumb_img, null, 100); break; case "jpeg": imagejpeg($thumb_img, null, 100); break; case "jpg": imagejpeg($thumb_img, null, 100); break; case "png": imagepng($thumb_img, null, 9); break; case "webp": imagewebp($thumb_img, null, 100); break; default: throw new \yii\base\NotSupportedException("Unsupport imageX method!"); break; } imagedestroy($this->image); //destory origin return ob_get_clean(); //返回二进制数据流 }
/** * Saves the image to a file * * @param GDImage_Image $img * @param string $uri * @param integer $chunk_size * @param integer $type */ function save($handle, $uri = null, $chunk_size = null, $type = null) { ob_start(); imagegd2($handle, null, $chunk_size, $type); $imageBuffer = ob_get_contents(); ob_end_clean(); JFile::write($uri, $imageBuffer); }
/** * Workarround method for cloning a GD2 image resource. * * @param resource $resource * * @return resource */ private function cloneGdResource($resource) { ob_start(); imagegd2($resource); $clone = imagecreatefromstring(ob_get_clean()); // Only works for images with transparency if we set these imagealphablending($clone, false); imagesavealpha($clone, true); return $clone; }
/** * Returns the binary data for the image. * * @return string * @author Oliver Lillie */ public function toBinaryData() { $gd = $this->toGdImage(); if ($gd !== false) { ob_start(); imagegd2($gd); return ob_get_clean(); } return false; }
/** * @test */ public function readFileOk() { $file = ROOT . '/test/assets/images/file2.png'; $resource = $this->reader->read($file); ob_start(); imagegd2($resource->getRaw()); $contents = md5(ob_get_clean()); ob_start(); $fromGd = imagecreatefrompng($file); imagegd2($fromGd); $expected = md5(ob_get_clean()); $this->assertEquals($expected, $contents); }
/** * 按比例压缩图片 * @param int $percent * @return string 二进制数据流 */ public function compress($percent) { $image = imagecreatefromstring($this->_StreamData); $width = imagesx($image); //原图width $height = imagesy($image); //原图height $t_w = $percent * $width; //缩略图width $t_h = $percent * $height; //缩略图height $thumb_img = imagecreatetruecolor($t_w, $t_h); imagecopyresampled($thumb_img, $image, 0, 0, 0, 0, $t_w, $t_h, $width, $height); ob_start(); switch ($this->_mimetype) { case "gd2": imagegd2($thumb_img, null, 100); break; case "gd": imagegd($thumb_img, null, 100); break; case "gif": imagegif($thumb_img, null, 100); break; case "jpeg": imagejpeg($thumb_img, null, 100); break; case "jpg": imagejpeg($thumb_img, null, 100); break; case "png": imagepng($thumb_img, null, 100); break; default: throw new \yii\base\NotSupportedException("Unsupport imageX method!"); break; } imagedestroy($image); //destory origin return ob_get_clean(); //返回二进制数据流 }
/** {@inheritdoc} */ public function set($z, $x, $y, $img) { ob_start(); imagegd2($img); $data = ob_get_clean(); $z = (int) $z; $x = (int) $x; $y = (int) $y; $result = $this->get($z, $x, $y); if ($result) { $stmt = $this->db->prepare("UPDATE tiledata SET image = :image WHERE z = :z AND x = :x AND y = :y;"); } else { $stmt = $this->db->prepare("INSERT INTO tiledata (z, x, y, image) VALUES(:z, :x, :y, :image);"); } $stmt->bindValue('z', $x, \SQLITE3_INTEGER); $stmt->bindValue('x', $z, \SQLITE3_INTEGER); $stmt->bindValue('y', $y, \SQLITE3_INTEGER); $stmt->bindValue('image', $data, \SQLITE3_BLOB); $stmt->execute(); }
/** * Neues Bild Stueckweise erstellen */ private function copyResampledPart(&$image, &$newImage, $newImageInfo, $newWidth, $newHeight, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $bgColor = null) { // Breite und Hoehe angegeben? if ($newWidth <= 0 && $newHeight <= 0) { // Fehler return; } // temporaeres Verzeichnis vorhanden if (!empty($this->tempDir) && file_exists($this->tempDir)) { // Ja -> verwenden $tmpDir = $this->tempDir; } else { // Nein -> temporaeres Verzeichnis des Systems verwenden $tmpDir = sys_get_temp_dir(); } // Maximial Breite der einzelnen Bereich ermitteln $partWidth = 50; $maxUsedMemory = $this->getMemoryLimit() - memory_get_usage(); if ($maxUsedMemory > 0) { do { $partWidth = $newImageInfo['width'] = (int) ceil($newImageInfo['width'] / 2); $requiredMemory = $this->getRequiredMemory($newImageInfo); } while ($partWidth > 50 && $maxUsedMemory < $requiredMemory); } if ($partWidth < 50) { $partWidth = 50; } // Bild in einzelne Bereich zerlegen $partImages = array(); $partX = 0; while ($partX < $newWidth) { $partImage = null; $success = $this->doCopyResampled($image, $partImage, $this->imageType, $partWidth, $newHeight, $dst_x - $partX, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $bgColor); if ($success && $partImage) { $temp_file = tempnam($tmpDir, 'part_img_'); if (!imagegd2($partImage, $temp_file)) { return false; } $partImages[] = array('x' => $partX, 'file' => $temp_file); imagedestroy($partImage); gc_collect_cycles(); } else { return false; } $partX += $partWidth; } // Originalbild schliessen imagedestroy($image); gc_collect_cycles(); $image = null; // neues Bild erstellen $newImage = imagecreatetruecolor($newWidth, $newHeight); if (!$newImage) { return false; } // Neues Bild aus den einzelne Bereich erstellen $first = true; foreach ($partImages as $nextPart) { $partImage = imagecreatefromgd2($nextPart['file']); unlink($nextPart['file']); if ($newImage && $partImage) { $this->doCopyResampled($partImage, $newImage, $this->imageType, $newWidth, $newHeight, $nextPart['x'], 0, 0, 0, $partWidth, $newHeight, $partWidth, $newHeight, $bgColor, $first); } if ($partImage) { imagedestroy($partImage); } $first = false; } // Status zurueckgeben return $newImage ? true : false; }
public function saveToGD2($_filename) { if (file_exists($_filename)) { unlink($_filename); } $result = imagegd2($this->resource, $_filename); if ($result === false) { throw new \UnexpectedValueException("fail to save"); } }
protected function gdImageToBinaryData($gdImage) { ob_start(); imagegd2($gdImage); return ob_get_clean(); }
/** * Prints the Image * * @param string $name * @param string $directory * @param string $imageType */ private function saveImage($name, $directory, $imageType = 'png', $foreground = null) { switch ($imageType) { case 'jpg': case 'jpeg': imagejpeg($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType); break; case 'gif': imagegif($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType); break; case 'gd': imagegd($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType); break; case 'gd2': imagegd2($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType); break; case 'webp': imagewebp($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType); break; case 'wbmp': imagewbmp($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType, $foreground); break; case 'xbm': imagexbm($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType, $foreground); break; case 'svg': default: imagepng($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType); } imagedestroy($this->imageProperties[0]); }
<?php $cwd = dirname(__FILE__); echo "JPEG to GD1 conversion: "; echo imagegd(imagecreatefromjpeg($cwd . "/conv_test.jpeg"), $cwd . "/test.gd1") ? 'ok' : 'failed'; echo "\n"; echo "JPEG to GD2 conversion: "; echo imagegd2(imagecreatefromjpeg($cwd . "/conv_test.jpeg"), $cwd . "/test.gd2") ? 'ok' : 'failed'; echo "\n"; echo "GD1 to JPEG conversion: "; echo imagejpeg(imagecreatefromgd($cwd . "/test.gd1"), $cwd . "/test_gd1.jpeg") ? 'ok' : 'failed'; echo "\n"; echo "GD2 to JPEG conversion: "; echo imagejpeg(imagecreatefromgd2($cwd . "/test.gd2"), $cwd . "/test_gd2.jpeg") ? 'ok' : 'failed'; echo "\n"; @unlink($cwd . "/test.gd1"); @unlink($cwd . "/test.gd2"); @unlink($cwd . "/test_gd1.jpeg"); @unlink($cwd . "/test_gd2.jpeg");
function output($a_mime = 'image/png') { $mime = trim(strtolower($a_mime)); if ($this->m_handle) { ob_start(); switch ($mime) { case 'jpg': case 'jpeg': case 'image/jpeg': imagejpeg($this->m_handle); break; case 'png': case 'image/png': imagepng($this->m_handle); break; case 'gif': case 'image/gif': imagegif($this->m_handle); break; case 'gd': case 'image/gd': imagegd($this->m_handle); break; case 'gd2': case 'image/gd2': imagegd2($this->m_handle); break; case 'bmp': case 'wbmp': case 'image/bmp': case 'image/wbmp': imagewbmp($this->m_handle); break; } ZResponse::getInstance()->setContent(ob_get_contents()); ob_end_clean(); } ZResponse::getInstance()->setContentType($mime); }
<?php $cwd = dirname(__FILE__); echo "XPM to GD1 conversion: "; echo imagegd(imagecreatefromxpm($cwd . "/conv_test.xpm"), $cwd . "/test.gd1") ? 'ok' : 'failed'; echo "\n"; echo "XPM to GD2 conversion: "; echo imagegd2(imagecreatefromxpm($cwd . "/conv_test.xpm"), $cwd . "/test.gd2") ? 'ok' : 'failed'; echo "\n"; @unlink($cwd . "/test.gd1"); @unlink($cwd . "/test.gd2");
<?php $image = imagecreate(1, 1); // 1px image $tempdir = sys_get_temp_dir() . '/php-gdtest'; if (!file_exists($tempdir) && !is_dir($tempdir)) { mkdir($tempdir, 0777, true); } $userinput = "1"; // from post or get data $temp = $tempdir . "/test" . $userinput . ".tmp"; echo "\nimagegd2 TEST\n"; imagegd2($image, $temp); var_dump(file_exists($tempdir . "/test1")); var_dump(file_exists($tempdir . "/test1.tmp")); foreach (glob($tempdir . "/test*") as $file) { unlink($file); } error_reporting(0); $tempdir = sys_get_temp_dir() . '/php-gdtest'; foreach (glob($tempdir . "/test*") as $file) { unlink($file); } rmdir($tempdir);
/** * save gd resource to the given dest in (.gd2) extension * @param string $dest the dest path ex:('images/preview/') * @param resource $resource gd resource * @param string $name the file name * @return boolean true on success false otherwise */ public static function saveGD($dest, $resource, $name) { if (@get_resource_type($resource) == TIP_RT) { if (!@is_dir($dest)) { self::logger("saveGD", "Dest Directory IS Not Exist ({$dest})"); } $dest = $dest . $name . '.gd2'; $result = @imagegd2($resource, $dest, null, IMG_GD2_COMPRESSED); if (!$result) { self::logger("saveGD", "Unable To Save GD Resource Into ({$dest})"); } return $result; } self::logger("saveGD", " Not A GD Resource"); return false; }
/** * Resize and save the image * need to call $this->set() before * * @return boolean */ function resize() { $this->logInfo('Resize'); $this->src_image = $this->_createImage($this->_oldfileAddr, $this->_fileExtension); if (!$this->src_image) { $this->logInfo('Resize error: src empty'); $this->setError('Resize error: src empty'); return false; } if (!empty($this->_preset['mode']) && $this->_preset['mode'] == 'no') { $this->logInfo('Resize: copying original file'); $this->dst_image = $this->src_image; } else { //Source and destination images metrics $h_src = imagesy($this->src_image); $w_src = imagesx($this->src_image); $h_dst = (int) $this->_preset['h']; $w_dst = (int) $this->_preset['w']; $enlarge = empty($this->_preset['enlarge']) ? false : true; //Resize parameters $src_x = 0; $src_y = 0; $h_ratio = $h_dst == $h_src ? 1 : $h_dst / $h_src; //NB: checking to prevent rounding problem, e.g. 14759/14759 = 0.9999 $w_ratio = $w_dst == $w_src ? 1 : $w_dst / $w_src; switch ($this->_preset['mode']) { case self::RESIZE_METHOD_SCALE: $ratio = min($h_ratio, $w_ratio); if (!$enlarge && $ratio > 1) { $ratio = 1; } $new_h = round($h_src * $ratio); $new_w = round($w_src * $ratio); $this->logInfo("Resize: scale ({$ratio})", array($w_src, $h_src, $new_w, $new_h)); if ($this->_prepareDstImage($new_w, $new_h)) { imagecopyresampled($this->dst_image, $this->src_image, 0, 0, 0, 0, $new_w, $new_h, $w_src, $h_src); $this->logInfo('Resize OK'); } else { $this->logInfo('Resize error'); $this->setError('Resize error'); return false; } break; case self::RESIZE_METHOD_CROP: $this->logInfo('Resize crop'); $centerSrcW = round($w_src / 2, 1); $centerSrcH = round($h_src / 2, 1); $centerDstW = round($w_dst / 2, 1); $centerDstH = round($h_dst / 2, 1); /** CROP FROM CENTER */ if ($h_src >= $h_dst and $w_src >= $w_dst) { $src_y = floor($centerSrcH - $centerDstH); $new_h = $h_dst; $src_x = floor($centerSrcW - $centerDstW); $new_w = $w_dst; if ($this->_prepareDstImage($new_w, $new_h)) { imagecopy($this->dst_image, $this->src_image, 0, 0, $src_x, $src_y, $new_w, $new_h); $this->logInfo('Resize crop OK'); } else { $this->logInfo('Resize crop error'); $this->setError('Resize&crop error'); return false; } } else { if (!$enlarge) { if ($h_src > $h_dst) { $src_y = floor($centerSrcH - $centerDstH); $new_h = $h_dst; } else { $new_h = $h_src; } if ($w_src > $w_dst) { $src_x = floor($centerSrcW - $centerDstW); $new_w = $w_dst; } else { $new_w = $w_src; } if ($this->_prepareDstImage($new_w, $new_h)) { imagecopy($this->dst_image, $this->src_image, 0, 0, $src_x, $src_y, $new_w, $new_h); $this->logInfo('Resize crop OK'); } else { $this->logInfo('Resize crop error'); $this->setError('Resize&crop2 error'); return false; } } else { // image increased so as to completely fill the target area, and then cut $ratio = 1; if ($h_dst > $w_dst) { $ratio = round($h_dst / $h_src, 4); } if ($h_dst < $w_dst) { $ratio = round($w_dst / $w_src, 4); } $new_h = round($h_src * $ratio); $new_w = round($w_src * $ratio); $this->logInfo("Resize crop/enlarge ({$ratio})", array($w_src, $h_src, $new_w, $new_h)); if ($this->_prepareDstImage($new_w, $new_h)) { imagecopyresampled($this->dst_image, $this->src_image, 0, 0, 0, 0, $new_w, $new_h, $w_src, $h_src); $this->logInfo('Resize crop/enlarge OK'); } else { $this->logInfo('Resize crop/enlarge error'); $this->setError('Resize&crop&enlarge error'); return false; } // calculations and cut image if ($w_src > $w_dst or $h_src > $h_dst) { $centerSrcW = round($new_w / 2, 1); $centerSrcH = round($new_h / 2, 1); if ($new_h > $h_dst) { $src_y = floor($centerSrcH - $centerDstH); $new_h = $h_dst; } if ($new_w > $w_dst) { $src_x = floor($centerSrcW - $centerDstW); $new_w = $w_dst; } imagedestroy($this->src_image); $this->src_image = $this->dst_image; $this->logInfo('Resize crop/enlarge/crop'); if ($this->_prepareDstImage($new_w, $new_h)) { imagecopy($this->dst_image, $this->src_image, 0, 0, $src_x, $src_y, $new_w, $new_h); $this->logInfo('Resize crop/enlarge/crop OK'); } else { $this->logInfo('Resize crop/enlarge/crop error'); return false; } } } } break; case self::RESIZE_METHOD_STRETCH: $this->logInfo('Resize stretch'); if (!$enlarge and $w_src <= $w_dst and $h_src <= $h_dst) { $result = copy($this->_oldfileAddr, $this->_newFileAddr); return $result; } else { $new_h = $h_dst; $new_w = $w_dst; } if ($this->_prepareDstImage($new_w, $new_h)) { imagecopyresampled($this->dst_image, $this->src_image, 0, 0, 0, 0, $new_w, $new_h, $w_src, $h_src); $this->logInfo('Resize stretch OK'); } else { $this->logInfo('Resize stretch error'); $this->setError('Resize&stretch error'); return false; } break; } } if (!empty($this->_preset['water-image']) || !empty($this->_preset['water-text'])) { $this->logInfo('Watermarking'); $this->_addWatermark(); } $this->logInfo('Saving as ' . $this->_fileExtension); imagesavealpha($this->dst_image, true); switch ($this->_fileExtension) { case 'jpeg': case 'jpe': case 'jpg': $return = @imagejpeg($this->dst_image, $this->_newFileAddr, 100); break; case 'png': $return = @imagepng($this->dst_image, $this->_newFileAddr); break; case 'gif': $return = @imagegif($this->dst_image, $this->_newFileAddr); break; case 'gd': $return = @imagegd2($this->dst_image, $this->_newFileAddr, IMG_GD2_COMPRESSED); break; default: $this->setError('Unsupported media type of target file: ' . $this->_fileExtension); return false; } imagedestroy($this->src_image); $this->logInfo('Resize finished'); if (!$return) { $this->setError('Result save error'); } return $return; }
public function save($handle, $uri = null, $chunk_size = null, $type = null) { return imagegd2($handle, $uri, $chunk_size, $type); }
<?php $file = dirname(__FILE__) . '/bug38212.gd2'; $im1 = imagecreatetruecolor(10, 100); imagefill($im1, 0, 0, 0xffffff); imagegd2($im1, $file); $im = imagecreatefromgd2part($file, 0, 0, -25, 10); unlink($file);
public function dump() { ob_start(); @imagegd2($this->raw); return ob_get_clean(); }
/** * Make the $this->hdlWork to be an exact copy * of $this->hdlOrig resource * * @return object $this */ protected function copyOrig() { d('start cloning orig resource'); $tmpfname = \tempnam($this->Ini->TEMP_DIR, "imgclone"); d('$tmpfname: ' . $tmpfname); \imagegd2($this->hdlOrig, $tmpfname); $this->hdlWork = \imagecreatefromgd2($tmpfname); @\unlink($tmpfname); return $this; }
<?php $str = file_get_contents(dirname(__FILE__) . '/src.gd2'); $res = imagecreatefromstring($str); /* string */ ob_start(); imagegd2($res); $str2 = ob_get_clean(); var_dump(imagecreatefromstring($str2)); /* file */ $file = dirname(__FILE__) . "/bug41442.gd2"; imagegd2($res, $file); $str2 = file_get_contents($file); var_dump(imagecreatefromstring($str2)); @unlink($file); echo "Done\n";
/** * 将当前画布存放到文件中 * @param resource $dst_im 目标文件的当前画布 * @return resource 生成一个图片文件 */ public function _to($dst_im) { switch ($this->dst_img_ext) { case "gd2": imagegd2($dst_im, $this->dst_img); break; case "gd": imagegd($dst_im, $this->dst_img); break; case "gif": imagegif($dst_im, $this->dst_img); break; case "jpeg": imagejpeg($dst_im, $this->dst_img); break; case "jpg": imagejpeg($dst_im, $this->dst_img); break; case "png": imagepng($dst_im, $this->dst_img); break; default: break; } if (file_exists($this->dst_img)) { return TRUE; } return FALSE; }
foreach ($_POST as $p => $val) { $a = explode("_", $p); if (count($a) == 6) { $pid = $a[0]; $fid = $a[1]; $box = array('tlx' => $a[2], 'tly' => $a[3], 'brx' => $a[4], 'bry' => $a[5]); if ($cpid != $pid || $cfid != $fid) { $cpid = $pid; $cfid = $fid; $sql = "SELECT image\n\t\t\t\t\tFROM formpages\n\t\t\t\t\tWHERE pid = {$pid} and fid = {$fid}"; $row = $db->GetRow($sql); $im = imagecreatefromstring($row['image']); } $image = st_ocr($im, $box); ob_start(); imagegd2($image); $image = ob_get_contents(); ob_end_clean(); $sql = "INSERT INTO ocrtrainst (val,fid,image)\n\t\t\t\tVALUES ('{$val}','{$fid}','" . addslashes($image) . "')"; $db->Execute($sql); } } } if (isset($_GET['delete'])) { $fid = intval($_GET['delete']); $sql = "DELETE FROM ocrtrainst\n\t\tWHERE fid = '{$fid}'"; $db->Execute($sql); } if (isset($_GET['fid']) && isset($_GET['qid']) && isset($_GET['vid'])) { $fid = intval($_GET['fid']); $qid = intval($_GET['qid']);
function _update_feature_images($title, $name) { $this->load->config('gfx'); /* title gd2 cache */ $text = imagecreatetruecolor(150, 20); imagesavealpha($text, true); imagefill($text, 0, 0, imagecolorallocatealpha($text, 255, 255, 255, 127)); imagettftext($text, 12, 0, 0, 16, imagecolorallocate($text, 0, 0, 0), $this->config->item('gfx_sticker_font'), $title); imagegd2($text, './stickerimages/features/' . $name . '.gd2'); //imagepng($text, './stickerimages/features/' . $name . '-text.png'); /* singlefeature sticker */ $bg = imagecreatefromgd2('./images/' . $this->config->item('language') . '/singlefeature.gd2'); imagealphablending($bg, true); imagesavealpha($bg, true); $D = imagettfbbox(12, 0, $this->config->item('gfx_sticker_font'), $title); imagecopy($bg, $text, (150 - ($D[2] - $D[0])) / 2, 7, 0, 0, 150, 20); imagepng($bg, './stickerimages/features/' . $name . '.png'); imagedestroy($text); imagedestroy($bg); }
/** * Return 64x26 bitmap with the caption (name) for the given geocache. */ private function get_caption($cache_id) { # Check cache. $cache_key = "tilecaption/" . self::$VERSION . "/" . $cache_id; $gd2 = self::$USE_CAPTIONS_CACHE ? Cache::get($cache_key) : null; if ($gd2 === null) { # We'll work with 16x bigger image to get smoother interpolation. $im = imagecreatetruecolor(64 * 4, 26 * 4); imagealphablending($im, false); $transparent = imagecolorallocatealpha($im, 255, 255, 255, 127); imagefilledrectangle($im, 0, 0, 64 * 4, 26 * 4, $transparent); imagealphablending($im, true); # Get the name of the cache. $name = Db::select_value("\n select name\n from caches\n where cache_id = '" . mysql_real_escape_string($cache_id) . "'\n "); # Split the name into a couple of lines. //$font = $GLOBALS['rootpath'].'util.sec/bt.ttf'; $font = $GLOBALS['rootpath'] . 'okapi/static/tilemap/tahoma.ttf'; $size = 25; $lines = explode("\n", self::wordwrap($font, $size, 64 * 4 - 6 * 2, $name)); # For each line, compute its (x, y) so that the text is centered. $y = 0; $positions = array(); foreach ($lines as $line) { $bbox = imagettfbbox($size, 0, $font, $line); $width = $bbox[2] - $bbox[0]; $x = 128 - ($width >> 1); $positions[] = array($x, $y); $y += 36; } $drawer = function ($x, $y, $color) use(&$lines, &$positions, &$im, &$size, &$font) { $len = count($lines); for ($i = 0; $i < $len; $i++) { $line = $lines[$i]; list($offset_x, $offset_y) = $positions[$i]; imagettftext($im, $size, 0, $offset_x + $x, $offset_y + $y, $color, $font, $line); } }; # Draw an outline. $outline_color = imagecolorallocatealpha($im, 255, 255, 255, 80); for ($x = 0; $x <= 12; $x += 3) { for ($y = $size - 3; $y <= $size + 9; $y += 3) { $drawer($x, $y, $outline_color); } } # Add a slight shadow effect (on top of the outline). $drawer(9, $size + 3, imagecolorallocatealpha($im, 0, 0, 0, 110)); # Draw the caption. $drawer(6, $size + 3, imagecolorallocatealpha($im, 150, 0, 0, 40)); # Resample. imagealphablending($im, false); $small = imagecreatetruecolor(64, 26); imagealphablending($small, false); imagecopyresampled($small, $im, 0, 0, 0, 0, 64, 26, 64 * 4, 26 * 4); # Cache it! ob_start(); imagegd2($small); $gd2 = ob_get_clean(); Cache::set_scored($cache_key, $gd2); } return imagecreatefromstring($gd2); }
public function __clone() { ob_start(); imagegd2($this->image); $this->setImageResource(imagecreatefromstring(ob_get_clean())); }
function save($handle, $uri = null, $chunk_size = null, $type = null) { imagegd2($handle, null, $chunk_size, $type); }
/** * 存储图片 * * @param $resource * @param $save_path * @param $image_type * @param int $quality * @return bool */ protected function save_image($resource, $save_path, $image_type, $quality = 100) { switch ($image_type) { case 'jpg': case 'jpeg': case 'pjpeg': $ret = imagejpeg($resource, $save_path, $quality); break; case 'gif': $ret = imagegif($resource, $save_path); break; case 'png': $ret = imagepng($resource, $save_path); break; default: $ret = imagegd2($resource, $save_path); break; } return $ret; }
/** * Output an image * * @param resource handle * @return bool */ public function output($handle) { return imagegd2($handle, null, 0, $this->format); }