case "image/png":
        case "image/x-png":
            $im = imagecreatefrompng($file);
            //png file
            imagefill($im2, 0, 0, imagecolorallocate($im2, 255, 255, 255));
            imagealphablending($im2, TRUE);
            break;
        default:
            $im = false;
            break;
    }
    //calculate new image dimensions (preserve aspect)
    if ($width > $height) {
        $new_height = $_size;
        $new_width = $width / $height * $new_height;
        $x = ($width - $height) / 2;
        $y = 0;
    } else {
        $new_width = $_size;
        $new_height = $height / $width * $new_width;
        $y = ($height - $width) / 2;
        $x = 0;
    }
    imagecopyresampled($im2, $im, 0, 0, $x, $y, $new_width, $new_height, $width, $height);
    return $im2;
}
// ---End Function
$img = LoadJpeg($url, $typeMime, $width, $height);
imagejpeg($img);
imagedestroy($img);
//imagedestroy($image);
Пример #2
0
        /* Output an errmsg */
        ImageString($im, 1, 5, 5, "Error {$imgname}", $tc);
    }
    return $im;
}
$id = $filename;
$sz = $size;
$savefile = "tempimg/" . time() . ".jpg";
$ch = curl_init($id);
$fp = fopen($savefile, "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
$im = LoadJpeg($savefile);
// output
$im_width = imageSX($im);
$im_height = imageSY($im);
// work out new sizes
if ($im_width >= $im_height) {
    $factor = $sz / $im_width;
    $new_width = $sz;
    $new_height = $im_height * $factor;
} else {
    $factor = $sz / $im_height;
    $new_height = $sz;
    $new_width = $im_width * $factor;
}
// resize
$new_im = ImageCreate($new_width, $new_height);
Пример #3
0
<?php

function LoadJpeg($imgname)
{
    /* Attempt to open */
    $im = imagecreatefromjpeg($imgname);
    /* See if it failed */
    if (!$im) {
        /* Create a black image */
        $im = imagecreatetruecolor(150, 30);
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc = imagecolorallocate($im, 0, 0, 0);
        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
        /* Output an error message */
        imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }
    return $im;
}
header('Content-Type: image/jpeg');
$img = LoadJpeg('Origin.jpg');
imagejpeg($img);
imagedestroy($img);
Пример #4
0
        /* Creo un'immagine nera */
        $bgc = imagecolorallocate($im, 255, 255, 255);
        /* Imposto il colore di background */
        $tc = imagecolorallocate($im, 0, 0, 0);
        /* Imposto l'altro colore */
        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
        /* creo un rettangolo pieno */
        /* Output messaggio di errore se l'immagine non viene caricata */
        imagestring($im, 1, 5, 5, "Error loading {$imgname}", $tc);
    }
    /* Output dell'immagine */
    return $im;
}
##########################################################
// carico l'immagine jpg
$img = LoadJpeg($_GET['path']);
// controllo le dimensioni dell'immagine
$fullsize_width = imagesx($img);
$fullsize_height = imagesy($img);
// Assegno la dimensione massima per il resize
$max_dim = 240;
// Assegno il colore di sfondo
$bg = '#ffffff';
//Trovo la dimensione per il thumb
if ($fullsize_width >= $fullsize_height) {
    $small_width = $max_dim;
    //dimensione della larghezza l'altezza viene fatta in proporzione
    $small_height = floor($fullsize_height / ($fullsize_width / $small_width));
    $dist_height = ($max_dim - $small_height) / 2;
    $dist_width = 0;
} else {
Пример #5
0
<?php

include_once "central/config.php";
function LoadJpeg($imgname)
{
    /* Attempt to open */
    $im = @imagecreatefromjpeg($imgname);
    /* See if it failed */
    if (!$im) {
        /* Create a black image */
        $im = imagecreatetruecolor(150, 30);
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc = imagecolorallocate($im, 0, 0, 0);
        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
        /* Output an error message */
        imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }
    return $im;
}
//echo $img_path."users/".$_REQUEST["imgid"];
header('Content-Type: image/jpeg');
if (strpos($_REQUEST["imgid"], ".jpg") > 0 && file_exists($img_path . "users/" . $_REQUEST["imgid"])) {
    $img = LoadJpeg($img_path . "users/" . $_REQUEST["imgid"]);
    imagejpeg($img);
    imagedestroy($img);
} else {
    $img = LoadJpeg($img_path . "/users/noimage.jpg");
    imagejpeg($img);
    imagedestroy($img);
}
Пример #6
0
}
function AllocateColorByHex($Image, $Hex)
{
    $Hex = str_replace('#', $Hex);
    $Hex = split($Hex, 2);
    return imagecolorallocate($Image, $Hex[0], $Hex[1], $Hex[2]);
}
// Create a 300x100 image
$img = imagecreatetruecolor(400, 25);
$white = imagecolorallocate($img, 0xff, 0xff, 0xff);
$black = imagecolorallocate($img, 0x0, 0x0, 0x0);
// Make the background red
imagefilledrectangle($img, 0, 0, 399, 15, $white);
// Path to our ttf font file
$fontbold = './fontbold.ttf';
$background = LoadJpeg('./rainbowsmoke.jpg');
imagecopy($img, $background, 0, 0, rand(1, 600), rand(1, 300), 400, 25);
if ($_GET['text']) {
    $_GET['word'] = $_GET['text'];
}
$Word = stripslashes($_GET['word']);
if (empty($Word)) {
    $Word = 'Rachel should learn how to program.';
}
imagefttext($img, 13, 0, 17, 17, $white, $fontbold, $Word);
imagefttext($img, 13, 0, 16, 16, $black, $fontbold, $Word);
# Output image to the browser
header('Content-Type: image/jpg');
imagejpeg($img);
imagedestroy($img);
imagedestroy($background);
<?php

session_start();
if ($_SESSION['session_number'] == $_GET["id"]) {
    function LoadJpeg($imgname)
    {
        /* Attempt to open */
        $im = @imagecreatefromjpeg($imgname);
        /* See if it failed */
        if (!$im) {
            /* Create a black image */
            $im = imagecreatetruecolor(150, 30);
            $bgc = imagecolorallocate($im, 255, 255, 255);
            $tc = imagecolorallocate($im, 0, 0, 0);
            imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
            /* Output an error message */
            imagestring($im, 10, 50, 50, 'Error loading ' . $imgname, $tc);
        }
        return $im;
    }
    header('Content-Type: image/jpeg');
    $img = LoadJpeg($_SESSION['link']);
    imagejpeg($img);
    imagedestroy($img);
    //session_destroy();
} else {
    echo "error!";
    //session_destroy();
}
Пример #8
0
<?php

require_once '../../config.php';
$courseid = optional_param('courseid', 0, PARAM_INT);
$updir = "{$courseid}/presentation/temp";
$imagepath = $CFG->dataroot . "/" . $updir . "/s_" . $_GET['id'] . ".jpg";
function LoadJpeg($imgname)
{
    /* Attempt to open */
    $im = @imagecreatefromjpeg($imgname);
    /* See if it failed */
    if (!$im) {
        /* Create a black image */
        $im = imagecreatetruecolor(150, 30);
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc = imagecolorallocate($im, 0, 0, 0);
        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
        /* Output an error message */
        imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }
    return $im;
}
header('Content-Type: image/jpeg');
$img = LoadJpeg($imagepath);
imagejpeg($img);
imagedestroy($img);