コード例 #1
0
ファイル: function.php プロジェクト: alileza/certs-gen
function generateImage($base, $text, $fontSize = 141, $letterSpacing = 25)
{
    $filename = 'layout/' . $base . '.jpg';
    // Create Image From Existing File
    $jpg_image = imagecreatefromjpeg($filename);
    $img_size = getimagesize($filename);
    // Allocate A Color For The Text
    $white = imagecolorallocate($jpg_image, 119, 24, 15);
    // Set Path to Font File
    $font_path = 'Antonio-Regular.ttf';
    $bbox = fixbbox(imagettfbbox($fontSize, 0, $font_path, $text));
    $left = $img_size[0] / 2 - $bbox['width'] / 2;
    $top = 1170;
    // Print Text On Image
    imagettftextSp($jpg_image, $fontSize - $letterSpacing, 0, $left, $top, $white, $font_path, $text, $letterSpacing);
    $name = strtolower(str_replace(' ', '-', $text));
    // Send Image to Browser
    imagejpeg($jpg_image, 'result/' . $name . '.jpg');
    // Clear Memory
    imagedestroy($jpg_image);
}
コード例 #2
0
ファイル: image_text.php プロジェクト: laiello/perminator
            $bbox = imagettftext($image, $size, $angle, $temp_x, $y, $color, $font, $text[$i]);
            $temp_x += $spacing + ($bbox[2] - $bbox[0]);
        }
    }
}
// Basic font settings
$minWidth = array_key_exists("minWidth", $_GET) ? (int) $_GET['minWidth'] : 500;
$paddingTop = array_key_exists("paddingTop", $_GET) ? (int) $_GET['paddingTop'] : 10;
$paddingBottom = array_key_exists("paddingBottom", $_GET) ? (int) $_GET['paddingBottom'] : 10;
$paddingLeft = array_key_exists("paddingLeft", $_GET) ? (int) $_GET['paddingLeft'] : 10;
$paddingRight = array_key_exists("paddingRight", $_GET) ? (int) $_GET['paddingRight'] : 10;
$fontSize = array_key_exists("fontSize", $_GET) ? (int) $_GET['fontSize'] : 100;
$fontColor = array_key_exists("fontColor", $_GET) ? $_GET['fontColor'] : 0xf6e336;
$fontFile = array_key_exists("fontFile", $_GET) ? $_GET['fontFile'] : 'HMKLS.ttf';
$text = array_key_exists("value", $_GET) ? $_GET['value'] : "blank";
// Starting X, Y position
$x = $paddingLeft;
$y = $fontSize + $paddingTop;
$boxSize = imagettfbbox($fontSize, 0, $fontFile, $text);
$width = abs($boxSize[0]) + abs($boxSize[2]) + $paddingLeft + $paddingRight;
$width = $width < $minWidth ? $minWidth : $width;
$height = abs($boxSize[5]) + abs($boxSize[1] + $paddingTop + $paddingBottom);
$image = imagecreatetruecolor($width, $height);
imagesavealpha($image, true);
imageantialias($image, true);
$bgColor = imagecolorallocatealpha($image, 0, 0, 0, 127);
imagefill($image, 0, 0, $bgColor);
imagettftextSp($image, $fontSize, 0, $x, $y, $fontColor, $fontFile, $text, 0);
header('Content-Type: image/png; Content-Disposition: attachment; filename=image.png');
imagepng($image);
imagedestroy($image);
コード例 #3
0
ファイル: index.php プロジェクト: CreativeGS/GIFcountdown
        $hours = $interval->format($f_hours);
        $minutes = $interval->format($f_minutes);
        $seconds = $interval->format($f_seconds);
    }
    if (preg_match('/^[0-9]\\:/', $hours)) {
        $hours = '0' . $hours;
    }
    if (preg_match('/^[0-9]\\:/', $minutes)) {
        $minutes = '0' . $minutes;
    }
    if (preg_match('/^[0-9]\\:/', $seconds)) {
        $seconds = '0' . $seconds;
    }
    imagettftextSp($image, $font['size'], $font['angle'], 32, 48, $font['color'], $font['file'], $hours, 16);
    imagettftextSp($image, $font['size'], $font['angle'], 132, 48, $font['color'], $font['file'], $minutes, 16);
    imagettftextSp($image, $font['size'], $font['angle'], 232, 48, $font['color'], $font['file'], $seconds, 16);
    ob_start();
    imagesavealpha($image, true);
    imagecolortransparent($image, 127 << 24);
    imagegif($image);
    $frames[] = ob_get_contents();
    $delays[] = $delay;
    $loops = 0;
    ob_end_clean();
    $now->modify('+1 ' . $t);
}
// Create GIF animation
$gif = new AnimatedGif($frames, $delays, $loops);
// if($is_cache){
file_put_contents($cache_file, $gif->getAnimation());
// }
コード例 #4
0
ファイル: genimg.php プロジェクト: creativecommons/mp
    case 2:
        $padding = floor($width - $size) / 4;
        //15;
        break;
    case 3:
        $padding = 2;
        //1;
        break;
}
////////////////////////////////////////////////////////////////////////////////
// Draw the image (main flow of execution)
////////////////////////////////////////////////////////////////////////////////
imagefill($im, 0, 0, $background_color);
// Add some shadow to the text
//imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
imagettftextSp($im, $size, 0, $padding, $lineheight, $foreground_color, $font, $text, 1);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
////////////////////////////////////////////////////////////////////////////////
// Functions
////////////////////////////////////////////////////////////////////////////////
// Only accept rgb/rgba 6 or 8 digit hex color descriptions
function allocate_color($img, $spec)
{
    $elements = str_split($spec, 2);
    $num_elements = count($elements);
    if ($num_elements < 3 || $num_elements > 4) {
        http_response_code(422);
        exit;
    }
コード例 #5
0
ファイル: gif.php プロジェクト: abaklanov/EmailCountdown
    $interval = date_diff($future_date, $now);
    if ($future_date < $now or $expire < $now) {
        // Open the first source image and add the text.
        $image = imagecreatefrompng('images/expired.png');
        ob_start();
        imagegif($image);
        $frames[] = ob_get_contents();
        $delays[] = $delay;
        $loops = 1;
        ob_end_clean();
        break;
    } else {
        // Open the first source image and add the text.
        $image = imagecreatefrompng('images/preview.png');
        $text = $interval->format('0%a:%H:%I:%S');
        imagettftextSp($image, $font['size'], $font['angle'], $font['x-offset'], $font['y-offset'], $font['color'], $font['file'], $text, 1);
        ob_start();
        imagegif($image);
        $frames[] = ob_get_contents();
        $delays[] = $delay;
        $loops = 0;
        ob_end_clean();
    }
    $now->modify('+1 second');
}
//expire this image instantly
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');