/** * 生成された画像を保存する * * @return boolean * @access public * @static */ function save() { //保存先のディレクトリが存在しているかチェック $filePath = dirname($this->dstPath); if (!file_exists($filePath)) { mkdir($filePath); } if ($this->imageType == 'image/jpeg') { return imageJpeg($this->dstImage, $this->dstPath, $this->quality); } elseif ($this->imageType == 'image/gif') { return imageGif($this->dstImage, $this->dstPath); } elseif ($this->imageType == 'image/png') { return imagePng($this->dstImage, $this->dstPath); } }
function image_createThumb($src, $dest, $maxWidth, $maxHeight, $quality = 75) { if (file_exists($src) && isset($dest)) { // path info $destInfo = pathInfo($dest); // image src size $srcSize = getImageSize($src); // image dest size $destSize[0] = width, $destSize[1] = height $srcRatio = $srcSize[0] / $srcSize[1]; // width/height ratio $destRatio = $maxWidth / $maxHeight; if ($destRatio > $srcRatio) { $destSize[1] = $maxHeight; $destSize[0] = $maxHeight * $srcRatio; } else { $destSize[0] = $maxWidth; $destSize[1] = $maxWidth / $srcRatio; } // path rectification if ($destInfo['extension'] == "gif") { $dest = substr_replace($dest, 'jpg', -3); } // true color image, with anti-aliasing $destImage = imageCreateTrueColor($destSize[0], $destSize[1]); // imageAntiAlias($destImage,true); // src image switch ($srcSize[2]) { case 1: //GIF $srcImage = imageCreateFromGif($src); break; case 2: //JPEG $srcImage = imageCreateFromJpeg($src); break; case 3: //PNG $srcImage = imageCreateFromPng($src); break; default: return false; break; } // resampling imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destSize[0], $destSize[1], $srcSize[0], $srcSize[1]); // generating image switch ($srcSize[2]) { case 1: case 2: imageJpeg($destImage, $dest, $quality); break; case 3: imagePng($destImage, $dest); break; } return true; } else { return 'No such File'; } }
function king_def() { global $king; header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // 过去的时间 header("Content-type: image/png"); $salt = kc_get('salt', 1, 1); $width = $king->config('verifywidth'); //图片长度 $height = $king->config('verifyheight'); //图片高度 $size = $king->config('verifysize'); //文字大小 $num = $king->config('verifynum'); //文字数量 $content = $king->config('verifycontent'); //随机字符 $array_content = explode('|', $content); $array_content = array_diff($array_content, array(null)); $array_font = kc_f_getdir('system/verify_font', 'ttf|ttc'); $str = ''; $img = imageCreate($width, $height); //创建一个空白图像 imageFilledRectangle($img, 0, 0, $width, $height, imagecolorallocate($img, 255, 255, 255)); //写字 for ($i = 0; $i < $num; $i++) { $code = $array_content[array_rand($array_content)]; $str .= $code; //验证码字符 $color = imageColorAllocate($img, rand(0, 128), rand(0, 128), rand(0, 128)); $font = 'verify_font/' . $array_font[array_rand($array_font)]; //随机读取一个字体 $left = rand(round($size * 0.2), round($size * 0.4)) + $i * $size; imagettftext($img, rand(round($size * 0.7), $size), rand(-20, 20), $left, rand(round($size * 1.2), $size * 1.4), $color, $font, $code); } //画星号 $max = $width * $height / 400; for ($i = 0; $i < $max; $i++) { imagestring($img, 15, rand(0, $width), rand(0, $height), '*', rand(192, 250)); } //画点 $max = $width * $height / 40; for ($i = 0; $i < $max; $i++) { imageSetPixel($img, rand(0, $width), rand(0, $height), rand(1, 200)); } //画线 $max = $width * $height / 800; for ($i = 0; $i < $max; $i++) { imageline($img, rand(0, $width), rand(0, $height), rand(0, $width), rand(0, $height), rand(0, 255)); } //写验证码到verify中 $verify = new KC_Verify_class(); $verify->Put($salt, $str); imagePng($img); imageDestroy($img); $verify->Clear(); }
public static function CreatePngThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $imageNewName) { $srcImg = ImageCreateFromPng($imageDirectory . $imageName); $origWidth = imagesx($srcImg); $origHeight = imagesy($srcImg); $ratio = $thumbWidth / $origWidth; $thumbHeight = $origHeight * $ratio; $thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight); imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imagesx($srcImg), imagesy($srcImg)); imagePng($thumbImg, $thumbDirectory . $imageNewName); }
public static function saveFile($image = null, $destFile = null, $saveType = self::SAVE_JPG) { switch ($saveType) { case self::SAVE_GIF: return @imageGif($image, $destFile); case self::SAVE_JPG: return @imageJpeg($image, $destFile, self::SAVE_QUALITY); case self::SAVE_PNG: return @imagePng($image, $destFile); default: return false; } }
function make_img($content) { $timage = array(strlen($content) * 20 + 10, 28); // array(largeur, hauteur) de l'image; ici la largeur est fonction du nombre de lettre du contenu, on peut bien sur mettre une largeur fixe. $content = preg_replace('/(\\w)/', '\\1 ', $content); // laisse plus d'espace entre les lettres $image = imagecreatetruecolor($timage[0], $timage[1]); // création de l'image // definition des couleurs $fond = imageColorAllocate($image, 240, 255, 240); $grey = imageColorAllocate($image, 210, 210, 210); $text_color = imageColorAllocate($image, rand(0, 100), rand(0, 50), rand(0, 60)); imageFill($image, 0, 0, $fond); // on remplit l'image de blanc //On remplit l'image avec des polygones for ($i = 0, $imax = mt_rand(3, 5); $i < $imax; $i++) { $x = mt_rand(3, 10); $poly = array(); for ($j = 0; $j < $x; $j++) { $poly[] = mt_rand(0, $timage[0]); $poly[] = mt_rand(0, $timage[1]); } imageFilledPolygon($image, $poly, $x, imageColorAllocate($image, mt_rand(150, 255), mt_rand(150, 255), mt_rand(150, 255))); } // Création des pixels gris for ($i = 0; $i < $timage[0] * $timage[1] / rand(15, 18); $i++) { imageSetPixel($image, rand(0, $timage[0]), rand(0, $timage[1]), $grey); } // affichage du texte demandé; on le centre en hauteur et largeur (à peu près ^^") //imageString($image, 5, ceil($timage[0]-strlen($content)*8)/2, ceil($timage[1]/2)-9, $content, $text_color); $longueur_chaine = strlen($content); for ($ch = 0; $ch < $longueur_chaine; $ch++) { imagettftext($image, 18, mt_rand(-30, 30), 10 * ($ch + 1), mt_rand(18, 20), $text_color, 'res/georgia.ttf', $content[$ch]); } $type = function_exists('imageJpeg') ? 'jpeg' : 'png'; @header('Content-Type: image/' . $type); @header('Cache-control: no-cache, no-store'); $type == 'png' ? imagePng($image) : imageJpeg($image); ImageDestroy($image); exit; }
function resizeImage($file, $max_x, $max_y, $forcePng = false) { if ($max_x <= 0 || $max_y <= 0) { $max_x = 5; $max_y = 5; } $src = BASEDIR . '/avatars/' . $file; list($width, $height, $type) = getImageSize($src); $scale = min($max_x / $width, $max_y / $height); $newWidth = $width * $scale; $newHeight = $height * $scale; $img = imagecreatefromstring(file_get_contents($src)); $black = imagecolorallocate($img, 0, 0, 0); $resizedImage = imageCreateTrueColor($newWidth, $newHeight); imagecolortransparent($resizedImage, $black); imageCopyResampled($resizedImage, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); imageDestroy($img); unlink($src); if (!$forcePng) { switch ($type) { case IMAGETYPE_JPEG: imageJpeg($resizedImage, BASEDIR . '/avatars/' . $file); break; case IMAGETYPE_GIF: imageGif($resizedImage, BASEDIR . '/avatars/' . $file); break; case IMAGETYPE_PNG: imagePng($resizedImage, BASEDIR . '/avatars/' . $file); break; default: imagePng($resizedImage, BASEDIR . '/avatars/' . $file); break; } } else { imagePng($resizedImage, BASEDIR . '/avatars/' . $file . '.png'); } return; }
function save($filename, $type = 'png', $quality = 100) { $this->_build(); $this->_build_border(); switch ($type) { case 'gif': $ret = imageGif($this->_dest_image, $filename); break; case 'jpg': case 'jpeg': $ret = imageJpeg($this->_dest_image, $filename, $quality); break; case 'png': $ret = imagePng($this->_dest_image, $filename); break; default: $this->_error('Save: Invalid Format'); break; } if (!$ret) { $this->_error('Save: Unable to save'); } }
function drawField($team) { $field = imagecreatefromjpeg("img/field.jpg"); foreach ($team->players as $player) { $img = drawPlayer($player->number, $player->name); $width = imagesx($img); $height = imagesy($img); $posX = $player->x - ($width - 26) / 2; $posY = $player->y - 10; imageAlphaBlending($field, true); // копировать сюда будем вместе с настройками imageSaveAlpha($field, true); // сохраняем imageCopy($field, $img, $posX, $posY, 0, 0, $width, $height); //копируем картинку с формой в пустой бокс } $copyright = drawCaption("http://www.ezheloko.ru/tactic", 12, 0); imagecopymerge_alpha($field, $copyright, 240, imagesY($field) - 25, 0, 0, imagesX($copyright), imagesY($copyright), 30); $name = generateName(); $name = "formations/" . $name . ".png"; imagePng($field, $name); return $name; }
function all_project_tree($id_user, $completion, $project_kind) { include "../include/config.php"; $config["id_user"] = $id_user; $dotfilename = $config["homedir"] . "/attachment/tmp/{$id_user}.all.dot"; $pngfilename = $config["homedir"] . "/attachment/tmp/{$id_user}.projectall.png"; $mapfilename = $config["homedir"] . "/attachment/tmp/{$id_user}.projectall.map"; $dotfile = fopen($dotfilename, "w"); fwrite($dotfile, "digraph Integria {\n"); fwrite($dotfile, "\t ranksep=1.8;\n"); fwrite($dotfile, "\t ratio=auto;\n"); fwrite($dotfile, "\t size=\"9,9\";\n"); fwrite($dotfile, 'URL="' . $config["base_url"] . '/index.php?sec=projects&sec2=operation/projects/project_tree";' . "\n"); fwrite($dotfile, "\t node[fontsize=" . $config['fontsize'] . "];\n"); fwrite($dotfile, "\t me [label=\"{$id_user}\", style=\"filled\", color=\"yellow\"]; \n"); $total_project = 0; $total_task = 0; if ($project_kind == "all") { $sql1 = "SELECT * FROM tproject WHERE disabled = 0"; } else { $sql1 = "SELECT * FROM tproject WHERE disabled = 0 AND end != '0000-00-00 00:00:00'"; } if ($result1 = mysql_query($sql1)) { while ($row1 = mysql_fetch_array($result1)) { if (user_belong_project($id_user, $row1["id"], 1) == 1) { $project[$total_project] = $row1["id"]; $project_name[$total_project] = $row1["name"]; if ($completion < 0) { $sql2 = "SELECT * FROM ttask WHERE id_project = " . $row1["id"]; } elseif ($completion < 101) { $sql2 = "SELECT * FROM ttask WHERE completion < {$completion} AND id_project = " . $row1["id"]; } else { $sql2 = "SELECT * FROM ttask WHERE completion = 100 AND id_project = " . $row1["id"]; } if ($result2 = mysql_query($sql2)) { while ($row2 = mysql_fetch_array($result2)) { if (user_belong_task($id_user, $row2["id"], 1) == 1) { $task[$total_task] = $row2["id"]; $task_name[$total_task] = $row2["name"]; $task_parent[$total_task] = $row2["id_parent_task"]; $task_project[$total_task] = $project[$total_project]; $task_workunit[$total_task] = get_task_workunit_hours($row2["id"]); $task_completion[$total_task] = $row2["completion"]; $total_task++; } } } $total_project++; } } } // Add project items for ($ax = 0; $ax < $total_project; $ax++) { fwrite($dotfile, 'PROY' . $project[$ax] . ' [label="' . wordwrap($project_name[$ax], 12, '\\n') . '", style="filled", color="grey", URL="' . $config["base_url"] . '/index.php?sec=projects&sec2=operation/projects/task&id_project=' . $project[$ax] . '"];'); fwrite($dotfile, "\n"); } // Add task items for ($ax = 0; $ax < $total_task; $ax++) { $temp = 'TASK' . $task[$ax] . ' [label="' . wordwrap($task_name[$ax], 12, '\\n') . '"'; if ($task_completion[$ax] < 10) { $temp .= 'color="red"'; } elseif ($task_completion[$ax] < 100) { $temp .= 'color="yellow"'; } elseif ($task_completion[$ax] == 100) { $temp .= 'color="green"'; } $temp .= "URL=\"" . $config["base_url"] . "/index.php?sec=projects&sec2=operation/projects/task_detail&id_project=" . $task_project[$ax] . "&id_task=" . $task[$ax] . "&operation=view\""; $temp .= "];"; fwrite($dotfile, $temp); fwrite($dotfile, "\n"); } // Make project attach to user "me" for ($ax = 0; $ax < $total_project; $ax++) { fwrite($dotfile, 'me -> PROY' . $project[$ax] . ';'); fwrite($dotfile, "\n"); } // Make project first parent task relation visible for ($ax = 0; $ax < $total_task; $ax++) { if ($task_parent[$ax] == 0) { fwrite($dotfile, 'PROY' . $task_project[$ax] . ' -> TASK' . $task[$ax] . ';'); fwrite($dotfile, "\n"); } } // Make task-subtask parent task relation visible for ($ax = 0; $ax < $total_task; $ax++) { if ($task_parent[$ax] != 0) { fwrite($dotfile, 'TASK' . $task_parent[$ax] . ' -> TASK' . $task[$ax] . ';'); fwrite($dotfile, "\n"); } } fwrite($dotfile, "}"); fwrite($dotfile, "\n"); // exec ("twopi -Tpng $dotfilename -o $pngfilename"); exec("twopi -Tcmapx -o{$mapfilename} -Tpng -o{$pngfilename} {$dotfilename}"); Header('Content-type: image/png'); $imgPng = imageCreateFromPng($pngfilename); imageAlphaBlending($imgPng, true); imageSaveAlpha($imgPng, true); imagePng($imgPng); require $mapfilename; //unlink ($pngfilename); unlink($dotfilename); }
ImageGif($im1, $imagnam, $quality); echo "<img src='" . $imagnam . "' alt=''/><br/>"; break; case "jpg": $imagnam = "temp/{$namefile}.temp.jpg"; imageJpeg($im1, $imagnam, $quality); echo "<img src='" . $imagnam . "' alt=''/><br/>"; break; case "jpeg": $imagnam = "temp/{$namefile}.temp.jpg"; imageJpeg($im1, $imagnam, $quality); echo "<img src='" . $imagnam . "' alt=''/><br/>"; break; case "png": $imagnam = "temp/{$namefile}.temp.png"; imagePng($im1, $imagnam, $quality); echo "<img src='" . $imagnam . "' alt=''/><br/>"; break; } imagedestroy($im); imagedestroy($im1); $kom = mysql_query("select * from `gallery` where type='km' and refid='" . $newf['id'] . "';"); $kom1 = mysql_num_rows($kom); echo "</a><br/>" . $lng['date'] . ': ' . functions::display_date($newf['time']) . '<br/>' . $lng['description'] . ": {$newf['text']}<br/>"; $al = mysql_query("select * from `gallery` where type = 'al' and id = '" . $newf['refid'] . "';"); $al1 = mysql_fetch_array($al); $rz = mysql_query("select * from `gallery` where type = 'rz' and id = '" . $al1['refid'] . "';"); $rz1 = mysql_fetch_array($rz); echo '<a href="index.php?id=' . $al1['id'] . '">' . $rz1['text'] . ' / ' . $al1['text'] . '</a></div>'; } ++$i;
private function createNewImage($newImg, $newName, $imgInfo) { $this->path = rtrim($this->path, "/") . "/"; switch ($imgInfo["type"]) { case 1: //gif $result = imageGIF($newImg, $this->path . $newName); break; case 2: //jpg $result = imageJPEG($newImg, $this->path . $newName); break; case 3: //png $result = imagePng($newImg, $this->path . $newName); break; } imagedestroy($newImg); return $newName; }
$charImageStep = $imageWidth / ($charsNumber + 1); $charWritePoint = $charImageStep; // Write captcha characters to the image for ($i = 0; $i < $charsNumber; $i++) { $nextChar = $characters[mt_rand(0, count($characters) - 1)]; $captchaText .= $nextChar; // Font properties $randomFontSize = mt_rand(25, 30); // Random character size to spice things a little bit :) $randomFontAngle = mt_rand(-25, 25); // Twist the character a little bit $fontType = select_captcha_font(); // This is the font we are using - we need to point to the ttf file here // Pixels $pixelX = $charWritePoint; // We will write a character at this X point $pixelY = 40; // We will write a character at this Y point // Random character color // R // G // B // Alpha $randomCharColor = imageColorAllocateAlpha($captchaImage, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 25)); // Write a character to the image imageTtfText($captchaImage, $randomFontSize, $randomFontAngle, $pixelX, $pixelY, $randomCharColor, $fontType, $nextChar); // Increase captcha step $charWritePoint += $charImageStep; } // Add currently generated captcha text to the session $_SESSION['login_captcha'] = $captchaText; // Return the image return imagePng($captchaImage); // Destroy captcha image imageDestroy($captchaImage);
$textColor = imageColorAllocate($image, rand(0, 100), rand(0, 100), rand(0, 100)); $font = rand(1, 4) . ".ttf"; $randsize = rand($size - $size / 10, $size + $size / 10); $location = $left + ($i * $size + $size / 10); imagettftext($image, $randsize, rand(-18, 18), $location, rand($size - $size / 10, $size + $size / 10), $textColor, $font, $randtext); } if ($noise == true) { setnoise(); } $_SESSION['cv_yzm'] = $code; $bordercolor = getcolor($bordercolor); if ($border == true) { imageRectangle($image, 0, 0, $width - 1, $height - 1, $bordercolor); } header("Content-type: image/png"); imagePng($image); imagedestroy($image); function getcolor($color) { global $image; $color = eregi_replace("^#", "", $color); $r = $color[0] . $color[1]; $r = hexdec($r); $b = $color[2] . $color[3]; $b = hexdec($b); $g = $color[4] . $color[5]; $g = hexdec($g); $color = imagecolorallocate($image, $r, $b, $g); return $color; } function setnoise()
/** * Creates error image based on gfx/notfound_thumb.png * Requires GD lib enabled, otherwise it will exit with the three * textstrings outputted as text. Outputs the image stream to browser and exits! * * @param string $filename Name of the file * @param string $textline1 Text line 1 * @param string $textline2 Text line 2 * @param string $textline3 Text line 3 * @return void * @throws \RuntimeException * * @internal Don't use this method from outside the LocalImageProcessor! */ public function getTemporaryImageWithText($filename, $textline1, $textline2, $textline3) { if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) { throw new \RuntimeException('TYPO3 Fatal Error: No gdlib. ' . $textline1 . ' ' . $textline2 . ' ' . $textline3, 1270853952); } // Creates the basis for the error image if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) { $im = imagecreatefrompng(PATH_typo3 . 'gfx/notfound_thumb.png'); } else { $im = imagecreatefromgif(PATH_typo3 . 'gfx/notfound_thumb.gif'); } // Sets background color and print color. $white = imageColorAllocate($im, 255, 255, 255); $black = imageColorAllocate($im, 0, 0, 0); // Prints the text strings with the build-in font functions of GD $x = 0; $font = 0; if ($textline1) { imagefilledrectangle($im, $x, 9, 56, 16, $white); imageString($im, $font, $x, 9, $textline1, $black); } if ($textline2) { imagefilledrectangle($im, $x, 19, 56, 26, $white); imageString($im, $font, $x, 19, $textline2, $black); } if ($textline3) { imagefilledrectangle($im, $x, 29, 56, 36, $white); imageString($im, $font, $x, 29, substr($textline3, -14), $black); } // Outputting the image stream and exit if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) { imagePng($im, $filename); } else { imageGif($im, $filename); } }
function imageResize($params, $filePath) { $params["WIDTH"] = !isset($params["WIDTH"]) ? 100 : intval($params["WIDTH"]); $params["HEIGHT"] = !isset($params["HEIGHT"]) ? 100 : intval($params["HEIGHT"]); $params["MODE"] = !isset($params["MODE"]) ? 'inv' : strtolower($params["MODE"]); $params["QUALITY"] = (!isset($params["QUALITY"]) || intval($params["QUALITY"]) <= 0 ) ? 100 : $params["QUALITY"]; $params["HIQUALITY"] = !isset($params["HIQUALITY"]) ? (($params["WIDTH"] <= 200 || $params["HEIGHT"] <= 200) ? 1 : 0 ) : 0; $imageType = getFileExtension($filePath); $pathToOriginalFile = "{$_SERVER["DOCUMENT_ROOT"]}/{$filePath}"; if (!file_exists($pathToOriginalFile)) return; $salt = md5(strtolower($filePath) . implode('_', $params) . $SETSTYLE); $salt = substr($salt, 0, 3) . '/'; $filename = basename($filePath); $pathToFile = $salt . $filename; // если изображение существует if (is_file(CHACHE_IMG_PATH . $pathToFile) == true) { if ($_REQUEST["clear_cache"] == 'IMAGE') { //при очистке кэша unlink(RETURN_IMG_PATH . $pathToFile); } else { return RETURN_IMG_PATH . $pathToFile; } } CheckDirPath(CHACHE_IMG_PATH . $salt); $i = getImageSize($pathToOriginalFile); if (intval($params["WIDTH"]) == 0) $params["WIDTH"] = intval($params["HEIGHT"] / $i[1] * $i[0]); if (intval($params["HEIGHT"]) == 0) $params["HEIGHT"] = intval($params["WIDTH"] / $i[0] * $i[1]); //если вырезаться будет cut проверка размеров if (($params["WIDTH"] > $i[0] || $params["HEIGHT"] > $i[1]) && ($params["MODE"] != "in" && $params["MODE"] != "inv")) { $params["WIDTH"] = $i[0]; $params["HEIGHT"] = $i[1]; } $im = ImageCreateTrueColor($params["WIDTH"], $params["HEIGHT"]); imageAlphaBlending($im, false); switch (strtolower($imageType)) { case 'gif' : $i0 = ImageCreateFromGif($pathToOriginalFile); $icolor = imagecolorallocate($im, 255, 255, 255); imagefill($im, 0, 0, $icolor); break; case 'jpg' : case 'jpeg' : $i0 = ImageCreateFromJpeg($pathToOriginalFile); $icolor = imagecolorallocate($im, 255, 255, 255); imagefill($im, 0, 0, $icolor); break; case 'png' : $i0 = ImageCreateFromPng($pathToOriginalFile); $icolor = imagecolorallocate($im, 255, 255, 255); imagefill($im, 0, 0, $icolor); break; } if (!($i[0] == $params["WIDTH"] && $i[1] == $params["HEIGHT"] && !$SETSTYLE)) { switch (strtolower($params["MODE"])) { case 'cut' : $k_x = $i [0] / $params["WIDTH"]; $k_y = $i [1] / $params["HEIGHT"]; if ($k_x > $k_y) $k = $k_y; else $k = $k_x; $pn["WIDTH"] = $i [0] / $k; $pn["HEIGHT"] = $i [1] / $k; $x = ($params["WIDTH"] - $pn["WIDTH"]) / 2; $y = ($params["HEIGHT"] - $pn["HEIGHT"]) / 2; imageCopyResampled($im, $i0, $x, $y, 0, 0, $pn["WIDTH"] + 2, $pn["HEIGHT"] + 2, $i[0], $i[1]); // ( dst_im, src_im, dstX, dstY, srcX, srcY, int dstW, int dstH, int srcW, int srcH) break; //вписана в квадрат без маштабирования (картинка может быть увеличена больше своего размера) case 'in' : if (($i [0] < $params["WIDTH"]) && ($i [1] < $params["HEIGHT"])) { $k_x = 1; $k_y = 1; } else { $k_x = $i[0] / $params["WIDTH"]; $k_y = $i[1] / $params["HEIGHT"]; } if ($k_x < $k_y) $k = $k_y; else $k = $k_x; $pn["WIDTH"] = intval($i[0] / $k); $pn["HEIGHT"] = intval($i[1] / $k); $x = intval(($params["WIDTH"] - $pn["WIDTH"]) / 2); $y = intval(($params["HEIGHT"] - $pn["HEIGHT"]) / 2); imageCopyResampled($im, $i0, $x, $y, 0, 0, $pn["WIDTH"], $pn["HEIGHT"], $i[0], $i[1]); // 1 первый параметр изборажение источник // 2 изображение которое вставляется // 3 4 -х и у с какой точки будет вставятся в изображении источник // 5 6 - ширина и высота куда будет вписано изображение break; //вписана в квадрат с маштабированием (картинка может быть увеличена) case 'inv' : $k_x = $i [0] / $params["WIDTH"]; $k_y = $i [1] / $params["HEIGHT"]; if ($k_x < $k_y) $k = $k_y; else $k = $k_x; $pn["WIDTH"] = $i [0] / $k; $pn["HEIGHT"] = $i [1] / $k; $x = ($params["WIDTH"] - $pn["WIDTH"]) / 2; $y = ($params["HEIGHT"] - $pn["HEIGHT"]) / 2; imageCopyResampled($im, $i0, $x, $y, 0, 0, $pn["WIDTH"], $pn["HEIGHT"], $i[0], $i[1]); if ($params["WIDTH"] == 55 && $params["HEIGHT"] == 45) { imageAlphaBlending($im, true); $waterMark = ImageCreateFromPng($_SERVER["DOCUMENT_ROOT"] . "/img/video.png"); imageCopyResampled($im, $waterMark, 0, 0, 0, 0, $params["WIDTH"], $params["HEIGHT"], $params["WIDTH"], $params["HEIGHT"]); } break; case 'width' : $factor = $i[1] / $i[0]; // определяем пропорцию height / width if ($factor > 1.35) { $pn["WIDTH"] = $params["WIDTH"]; $scale_factor = $i[0] / $pn["WIDTH"]; // коэфффициент масштабирования $pn["HEIGHT"] = ceil($i[1] / $scale_factor); $x = 0; $y = 0; if (($params["HEIGHT"] / $pn["HEIGHT"]) < 0.6) { //echo 100 / ($pn["HEIGHT"] * 100) / ($params["HEIGHT"] *1.5); $pn["HEIGHT"] = (100 / (($pn["HEIGHT"] * 100) / ($params["HEIGHT"] * 1.3))) * $pn["HEIGHT"]; $newKoef = $i[1] / $pn["HEIGHT"]; $pn["WIDTH"] = $i[0] / $newKoef; $x = ($params["WIDTH"] - $pn["WIDTH"]) / 2; //$y = ($params["HEIGHT"] - $pn["HEIGHT"]) / 2; } imageCopyResampled($im, $i0, $x, $y, 0, 0, $pn["WIDTH"], $pn["HEIGHT"], $i[0], $i[1]); } else { if (($i [0] < $params["WIDTH"]) && ($i [1] < $params["HEIGHT"])) { $k_x = 1; $k_y = 1; } else { $k_x = $i [0] / $params["WIDTH"]; $k_y = $i [1] / $params["HEIGHT"]; } if ($k_x < $k_y) $k = $k_y; else $k = $k_x; $pn["WIDTH"] = $i [0] / $k; $pn["HEIGHT"] = $i [1] / $k; $x = ($params["WIDTH"] - $pn["WIDTH"]) / 2; $y = ($params["HEIGHT"] - $pn["HEIGHT"]) / 2; imageCopyResampled($im, $i0, $x, $y, 0, 0, $params["MODE"], $pn["HEIGHT"], $i[0], $i[1]); } break; default : imageCopyResampled($im, $i0, 0, 0, 0, 0, $params["WIDTH"], $params["HEIGHT"], $i[0], $i[1]); break; } if ($params["HIQUALITY"]) { $sharpenMatrix = array ( array(-1.2, -1, -1.2), array(-1, 20, -1), array(-1.2, -1, -1.2) ); // calculate the sharpen divisor $divisor = array_sum(array_map('array_sum', $sharpenMatrix)); $offset = 0; // apply the matrix imageconvolution($im, $sharpenMatrix, $divisor, $offset); } switch (strtolower($imageType)) { case 'gif' :imageSaveAlpha($im, true); @imageGif($im, CHACHE_IMG_PATH . $pathToFile); break; case 'jpg' : case 'jpeg' : @imageJpeg($im, CHACHE_IMG_PATH . $pathToFile, $params["QUALITY"]); break; case 'png' : imageSaveAlpha($im, true); @imagePng($im, CHACHE_IMG_PATH . $pathToFile); break; } } else { copy($pathToOriginalFile, CHACHE_IMG_PATH . $pathToFile); } return RETURN_IMG_PATH . $pathToFile; }
/** * Creates a font-preview thumbnail. * This means a PNG/GIF file with the text "AaBbCc...." set with the font-file given as input and in various sizes to show how the font looks * Requires GD lib enabled. * Outputs the image stream to browser and exits! * * @param string $font The filepath to the font file (absolute, probably) * @return void * @todo Define visibility */ public function fontGif($font) { if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) { throw new \RuntimeException('TYPO3 Fatal Error: No gdlib.', 1270853953); } // Create image and set background color to white. $im = imageCreate(250, 76); $white = imageColorAllocate($im, 255, 255, 255); $col = imageColorAllocate($im, 0, 0, 0); // The test string and offset in x-axis. $string = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzÆæØøÅåÄäÖöÜüß'; $x = 13; // Print (with non-ttf font) the size displayed imagestring($im, 1, 0, 2, '10', $col); imagestring($im, 1, 0, 15, '12', $col); imagestring($im, 1, 0, 30, '14', $col); imagestring($im, 1, 0, 47, '18', $col); imagestring($im, 1, 0, 68, '24', $col); // Print with ttf-font the test string imagettftext($im, GeneralUtility::freetypeDpiComp(10), 0, $x, 8, $col, $font, $string); imagettftext($im, GeneralUtility::freetypeDpiComp(12), 0, $x, 21, $col, $font, $string); imagettftext($im, GeneralUtility::freetypeDpiComp(14), 0, $x, 36, $col, $font, $string); imagettftext($im, GeneralUtility::freetypeDpiComp(18), 0, $x, 53, $col, $font, $string); imagettftext($im, GeneralUtility::freetypeDpiComp(24), 0, $x, 74, $col, $font, $string); // Output PNG or GIF based on $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'] if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) { header('Content-type: image/png'); imagePng($im); } else { header('Content-type: image/gif'); imageGif($im); } imagedestroy($im); die; }
function debugMode($line, $message, $file = null, $config = null, $message2 = null) { global $im, $configData; // Destroy the image if (isset($im)) { imageDestroy($im); } if (is_numeric($line)) { $line -= 1; } $error_text = 'Error!'; $line_text = 'Line: ' . $line; $file = !empty($file) ? 'File: ' . $file : ''; $config = $config ? 'Check the config file' : ''; $message2 = !empty($message2) ? $message2 : ''; $lines = array(); $lines[] = array('s' => $error_text, 'f' => 5, 'c' => 'red'); $lines[] = array('s' => $line_text, 'f' => 3, 'c' => 'blue'); $lines[] = array('s' => $file, 'f' => 2, 'c' => 'green'); $lines[] = array('s' => $message, 'f' => 2, 'c' => 'black'); $lines[] = array('s' => $config, 'f' => 2, 'c' => 'black'); $lines[] = array('s' => $message2, 'f' => 2, 'c' => 'black'); $height = $width = 0; foreach ($lines as $line) { if (strlen($line['s']) > 0) { $line_width = ImageFontWidth($line['f']) * strlen($line['s']); $width = $width < $line_width ? $line_width : $width; $height += ImageFontHeight($line['f']); } } $im = @imagecreate($width + 1, $height); if ($im) { $white = imagecolorallocate($im, 255, 255, 255); $red = imagecolorallocate($im, 255, 0, 0); $green = imagecolorallocate($im, 0, 255, 0); $blue = imagecolorallocate($im, 0, 0, 255); $black = imagecolorallocate($im, 0, 0, 0); $linestep = 0; foreach ($lines as $line) { if (strlen($line['s']) > 0) { imagestring($im, $line['f'], 1, $linestep, utf8_to_nce($line['s']), ${$line}['c']); $linestep += ImageFontHeight($line['f']); } } switch ($configData['image_type']) { case 'jpeg': case 'jpg': header('Content-type: image/jpg'); @imageJpeg($im); break; case 'png': header('Content-type: image/png'); @imagePng($im); break; case 'gif': default: header('Content-type: image/gif'); @imagegif($im); break; } imageDestroy($im); } else { if (!empty($file)) { $file = "[<span style=\"color:green\">{$file}</span>]"; } $string = "<strong><span style=\"color:red\">Error!</span></strong>"; $string .= "<span style=\"color:blue\">Line {$line}:</span> {$message} {$file}\n<br /><br />\n"; if ($config) { $string .= "{$config}\n<br />\n"; } if (!empty($message2)) { $string .= "{$message2}\n"; } print $string; } exit; }
imageGif($imgNew); break; case "jpg": header('Content-type: image/jpeg'); imageJpeg($imgNew, $cache_path); imageJpeg($imgNew); break; case "jpeg": header('Content-type: image/jpeg'); imageJpeg($imgNew, $cache_path); imageJpeg($imgNew); break; case "png": header('Content-type: image/png'); imagePng($imgNew, $cache_path); imagePng($imgNew); break; } imageDestroy($img); imageDestroy($imgNew); // function from docos to convert short-hand notation to bytes function imageresize_return_bytes($val) { $val = trim($val); $last = strtolower($val[strlen($val) - 1]); switch ($last) { // The 'G' modifier is available since PHP 5.1.0 case 'g': $val *= 1024; case 'm': $val *= 1024;
function redimage($src, $dest, $dw = false, $dh = false, $stamp = false) { // detect file type (could be a lot better) if (is_array($src)) { $type_src = strtoupper(substr($src['name'], -3)); $src = $src['tmp_name']; } else { $type_src = strtoupper(substr($src, -3)); } $type_dest = strtoupper(substr($dest, -3)); // read source image switch ($type_src) { case 'JPG': $src_img = ImageCreateFromJpeg($src); break; case 'PEG': $src_img = ImageCreateFromJpeg($src); break; case 'GIF': $src_img = ImageCreateFromGif($src); break; case 'PNG': $src_img = imageCreateFromPng($src); break; case 'BMP': $src_img = imageCreatefromWBmp($src); break; } // get it's info $size = GetImageSize($src); $sw = $size[0]; $sh = $size[1]; /* // get it's info $size = GetImageSize ($src); $fw = $size[0]; $fh = $size[1]; // ROGNE the picture from the top left pixel's color $rogne_color = imagecolorat ($src_img, 0, 0); $rogne_point = array ($fh, 0, 0, $fw); for ($x = 0; $x < $fw; $x ++){ for ($y = 0; $y < $fh; $y ++){ if (imagecolorat ($src_img, $x, $y) != $rogne_color){ $rogne_point[0] = ($rogne_point[0] > $y)?$y:$rogne_point[0]; $rogne_point[1] = ($rogne_point[1] < $x)?$x:$rogne_point[1]; $rogne_point[2] = ($rogne_point[2] < $y)?$y:$rogne_point[2]; $rogne_point[3] = ($rogne_point[3] > $x)?$x:$rogne_point[3]; } } } $sw = $rogne_point[1] - $rogne_point[3]; $sh = $rogne_point[2] - $rogne_point[0]; $rogne_img = ImageCreateTrueColor ($sw, $sh); ImageCopyResampled ($rogne_img, $src_img, 0, 0, $rogne_point[3], $rogne_point[0], $fw, $fh, $fw, $fh); $src_img = $rogne_img; */ // do not redim the pic if ($dw == false && $dh == false) { $dest_img = ImageCreateTrueColor($sw, $sh); ImageCopyResampled($dest_img, $src_img, 0, 0, 0, 0, $sw, $sh, $sw, $sh); } else { // redim the pix with dest W as max Side if ($dw != 0 && $dh == false) { if ($sw == $sh) { $dh = $dw; } else { if ($sw > $sh) { $dh = round($dw / $sw * $sh); } else { $dh = $dw; $dw = round($dh / $sh * $sw); } } $dest_img = ImageCreateTrueColor($dw, $dh); ImageCopyResampled($dest_img, $src_img, 0, 0, 0, 0, $dw, $dh, $sw, $sh); } else { // redim the pic according to dest W or dest H if ($dw == 0 || $dh == 0) { if ($dw == 0) { $dw = round($dh / $sh * $sw); } else { if ($dh == 0) { $dh = round($dw / $sw * $sh); } } $dest_img = ImageCreateTrueColor($dw, $dh); ImageCopyResampled($dest_img, $src_img, 0, 0, 0, 0, $dw, $dh, $sw, $sh); } else { if ($sw / $sh < $dw / $dh) { $tw = $sw; $th = round($sw / $dw * $dh); $x = 0; $y = round(($sh - $th) / 2); $temp_img = ImageCreateTrueColor($tw, $th); $dest_img = ImageCreateTrueColor($dw, $dh); ImageCopyResampled($temp_img, $src_img, 0, 0, $x, $y, $sw, $sh, $sw, $sh); ImageCopyResampled($dest_img, $temp_img, 0, 0, 0, 0, $dw, $dh, $tw, $th); ImageDestroy($temp_img); } else { $tw = $sw; $th = round($sw * ($dh / $dw)); $x = 0; $y = round(($th - $sh) / 2); $temp_img = ImageCreateTrueColor($tw, $th); $dest_img = ImageCreateTrueColor($dw, $dh); imagefill($temp_img, 0, 0, imagecolorallocate($dest_img, 0, 0, 0)); ImageCopyResampled($temp_img, $src_img, $x, $y, 0, 0, $sw, $sh, $sw, $sh); ImageCopyResampled($dest_img, $temp_img, 0, 0, 0, 0, $dw, $dh, $tw, $th); ImageDestroy($temp_img); } } } } if ($stamp != false) { // detect file type (could be a lot better) $type_stamp = strtoupper(substr($stamp, -3)); // read stamp switch ($type_stamp) { case 'JPG': $stamp_img = ImageCreateFromJpeg($stamp); break; case 'PEG': $stamp_img = ImageCreateFromJpeg($stamp); break; case 'GIF': $stamp_img = ImageCreateFromGif($stamp); break; case 'PNG': $stamp_img = imageCreateFromPng($stamp); break; case 'BMP': $stamp_img = imageCreatefromWBmp($stamp); break; } // get it's info $size = GetImageSize($stamp); $stw = $size[0]; $sth = $size[1]; $sx = $dw - $stw; $sy = $dh - $sth; imagecolortransparent($stamp_img, imageColorAllocate($stamp_img, 0, 0, 0)); imagecopy($dest_img, $stamp_img, $sx, $sy, 0, 0, $stw, $sth); } // free destination if (file_exists($dest_img)) { unlink($dest_img); } // save dest image switch ($type_dest) { case 'JPG': imageJpeg($dest_img, $dest, 90); break; case 'PEG': imageJpeg($dest_img, $dest, 90); break; case 'GIF': imageGif($dest_img, $dest, 90); break; case 'PNG': imagePng($dest_img, $dest, 90); break; case 'BMP': imageWBmp($dest_img, $dest, 90); break; } // free memory imageDestroy($src_img); ImageDestroy($dest_img); }
/** * Сохраняет изображение в формате png * * @param string путь, по которому сохранится изображение * @return AcImage * * @throws UnsupportedFormatException * @throws FileAlreadyExistsException * @throws FileNotSaveException */ public function saveAsPNG($path) { if (!AcImagePNG::isSupport()) { throw new UnsupportedFormatException('png'); } if (!self::getRewrite() && self::isFileExists($path)) { throw new FileAlreadyExistsException($path); } if (!self::getTransparency()) { $this->putBackground(self::$backgroundColor); } // php >= 5.1.2 if (!imagePng(self::getResource(), $path, AcImagePNG::getQuality())) { throw new FileNotSaveException($path); } return $this; }
function showCartoonfy($p_ext, $p_dis) { switch (strtolower($p_ext)) { case "jpg": header('Content-type:image/' . strtolower($p_ext)); if ($p_dis) { header('Content-disposition:attachment;filename=' . time() . '.' . strtolower($p_ext)); } imageJpeg($this->i1); break; case "jpeg": header('Content-type:image/' . strtolower($p_ext)); if ($p_dis) { header('Content-disposition:attachment;filename=' . time() . '.' . strtolower($p_ext)); } imageJpeg($this->i1); break; case "gif": header('Content-type:image/' . strtolower($p_ext)); if ($p_dis) { header('Content-disposition:attachment;filename=' . time() . '.' . strtolower($p_ext)); } imageGif($this->i1); break; case "png": header('Content-type:image/' . strtolower($p_ext)); if ($p_dis) { header('Content-disposition:attachment;filename=' . time() . '.' . strtolower($p_ext)); } imagePng($this->i1); break; default: print "<b>" . $p_ext . "</b> is not supported image format!"; exit; } imageDestroy($this->i1); }
/** * Generate images of alternate sizes. */ function resizeImage($cnvrt_arry) { global $platform, $imgs, $cnvrt_path, $reqd_image, $convert_writable, $convert_magick, $convert_GD, $convert_cmd, $cnvrt_alt, $cnvrt_mesgs, $compat_quote; if (empty($imgs) || $convert_writable == FALSE) { return; } if ($convert_GD == TRUE && !($gd_version = gdVersion())) { return; } if ($cnvrt_alt['no_prof'] == TRUE) { $strip_prof = ' +profile "*"'; } else { $strip_prof = ''; } if ($cnvrt_alt['mesg_on'] == TRUE) { $str = ''; } foreach ($imgs as $img_file) { if ($cnvrt_alt['indiv'] == TRUE && $img_file != $reqd_image['file']) { continue; } $orig_img = $reqd_image['pwd'] . '/' . $img_file; $cnvrtd_img = $cnvrt_path . '/' . $cnvrt_arry['prefix'] . $img_file; if (!is_file($cnvrtd_img)) { $img_size = GetImageSize($orig_img); $height = $img_size[1]; $width = $img_size[0]; $area = $height * $width; $maxarea = $cnvrt_arry['maxwid'] * $cnvrt_arry['maxwid'] * 0.9; $maxheight = $cnvrt_arry['maxwid'] * 0.75 + 1; if ($area > $maxarea || $width > $cnvrt_arry['maxwid'] || $height > $maxheight) { if ($width / $cnvrt_arry['maxwid'] >= $height / $maxheight) { $dim = 'W'; } if ($height / $maxheight >= $width / $cnvrt_arry['maxwid']) { $dim = 'H'; } if ($dim == 'W') { $cnvt_percent = round(0.9375 * $cnvrt_arry['maxwid'] / $width * 100, 2); } if ($dim == 'H') { $cnvt_percent = round(0.75 * $cnvrt_arry['maxwid'] / $height * 100, 2); } // convert it if ($convert_magick == TRUE) { // Image Magick image conversion if ($platform == 'Win32' && $compat_quote == TRUE) { $winquote = '"'; } else { $winquote = ''; } exec($winquote . $convert_cmd . ' -geometry ' . $cnvt_percent . '%' . ' -quality ' . $cnvrt_arry['qual'] . ' -sharpen ' . $cnvrt_arry['sharpen'] . $strip_prof . ' "' . $orig_img . '"' . ' "' . $cnvrtd_img . '"' . $winquote); $using = $cnvrt_mesgs['using IM']; } elseif ($convert_GD == TRUE) { // GD image conversion if (eregi('\\.jpg$|\\.jpeg$', $img_file) == TRUE && (imageTypes() & IMG_JPG) == TRUE) { $src_img = imageCreateFromJpeg($orig_img); } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_PNG) == TRUE) { $src_img = imageCreateFromPng($orig_img); } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_GIF) == TRUE) { $src_img = imageCreateFromGif($orig_img); } else { continue; } $src_width = imageSx($src_img); $src_height = imageSy($src_img); $dest_width = $src_width * ($cnvt_percent / 100); $dest_height = $src_height * ($cnvt_percent / 100); if ($gd_version >= 2) { $dst_img = imageCreateTruecolor($dest_width, $dest_height); imageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height); } else { $dst_img = imageCreate($dest_width, $dest_height); imageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height); } imageDestroy($src_img); if (eregi('\\.jpg$|\\.jpeg$/i', $img_file) == TRUE && (imageTypes() & IMG_JPG) == TRUE) { imageJpeg($dst_img, $cnvrtd_img, $cnvrt_arry['qual']); } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_PNG) == TRUE) { imagePng($dst_img, $cnvrtd_img); } elseif (eregi('\\.gif$/i', $img_file) == TRUE && (imageTypes() & IMG_GIF) == TRUE) { imageGif($dst_img, $cnvrtd_img); } imageDestroy($dst_img); $using = $cnvrt_mesgs['using GD'] . $gd_version; } if ($cnvrt_alt['mesg_on'] == TRUE && is_file($cnvrtd_img)) { $str .= " <small>\n" . ' ' . $cnvrt_mesgs['generated'] . $cnvrt_arry['txt'] . $cnvrt_mesgs['converted'] . $cnvrt_mesgs['image_for'] . $img_file . $using . ".\n" . " </small>\n <br />\n"; } } } } if (isset($str)) { return $str; } }
$i = imageCreateTrueColor(500, 300); /* Подготовка к работе */ imageAntiAlias($i, true); $red = imageColorAllocate($i, 255, 0, 0); $white = imageColorAllocate($i, 0xff, 0xff, 0xff); $black = imageColorAllocate($i, 0, 0, 0); $green = imageColorAllocate($i, 0, 255, 0); $blue = imageColorAllocate($i, 0, 0, 255); $grey = imageColorAllocate($i, 192, 192, 192); imageFill($i, 0, 0, $grey); /* Рисуем примитивы */ imageSetPixel($i, 10, 10, $black); imageLine($i, 20, 20, 280, 180, $red); imageRectangle($i, 20, 20, 280, 180, $blue); //array of dots $points = [120, 120, 100, 200, 300, 200]; imagePolygon($i, $points, 3, $green); imageEllipse($i, 200, 150, 300, 200, $red); // imageArc($i, 210, 160, 300, 200, 0, 90, $black); imageFilledArc($i, 200, 150, 300, 200, 0, 40, $red, IMG_ARC_PIE); /* Рисуем текст */ imageString($i, 5, 150, 200, 'php7', $black); imageCharUp($i, 3, 200, 200, 'PHP5', $blue); imageTtfText($i, 30, 10, 300, 150, $green, 'arial.ttf', 'PHP7'); /* Отдаем изображение */ // header("Content-type: image/gif"); // imageGif($i); header("Content-type: image/png"); imagePng($i); //header("Content-type: image/jpg"); //imageJpeg($i);
<?php $dest = dirname(realpath(__FILE__)) . '/bug22544.png'; @unlink($dest); $image = imageCreateTruecolor(640, 100); $transparent = imageColorAllocate($image, 0, 0, 0); $red = imageColorAllocate($image, 255, 50, 50); imageColorTransparent($image, $transparent); imageFilledRectangle($image, 0, 0, 640 - 1, 100 - 1, $transparent); imagePng($image, $dest); echo md5_file($dest) . "\n"; @unlink($dest);
/** * Creates error image based on gfx/notfound_thumb.png * Requires GD lib enabled, otherwise it will exit with the three * textstrings outputted as text. Outputs the image stream to browser and exits! * * @param string $filename Name of the file * @param string $textline1 Text line 1 * @param string $textline2 Text line 2 * @param string $textline3 Text line 3 * @return void * @throws \RuntimeException */ public function getTemporaryImageWithText($filename, $textline1, $textline2, $textline3) { if (empty($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'])) { throw new \RuntimeException('TYPO3 Fatal Error: No gdlib. ' . $textline1 . ' ' . $textline2 . ' ' . $textline3, 1270853952); } // Creates the basis for the error image $basePath = ExtensionManagementUtility::extPath('core') . 'Resources/Public/Images/'; if (!empty($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'])) { $im = imagecreatefrompng($basePath . 'NotFound.png'); } else { $im = imagecreatefromgif($basePath . 'NotFound.gif'); } // Sets background color and print color. $white = imageColorAllocate($im, 255, 255, 255); $black = imageColorAllocate($im, 0, 0, 0); // Prints the text strings with the build-in font functions of GD $x = 0; $font = 0; if ($textline1) { imagefilledrectangle($im, $x, 9, 56, 16, $white); imageString($im, $font, $x, 9, $textline1, $black); } if ($textline2) { imagefilledrectangle($im, $x, 19, 56, 26, $white); imageString($im, $font, $x, 19, $textline2, $black); } if ($textline3) { imagefilledrectangle($im, $x, 29, 56, 36, $white); imageString($im, $font, $x, 29, substr($textline3, -14), $black); } // Outputting the image stream and exit if (!empty($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'])) { imagePng($im, $filename); } else { imageGif($im, $filename); } }
case 'mailgraph_virus_day': $imgPng = imagecreatefrompng($pluginDir . '/Mailgraph/tmp_graph/mailgraph_virus_day.png'); break; case 'mailgraph_virus_week': $imgPng = imagecreatefrompng($pluginDir . '/Mailgraph/tmp_graph/mailgraph_virus_week.png'); break; case 'mailgraph_virus_month': $imgPng = imagecreatefrompng($pluginDir . '/Mailgraph/tmp_graph/mailgraph_virus_month.png'); break; case 'mailgraph_virus_year': $imgPng = imagecreatefrompng($pluginDir . '/Mailgraph/tmp_graph/mailgraph_virus_year.png'); break; case 'mailgraph_greylist_day': $imgPng = imagecreatefrompng($pluginDir . '/Mailgraph/tmp_graph/mailgraph_greylist_day.png'); break; case 'mailgraph_greylist_week': $imgPng = imagecreatefrompng($pluginDir . '/Mailgraph/tmp_graph/mailgraph_greylist_week.png'); break; case 'mailgraph_greylist_month': $imgPng = imagecreatefrompng($pluginDir . '/Mailgraph/tmp_graph/mailgraph_greylist_month.png'); break; case 'mailgraph_greylist_year': $imgPng = imagecreatefrompng($pluginDir . '/Mailgraph/tmp_graph/mailgraph_greylist_year.png'); break; default: $imgPng = imagecreatefrompng($pluginDir . '/Mailgraph/frontend/noimage.png'); } /* Output image to browser */ header("Content-type: image/png"); imagePng($imgPng); imagedestroy($imgPng);
function show_error($file, $drawuserdef, $imgmaxx, $imgmaxy, $type, $section) { $im = ImageCreateTrueColor($imgmaxx, $imgmaxy); $black = ImageColorAllocate($im, 0, 0, 0); $bg2p = ImageColorAllocate($im, 175, 198, 219); $white = ImageColorAllocate($im, 255, 255, 255); $red = ImageColorAllocate($im, 255, 0, 0); ImageFill($im, 0, 0, $bg2p); ImageRectangle($im, 0, 0, $imgmaxx - 1, $imgmaxy - 1, $white); include "../config.php"; $bg3p = ImageColorAllocate($im, $fontcol_grap_R, $fontcol_grap_G, $fontcol_grap_B); $text = "There is a new supported {$type}-Device but no Logfile {$file}"; $fontsize = 9; $txtcolor = $bg3p; ImageTTFText($im, $fontsize, 0, 5, 17, $txtcolor, $fontttf, $text); $text = "Please check the userdef[{$section}] of <pgm3>/config.php and refresh your browser"; ImageTTFText($im, $fontsize, 0, 5, 45, $txtcolor, $fontttf, $text); header("Content-type: image/png"); imagePng($im); exit; }
$black = ImageColorAllocate($im, 0, 0, 0); $bg1p = ImageColorAllocate($im, $bg1_R, $bg1_G, $bg1_B); $bg2p = ImageColorAllocate($im, $buttonBg_R, $buttonBg_G, $buttonBg_B); $bg3p = ImageColorAllocate($im, $fontcol_grap_R, $fontcol_grap_G, $fontcol_grap_B); $white = ImageColorAllocate($im, 255, 255, 255); $gray = ImageColorAllocate($im, 133, 133, 133); $red = ImageColorAllocate($im, 255, 0, 0); $green = ImageColorAllocate($im, 0, 255, 0); $yellow = ImageColorAllocate($im, 255, 255, 0); $orange = ImageColorAllocate($im, 255, 230, 25); if ($room == $showroom) { $imgcolor = $bg1p; $txtcolor = $white; } else { $imgcolor = $bg2p; $txtcolor = $bg3p; } ImageFill($im, 0, 0, $imgcolor); ImageRectangle($im, 0, 0, $imgmaxxroom - 1, $imgmaxyroom - 1, $white); ###ttf $text = $room; $box = @imageTTFBbox($roomfontsizetitel, 0, $fontttfb, $text); $textwidth = abs($box[4] - $box[0]); $textheight = abs($box[5] - $box[1]); $xcord = $imgmaxxroom / 2 - $textwidth / 2 - 2; # $ycord = ($imgmaxyroom/2)+($textheight/2); $ycord = $imgmaxyroom / 3 + $roomfontsizetitel; ImageTTFText($im, $roomfontsizetitel, 0, $xcord, $ycord, $txtcolor, $fontttfb, $text); header("Content-type: image/png"); imagePng($im);
/** * This function resizes given image, if it has bigger dimensions, than we need and saves it (also makes chmod 0777 on the file) ... * It uses GD or ImageMagick, setting is available to change in CL's config file. * * @param string $inputFileName the input file to work with * @param string $outputFileName the file to write into the final (resized) image * @param integer $maxNewWidth maximal width of image * @param integer $maxNewHeight maximal height of image * @return bool TRUE, if everything was successful (resize and chmod), else FALSE */ function resize($inputFileName, $outputFileName, $maxNewWidth, $maxNewHeight) { $imageInfo = getimagesize($inputFileName); $fileType = $imageInfo['mime']; $extension = strtolower(str_replace('.', '', substr($outputFileName, -4))); $originalWidth = $imageInfo[0]; $originalHeight = $imageInfo[1]; if ($originalWidth > $maxNewWidth or $originalHeight > $maxNewHeight) { $newWidth = $maxNewWidth; $newHeight = $originalHeight / ($originalWidth / $maxNewWidth); if ($newHeight > $maxNewHeight) { $newHeight = $maxNewHeight; $newWidth = $originalWidth / ($originalHeight / $maxNewHeight); } $newWidth = ceil($newWidth); $newHeight = ceil($newHeight); } else { $newWidth = $originalWidth; $newHeight = $originalHeight; } $ok = FALSE; if (CL::getConf('CL_Images/engine') == 'imagick-cli') { exec("convert -thumbnail " . $newWidth . "x" . $newHeight . " " . $inputFileName . " " . $outputFileName); $ok = TRUE; } elseif (CL::getConf('CL_Images/engine') == 'imagick-php') { $image = new Imagick($inputFileName); $image->thumbnailImage($newWidth, $newHeight); $ok = (bool) $image->writeImage($outputFileName); $image->clear(); $image->destroy(); } else { $out = imageCreateTrueColor($newWidth, $newHeight); switch (strtolower($fileType)) { case 'image/jpeg': $source = imageCreateFromJpeg($inputFileName); break; case 'image/png': $source = imageCreateFromPng($inputFileName); break; case 'image/gif': $source = imageCreateFromGif($inputFileName); break; default: break; } imageCopyResized($out, $source, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight); switch (strtolower($extension)) { case 'jpg': case 'jpeg': if (imageJpeg($out, $outputFileName)) { $ok = TRUE; } break; case 'png': if (imagePng($out, $outputFileName)) { $ok = TRUE; } break; case 'gif': if (imageGif($out, $outputFileName)) { $ok = TRUE; } break; default: break; } imageDestroy($out); imageDestroy($source); } if ($ok and chmod($outputFileName, 0777)) { return TRUE; } else { return FALSE; } }