Esempio n. 1
1
function waterMark($fileInHD, $wmFile, $transparency = 50, $jpegQuality = 90, $margin = 5)
{
    $wmImg = imageCreateFromJPEG($wmFile);
    $jpegImg = imageCreateFromJPEG($fileInHD);
    // Water mark random position
    $wmX = (bool) rand(0, 1) ? $margin : imageSX($jpegImg) - imageSX($wmImg) - $margin;
    $wmY = (bool) rand(0, 1) ? $margin : imageSY($jpegImg) - imageSY($wmImg) - $margin;
    // Water mark process
    imageCopyMerge($jpegImg, $wmImg, $wmX, $wmY, 0, 0, imageSX($wmImg), imageSY($wmImg), $transparency);
    // Overwriting image
    ImageJPEG($jpegImg, $fileInHD, $jpegQuality);
}
Esempio n. 2
0
 public function createImage($text = '', $fontSize = 5)
 {
     // GD's built-in fonts are numbered from 1 - 5
     $font_size = $fontSize;
     // Calculate the appropriate image size
     $image_height = intval(imageFontHeight($font_size) * 2);
     $image_width = intval(strlen($text) * imageFontWidth($font_size) * 1.3);
     // Create the image
     $image = imageCreate($image_width, $image_height);
     // Create the colors to use in the image
     // gray background
     $back_color = imageColorAllocate($image, 216, 216, 216);
     // blue text
     $text_color = imageColorAllocate($image, 0, 0, 255);
     // black border
     $rect_color = imageColorAllocate($image, 0, 0, 0);
     // Figure out where to draw the text
     // (Centered horizontally and vertically
     $x = ($image_width - imageFontWidth($font_size) * strlen($text)) / 2;
     $y = ($image_height - imageFontHeight($font_size)) / 2;
     // Draw the text
     imageString($image, $font_size, $x, $y, $text, $text_color);
     // Draw a black border
     imageRectangle($image, 0, 0, imageSX($image) - 1, imageSY($image) - 1, $rect_color);
     // Send the image to the browser
     header('Content-Type: image/png');
     imagePNG($image);
     imageDestroy($image);
 }
Esempio n. 3
0
function malaslika($name, $filename, $new_w, $new_h)
{
    $system = explode('.', $name);
    if (preg_match('/jpg|jpeg/i', $system[1])) {
        $src_img = imagecreatefromjpeg($name);
    }
    if (preg_match('/png/i', $system[1])) {
        $src_img = imagecreatefrompng($name);
    }
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    if ($old_x > $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $old_y * ($new_h / $old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w = $old_x * ($new_w / $old_y);
        $thumb_h = $new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    $dst_img = imagecreatetruecolor($thumb_w, $thumb_h);
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    if (preg_match("/png/i", $system[1])) {
        imagepng($dst_img, $filename);
    } else {
        imagejpeg($dst_img, $filename);
    }
    imagedestroy($dst_img);
    imagedestroy($src_img);
}
Esempio n. 4
0
 private function imgSize()
 {
     if (!$this->error) {
         $this->img_heigth = imageSY($this->img);
         $this->img_width = imageSX($this->img);
     }
 }
Esempio n. 5
0
function resize($src, $dest, $new_width, $new_height)
{
    if (!file_exists($src)) {
        die('No source to sample picture: ' . $src);
    }
    $image_big = ImageCreateFromJpeg($src);
    $height = imageSY($image_big);
    $width = imageSX($image_big);
    $ratio_hor = 1;
    $ratio_ver = 1;
    if ($height > $new_height) {
        $ratio_ver = $new_height / $height;
    }
    if ($width > $new_width) {
        $ratio_hor = $new_width / $width;
    }
    $ratio = min($ratio_hor, $ratio_ver);
    $new_height = round($height * $ratio);
    $new_width = round($width * $ratio);
    $image_redim = imagecreatetruecolor($new_width, $new_height);
    #l'apercu de l'image (plus petite)
    imagecopyresampled($image_redim, $image_big, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    imagejpeg($image_redim, $dest, IMAGE_REDUCED_QUALITY);
    #ecrit l'apercu sur le disque
}
Esempio n. 6
0
function createLogo($name, $filename, $new_w, $new_h)
{
    $system = explode(".", $name);
    if (preg_match("/jpg|jpeg/", $system[1])) {
        $src_img = imagecreatefromjpeg($name);
    }
    if (preg_match("/png/", $system[1])) {
        $src_img = imagecreatefrompng($name);
    }
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    if ($old_x == $new_w) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    if ($old_x > $new_w) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    if ($old_x < $new_w) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    imagecopyresampled($dst_img, $src_img, 0, 0, 10, 0, $thumb_w, $thumb_h, $new_w, $new_h);
    if (preg_match("/png/", $system[1])) {
        imagepng($dst_img, $filename);
    } else {
        imagejpeg($dst_img, $filename);
    }
    imagedestroy($dst_img);
    imagedestroy($src_img);
}
Esempio n. 7
0
function createthumb($originalImage, $newName, $new_w, $new_h)
{
    $src_img = imagecreatefromjpeg($originalImage);
    $newName .= ".jpg";
    # Maintain proportions
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    if ($old_x > $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $old_y * ($new_h / $old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w = $old_x * ($new_w / $old_y);
        $thumb_h = $new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    # Create destination-image-resource
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    # Copy source-image-resource to destination-image-resource
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    # Create the final image from the destination-image-resource
    imagejpeg($dst_img, $newName);
    # Delete our image-resources
    imagedestroy($dst_img);
    imagedestroy($src_img);
    # Show results
    return $newName;
}
Esempio n. 8
0
 function createthumb($name, $filename, $new_w, $new_h)
 {
     $extention = pathinfo($name, PATHINFO_EXTENSION);
     if (preg_match('/jpg|jpeg/', $extention)) {
         $src_img = imagecreatefromjpeg($name);
     }
     if (preg_match('/png/', $extention)) {
         $src_img = imagecreatefrompng($name);
     }
     $old_x = imageSX($src_img);
     $old_y = imageSY($src_img);
     if ($old_x > $old_y) {
         $thumb_w = $new_w;
         $thumb_h = $old_y * ($new_h / $old_x);
     }
     if ($old_x < $old_y) {
         $thumb_w = $old_x * ($new_w / $old_y);
         $thumb_h = $new_h;
     }
     if ($old_x == $old_y) {
         $thumb_w = $new_w;
         $thumb_h = $new_h;
     }
     $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
     imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
     if (preg_match("/png/", $extention)) {
         imagepng($dst_img, $filename);
     } else {
         imagejpeg($dst_img, $filename);
     }
     imagedestroy($dst_img);
     imagedestroy($src_img);
 }
Esempio n. 9
0
function resize_image_crop($src_image, $width, $height)
{
    $src_width = imageSX($src_image);
    $src_height = imageSY($src_image);
    $width = $width <= 0 ? $src_width : $width;
    $height = $height <= 0 ? $src_height : $height;
    $prop_width = $src_width / $width;
    $prop_height = $src_height / $height;
    if ($prop_height > $prop_width) {
        $crop_width = $src_width;
        $crop_height = round($prop_width * $height);
        $srcX = 0;
        $srcY = round($src_height / 2) - round($crop_height / 2);
    } else {
        $crop_width = round($prop_height * $width);
        $crop_height = $src_height;
        $srcX = round($src_width / 2) - round($crop_width / 2);
        $srcY = 0;
    }
    $new_image = imageCreateTrueColor($width, $height);
    $tmp_image = imageCreateTrueColor($crop_width, $crop_height);
    imageCopy($tmp_image, $src_image, 0, 0, $srcX, $srcY, $crop_width, $crop_height);
    imageCopyResampled($new_image, $tmp_image, 0, 0, 0, 0, $width, $height, $crop_width, $crop_height);
    imagedestroy($tmp_image);
    image_unsharp_mask($new_image);
    return $new_image;
}
Esempio n. 10
0
function UploadImage($fupload_name)
{
    //direktori gambar
    $vdir_upload = "../../image/";
    $vfile_upload = $vdir_upload . $fupload_name;
    //Simpan gambar dalam ukuran sebenarnya
    move_uploaded_file($_FILES["file"]["tmp_name"], $vfile_upload);
    //identitas file asli
    $tipe_file = $_FILES['file']['type'];
    if ($tipe_file == "image/png") {
        $im_src = imagecreatefrompng($vfile_upload);
    } else {
        if ($tipe_file == "image/jpeg") {
            $im_src = imagecreatefromjpeg($vfile_upload);
        }
    }
    $src_width = imageSX($im_src);
    $src_height = imageSY($im_src);
    //Simpan dalam versi small 110 pixel
    //Set ukuran gambar hasil perubahan
    $small_width = 50;
    $small_height = $small_width / $src_width * $src_height;
    //proses perubahan ukuran
    $im = imagecreatetruecolor($small_width, $small_height);
    imagecopyresampled($im, $im_src, 0, 0, 0, 0, $small_width, $small_height, $src_width, $src_height);
    //Simpan gambar
    imagejpeg($im, $vdir_upload . "ttd_" . $fupload_name);
    //Hapus gambar di memori komputer
    imagedestroy($im_src);
    imagedestroy($im);
    unlink($vdir_upload . "" . $fupload_name);
}
function imageResize($file, $info, $destination)
{
    $height = $info[1];
    //высота
    $width = $info[0];
    //ширина
    //определяем размеры будущего превью
    $y = 150;
    if ($width > $height) {
        $x = $y * ($width / $height);
    } else {
        $x = $y / ($height / $width);
    }
    $to = imageCreateTrueColor($x, $y);
    switch ($info['mime']) {
        case 'image/jpeg':
            $from = imageCreateFromJpeg($file);
            break;
        case 'image/png':
            $from = imageCreateFromPng($file);
            break;
        case 'image/gif':
            $from = imageCreateFromGif($file);
            break;
        default:
            echo "No prevue";
            break;
    }
    imageCopyResampled($to, $from, 0, 0, 0, 0, imageSX($to), imageSY($to), imageSX($from), imageSY($from));
    imagepng($to, $destination);
    imagedestroy($from);
    imagedestroy($to);
}
Esempio n. 12
0
 public function run($file)
 {
     $res = $this->open_image($file);
     if ($res != TRUE) {
         return FALSE;
     }
     $this->image_progressive = isset($this->settings['field_settings']['progressive_jpeg']) === TRUE && $this->settings['field_settings']['progressive_jpeg'] == 'yes' ? TRUE : FALSE;
     if (function_exists('imagefilter') === TRUE) {
         @imagefilter($this->EE->channel_images->image, IMG_FILTER_GRAYSCALE);
     } else {
         $img_width = imageSX($this->EE->channel_images->image);
         $img_height = imageSY($this->EE->channel_images->image);
         // convert to grayscale
         $palette = array();
         for ($c = 0; $c < 256; $c++) {
             $palette[$c] = imagecolorallocate($this->EE->channel_images->image, $c, $c, $c);
         }
         for ($y = 0; $y < $img_height; $y++) {
             for ($x = 0; $x < $img_width; $x++) {
                 $rgb = imagecolorat($this->EE->channel_images->image, $x, $y);
                 $r = $rgb >> 16 & 0xff;
                 $g = $rgb >> 8 & 0xff;
                 $b = $rgb & 0xff;
                 $gs = $r * 0.299 + $g * 0.587 + $b * 0.114;
                 imagesetpixel($this->EE->channel_images->image, $x, $y, $palette[$gs]);
             }
         }
     }
     $this->save_image($file);
     return TRUE;
 }
 function imagecreator($filename)
 {
     $nx = 16;
     $ny = 8;
     $zoom = 4;
     $im = imageCreateFromJpeg("uploads/" . $filename);
     $temp_dir = "dir_{$filename}";
     mkdir("uploads/" . $temp_dir, 0744);
     $temp_dir = "uploads/" . $temp_dir;
     //return;
     $imSX = imageSX($im);
     $imSY = imageSY($im);
     $kusokX = $imSX / $nx;
     $kusokY = $imSY / $ny;
     for ($k = 0; $k < $ny; $k++) {
         for ($i = 0; $i < $nx; $i++) {
             $im2 = imagecreatetruecolor(512, 512);
             imagecopyresized($im2, $im, 0, 0, $i * $kusokX, $k * $kusokY, 512, 512, $kusokX, $kusokY);
             //imageInterlace($im2, 1);
             imagejpeg($im2, "{$temp_dir}/" . "1_{$zoom}_{$i}_{$k}_.jpeg", 90);
             $im2 = null;
         }
     }
     $factor = 2;
     $zoom = $zoom - 1;
     for ($k = 0; $k < $ny / $factor; $k++) {
         for ($i = 0; $i < $nx / $factor; $i++) {
             $im2 = imagecreatetruecolor(512, 512);
             imagecopyresized($im2, $im, 0, 0, $i * $kusokX * $factor, $k * $kusokY * $factor, 512, 512, $kusokX * $factor, $kusokY * $factor);
             //imageInterlace($im2, 1);
             imagejpeg($im2, "{$temp_dir}/" . "1_{$zoom}_{$i}_{$k}_.jpeg", 90);
             $im2 = null;
         }
     }
     $factor = 4;
     $zoom = $zoom - 1;
     for ($k = 0; $k < $ny / $factor; $k++) {
         for ($i = 0; $i < $nx / $factor; $i++) {
             $im2 = imagecreatetruecolor(512, 512);
             imagecopyresized($im2, $im, 0, 0, $i * $kusokX * $factor, $k * $kusokY * $factor, 512, 512, $kusokX * $factor, $kusokY * $factor);
             //imageInterlace($im2, 1);
             imagejpeg($im2, "{$temp_dir}/" . "1_{$zoom}_{$i}_{$k}_.jpeg", 90);
             $im2 = null;
         }
     }
     $factor = 8;
     $zoom = $zoom - 1;
     for ($k = 0; $k < $ny / $factor; $k++) {
         for ($i = 0; $i < $nx / $factor; $i++) {
             $im2 = imagecreatetruecolor(512, 512);
             imagecopyresized($im2, $im, 0, 0, $i * $kusokX * $factor, $k * $kusokY * $factor, 512, 512, $kusokX * $factor, $kusokY * $factor);
             //imageInterlace($im2, 1);
             imagejpeg($im2, "{$temp_dir}/" . "1_{$zoom}_{$i}_{$k}_.jpeg", 90);
             $im2 = null;
         }
     }
     $im2 = imagecreatetruecolor(512, 512);
     imagecopyresized($im2, $im, 0, 0, 0, 0, 512, 256, $imSX, $imSY);
     imagejpeg($im2, "{$temp_dir}/" . "1_0_0_0_.jpeg", 90);
 }
Esempio n. 14
0
 /**
  * function addWatermark
  *
  * @param string $imageFile
  * @param string $destinationFile
  */
 function addWatermark($imageFile, $destinationFile = true)
 {
     if ($destinationFile) {
         $destinationFile = $imageFile;
     }
     $watermark = @imagecreatefrompng($this->watermarkFile) or exit('Cannot open the watermark file.');
     imageAlphaBlending($watermark, false);
     imageSaveAlpha($watermark, true);
     $image_string = @file_get_contents($imageFile) or exit('Cannot open image file.');
     $image = @imagecreatefromstring($image_string) or exit('Not a valid image format.');
     $imageWidth = imageSX($image);
     $imageHeight = imageSY($image);
     $watermarkWidth = imageSX($watermark);
     $watermarkHeight = imageSY($watermark);
     if ($this->position == 'center') {
         $coordinate_X = ($imageWidth - $watermarkWidth) / 2;
         $coordinate_Y = ($imageHeight - $watermarkHeight) / 2;
     } else {
         $coordinate_X = $imageWidth - 5 - $watermarkWidth;
         $coordinate_Y = $imageHeight - 5 - $watermarkHeight;
     }
     imagecopy($image, $watermark, $coordinate_X, $coordinate_Y, 0, 0, $watermarkWidth, $watermarkHeight);
     if ($this->imageType == 'jpg') {
         imagejpeg($image, $destinationFile, 100);
     } elseif ($this->imageType == 'gif') {
         imagegif($image, $destinationFile);
     } elseif ($this->imageType == 'png') {
         imagepng($image, $destinationFile, 100);
     }
     imagedestroy($image);
     imagedestroy($watermark);
 }
Esempio n. 15
0
function UploadImage($bukti_name)
{
    //direktori gambar
    $vdir_upload = "bukti/";
    $vfile_upload = $vdir_upload . $bukti_name;
    //Simpan gambar dalam ukuran sebenarnya
    move_uploaded_file($_FILES["bukti"]["tmp_name"], $vfile_upload);
    //identitas file asli
    $im_src = imagecreatefromjpeg($vfile_upload);
    $src_width = imageSX($im_src);
    $src_height = imageSY($im_src);
    //Simpan dalam versi small 110 pixel
    //Set ukuran gambar hasil perubahan
    $dst_width = 50;
    $dst_height = $dst_width / $src_width * $src_height;
    //proses perubahan ukuran
    $im = imagecreatetruecolor($dst_width, $dst_height);
    imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
    //Simpan gambar
    imagejpeg($im, $vdir_upload . "small_" . $bukti_name);
    //Simpan dalam versi medium 360 pixel
    //Set ukuran gambar hasil perubahan
    $dst_width2 = 270;
    $dst_height2 = $dst_width2 / $src_width * $src_height;
    //proses perubahan ukuran
    $im2 = imagecreatetruecolor($dst_width2, $dst_height2);
    imagecopyresampled($im2, $im_src, 0, 0, 0, 0, $dst_width2, $dst_height2, $src_width, $src_height);
    //Simpan gambar
    imagejpeg($im2, $vdir_upload . "medium_" . $bukti_name);
    //Hapus gambar di memori komputer
    imagedestroy($im_src);
    imagedestroy($im);
    imagedestroy($im2);
}
Esempio n. 16
0
function resize($image, $width = false, $height = false)
{
    $original_width = imageSX($image);
    $original_height = imageSY($image);
    // ---------------------------------------------------------------------
    if ($height != false && is_numeric($height)) {
        $size["height"] = $height;
    } else {
        $size["height"] = $width * $original_height / $original_width;
    }
    // ---------------------------------------------------------------------
    if ($width != false && is_numeric($width)) {
        $size["width"] = $width;
    } else {
        $size["width"] = $height * $original_width / $original_height;
    }
    // ---------------------------------------------------------------------
    if ($original_width / $original_height > $size["width"] / $size["height"]) {
        // crop from either sides
        $rect_width = $original_height * ($size["width"] / $size["height"]);
        return crop($image, array("left" => ($original_width - $rect_width) / 2, "top" => 0, "width" => $rect_width, "height" => $original_height), array("width" => $size["width"], "height" => $size["height"]));
    } else {
        // crop from bottom
        $rect_height = $original_width * ($size["height"] / $size["width"]);
        return crop($image, array("left" => 0, "top" => 0, "width" => $original_width, "height" => $rect_height), array("width" => $size["width"], "height" => $size["height"]));
    }
}
Esempio n. 17
0
function createImage($name, $filename, $new_w, $new_h)
{
    $system2 = explode('.', strtolower(basename($filename)));
    $system2[1] = $system2[1];
    $src_img = imagecreatefromstring(readFileData($name));
    $old_w = imageSX($src_img);
    $old_h = imageSY($src_img);
    $thumb_w = $new_w;
    $thumb_h = $new_h;
    if ($new_w > $old_w) {
        $thumb_w = $old_w;
        $thumb_h = $thumb_w / $old_w * $old_h;
    } else {
        $thumb_w = $new_w;
        $thumb_h = $thumb_w / $old_w * $old_h;
    }
    if ($thumb_h > $new_h) {
        $thumb_h = $new_h;
        $thumb_w = $thumb_h / $old_h * $old_w;
    }
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    imagealphablending($dst_img, false);
    imagesavealpha($dst_img, true);
    $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127);
    imagefilledrectangle($dst_img, 0, 0, $thumb_w, $thumb_h, $transparent);
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_w, $old_h);
    if (preg_match("/png/", $system2[1])) {
        imagepng($dst_img, $filename);
    } else {
        imagejpeg($dst_img, $filename, 90);
    }
    imagedestroy($dst_img);
    imagedestroy($src_img);
}
Esempio n. 18
0
function ImageResize($fupload_name, $from_dir, $to_dir, $resize)
{
    //direktori gambar
    $vdir_upload = $from_dir;
    $vfile_upload = $vdir_upload . $fupload_name;
    //Simpan gambar dalam ukuran sebenarnya
    move_uploaded_file($_FILES["fupload"]["tmp_name"], $vfile_upload);
    //identitas file asli
    $im_src = imagecreatefromjpeg($vfile_upload);
    $src_width = imageSX($im_src);
    $src_height = imageSY($im_src);
    //Simpan dalam versi small 350 pixel
    //Set ukuran gambar hasil perubahan
    $dst_width = $resize;
    //perubahan ukuran gambar
    $dst_height = $dst_width / $src_width * $src_height;
    //proses perubahan ukuran
    $im = imagecreatetruecolor($dst_width, $dst_height);
    imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
    //Simpan gambar
    imagejpeg($im, $to_dir . "small_" . $fupload_name);
    //Hapus gambar di memori komputer
    imagedestroy($im_src);
    imagedestroy($im);
}
Esempio n. 19
0
 /**
  * Fill the canvas with the specified colosaver.
  *
  * @param Color $fillcolor The Color() to fill with.
  */
 function fillCanvas(Color $fillcolor)
 {
     $w = imageSX($this->himage);
     $h = imageSY($this->himage);
     imagealphablending($this->himage, false);
     imagefilledrectangle($this->himage, 0, 0, $w, $h, $fillcolor->getColor($this->himage, true));
     imagealphablending($this->himage, $this->canvas->alphablending);
 }
Esempio n. 20
0
 /**
  * @param int $x The X offset (positive values from left, negative from right)
  * @param int $y The Y offset (positive valeus from top, negative from bottom)
  * @param string $watermark The watermark image to apply
  * @param int $placement The placement method to use
  */
 function __construct($x, $y, $watermark, $placement = WatermarkImageFilter::POS_RELATIVE)
 {
     $this->hwatermark = imagecreatefromstring(file_get_contents($watermark));
     $this->x = $x;
     $this->y = $y;
     $this->placement = $placement;
     $this->width = imageSX($this->hwatermark);
     $this->height = imageSY($this->hwatermark);
 }
Esempio n. 21
0
 function background()
 {
     $this->im = imagecreatetruecolor($this->width, $this->height);
     $backgrounds = $c = array();
     if ($this->background && function_exists('imagecreatefromjpeg') && function_exists('imagecolorat') && function_exists('imagecopymerge') && function_exists('imagesetpixel') && function_exists('imageSX') && function_exists('imageSY')) {
         if ($handle = @opendir(PUBLIC_ROOT . './verify/background/')) {
             while ($bgfile = @readdir($handle)) {
                 if (preg_match('/\\.jpg$/i', $bgfile)) {
                     $backgrounds[] = PUBLIC_ROOT . './verify/background/' . $bgfile;
                 }
             }
             @closedir($handle);
         }
         if ($backgrounds) {
             $imwm = imagecreatefromjpeg($backgrounds[array_rand($backgrounds)]);
             $colorindex = imagecolorat($imwm, 0, 0);
             $c = imagecolorsforindex($imwm, $colorindex);
             $colorindex = imagecolorat($imwm, 1, 0);
             imagesetpixel($imwm, 0, 0, $colorindex);
             $c[0] = $c['red'];
             $c[1] = $c['green'];
             $c[2] = $c['blue'];
             imagecopymerge($this->im, $imwm, 0, 0, mt_rand(0, 200 - $this->width), mt_rand(0, 80 - $this->height), imageSX($imwm), imageSY($imwm), 100);
             imagedestroy($imwm);
         }
     }
     if (!$this->background || !$backgrounds) {
         for ($i = 0; $i < 3; $i++) {
             $start[$i] = mt_rand(200, 255);
             $end[$i] = mt_rand(100, 150);
             $step[$i] = ($end[$i] - $start[$i]) / $this->width;
             $c[$i] = $start[$i];
         }
         for ($i = 0; $i < $this->width; $i++) {
             $color = imagecolorallocate($this->im, $c[0], $c[1], $c[2]);
             imageline($this->im, $i, 0, $i, $this->height, $color);
             $c[0] += $step[0];
             $c[1] += $step[1];
             $c[2] += $step[2];
         }
         $c[0] -= 20;
         $c[1] -= 20;
         $c[2] -= 20;
     }
     ob_start();
     if (function_exists('imagepng')) {
         imagepng($this->im);
     } else {
         imagejpeg($this->im, '', 100);
     }
     imagedestroy($this->im);
     $bgcontent = ob_get_contents();
     ob_end_clean();
     $this->fontcolor = $c;
     return $bgcontent;
 }
Esempio n. 22
0
function createthumb($name, $target_w, $target_h, $transparency = true, $base64 = false)
{
    $arr = explode(".", $name);
    $ext = $arr[count($arr) - 1];
    if ($ext == "jpeg" || $ext == "jpg") {
        $img = @imagecreatefromjpeg($name);
    } elseif ($ext == "png") {
        $img = @imagecreatefrompng($name);
    } elseif ($ext == "gif") {
        $img = @imagecreatefromgif($name);
    } else {
        $img = imagecreatefromjpeg($name);
    }
    $oldw = imageSX($img);
    $oldh = imageSY($img);
    $neww;
    $newh;
    $x;
    $y;
    if ($oldw > $oldh) {
        $scale = $oldh / $oldw;
        $neww = $target_w;
        $newh = $neww * $scale;
        $x = 0;
        $y = ($target_h - $newh) / 2;
    } else {
        $scale = $oldw / $oldh;
        $newh = $target_h;
        $neww = $newh * $scale;
        $x = ($target_w - $neww) / 2;
        $y = 0;
    }
    $new_img = imagecreatetruecolor($target_w, $target_h);
    imagefill($new_img, 0, 0, imagecolorallocate($new_img, 255, 255, 255));
    imagecopyresampled($new_img, $img, $x, $y, 0, 0, $neww, $newh, $oldw, $oldh);
    if ($base64) {
        ob_start();
        imagepng($new_img);
        $img = ob_get_contents();
        ob_end_clean();
        $return = base64_encode($img);
    } else {
        if ($ext == "jpeg" || $ext == "jpg") {
            header('Content-Type: image/jpeg');
            imagejpeg($new_img);
            $return = true;
        } elseif ($ext == "png") {
            header('Content-Type: image/png');
            imagepng($new_img);
            $return = true;
        }
    }
    imagedestroy($new_img);
    imagedestroy($img);
    return $return;
}
Esempio n. 23
0
 function createThumbnail($imageName, $newWidth, $newHeight, $uploadDir, $moveToDir)
 {
     $path = $uploadDir . '/' . $imageName;
     $mime = getimagesize($path);
     if ($mime['mime'] == 'image/png') {
         $src_img = imagecreatefrompng($path);
     }
     if ($mime['mime'] == 'image/jpg') {
         $src_img = imagecreatefromjpeg($path);
     }
     if ($mime['mime'] == 'image/jpeg') {
         $src_img = imagecreatefromjpeg($path);
     }
     if ($mime['mime'] == 'image/pjpeg') {
         $src_img = imagecreatefromjpeg($path);
     }
     $old_x = imageSX($src_img);
     $old_y = imageSY($src_img);
     if ($old_x > $old_y) {
         $thumb_w = $newWidth;
         $thumb_h = $old_y / $old_x * $newWidth;
     }
     if ($old_x < $old_y) {
         $thumb_w = $old_x / $old_y * $newHeight;
         $thumb_h = $newHeight;
     }
     if ($old_x == $old_y) {
         $thumb_w = $newWidth;
         $thumb_h = $newHeight;
     }
     $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
     /* for png black background error Start */
     imagealphablending($dst_img, false);
     imagesavealpha($dst_img, true);
     $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127);
     imagefilledrectangle($dst_img, 0, 0, $thumb_w, $thumb_h, $transparent);
     /* for png black background error end */
     imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
     // New save location
     $new_thumb_loc = $moveToDir . $imageName;
     if ($mime['mime'] == 'image/png') {
         $result = imagepng($dst_img, $new_thumb_loc, 9);
     }
     if ($mime['mime'] == 'image/jpg') {
         $result = imagejpeg($dst_img, $new_thumb_loc, 100);
     }
     if ($mime['mime'] == 'image/jpeg') {
         $result = imagejpeg($dst_img, $new_thumb_loc, 100);
     }
     if ($mime['mime'] == 'image/pjpeg') {
         $result = imagejpeg($dst_img, $new_thumb_loc, 100);
     }
     imagedestroy($dst_img);
     imagedestroy($src_img);
     return $result;
 }
Esempio n. 24
0
 function createPoster($imageName)
 {
     $newWidth = 1980;
     $newHeight = 562;
     $mime = getimagesize($imageName);
     if ($mime['mime'] == 'image/png') {
         $src_img = imagecreatefrompng($imageName);
     }
     if ($mime['mime'] == 'image/jpg') {
         $src_img = imagecreatefromjpeg($imageName);
     }
     if ($mime['mime'] == 'image/jpeg') {
         $src_img = imagecreatefromjpeg($imageName);
     }
     if ($mime['mime'] == 'image/pjpeg') {
         $src_img = imagecreatefromjpeg($imageName);
     }
     $old_x = imageSX($src_img);
     $old_y = imageSY($src_img);
     if ($old_x > $old_y) {
         $thumb_w = $newWidth;
         $thumb_h = $old_y / $old_x * $newWidth;
     }
     if ($old_x < $old_y) {
         $thumb_w = $old_x / $old_y * $newHeight;
         $thumb_h = $newHeight;
     }
     if ($old_x == $old_y) {
         $thumb_w = $newWidth;
         $thumb_h = $newHeight;
     }
     $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
     imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
     if ($mime['mime'] == 'image/png') {
         $result = imagepng($dst_img, $imageName, 8);
     }
     if ($mime['mime'] == 'image/jpg') {
         $result = imagejpeg($dst_img, $imageName, 80);
     }
     if ($mime['mime'] == 'image/jpeg') {
         $result = imagejpeg($dst_img, $imageName, 80);
     }
     if ($mime['mime'] == 'image/pjpeg') {
         $result = imagejpeg($dst_img, $imageName, 80);
     }
     imagedestroy($dst_img);
     imagedestroy($src_img);
     if ($thumb_w != $newWidth) {
         Image::crop($imageName, $newWidth, $newHeight, [($thumb_w - $newWidth) / 2, 0])->save($imageName, ['quality' => 80]);
     }
     if ($thumb_h != $newHeight) {
         Image::crop($imageName, $newWidth, $newHeight, [0, ($thumb_h - $newHeight) / 2])->save($imageName, ['quality' => 80]);
     }
 }
Esempio n. 25
0
function make_thumb_w($src_img, $to_image, $new_w, $ext)
{
    $old_y = imageSY($src_img);
    $old_x = imageSX($src_img);
    if ($old_x < $new_w || $new_w == 0) {
        $new_w = $old_x;
    }
    $thumb_w = $new_w;
    $thumb_h = $old_y / ($old_x / $new_w);
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    return $dst_img;
}
Esempio n. 26
0
 /**
  * @see	\wcf\system\image\adapter\IImageAdapter::load()
  */
 public function load($image, $type = '')
 {
     if (!is_resource($image)) {
         throw new SystemException("Image resource is invalid.");
     }
     if (empty($type)) {
         throw new SystemException("Image type is missing.");
     }
     $this->image = $image;
     $this->type = $type;
     $this->height = imageSY($this->image);
     $this->width = imageSX($this->image);
 }
Esempio n. 27
0
function create_thumb($path, $new_path, $new_w, $new_h)
{
    // TO-DO: Need to verify path, need to use some faster library for resizing, this is slooow..
    $src_img = imagecreatefromjpeg($path);
    $dst_img = ImageCreateTrueColor($new_w, $new_h);
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, $old_x, $old_y);
    imagejpeg($dst_img, $new_path);
    imagedestroy($dst_img);
    imagedestroy($src_img);
    return $new_path;
}
Esempio n. 28
0
function make_thumb($img_name, $filename, $new_w, $new_h)
{
    //get image extension.
    $ext = getExtension($img_name);
    $ext = strtolower($ext);
    //creates the new image using the appropriate function from gd library
    if (!strcmp("jpg", $ext) || !strcmp("jpeg", $ext)) {
        $src_img = imagecreatefromjpeg($img_name);
    }
    if (!strcmp("png", $ext)) {
        $src_img = imagecreatefrompng($img_name);
    }
    if (!strcmp("gif", $ext)) {
        $src_img = imagecreatefromgif($img_name);
    }
    if (!strcmp("bmp", $ext)) {
        $src_img = imagecreatefromwbmp($img_name);
    }
    //gets the dimmensions of the image
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    // next we will calculate the new dimmensions for the thumbnail image
    // the next steps will be taken:
    //     1. calculate the ratio by dividing the old dimmensions with the new ones
    //    2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable
    //        and the height will be calculated so the image ratio will not change
    //    3. otherwise we will use the height ratio for the image
    // as a result, only one of the dimmensions will be from the fixed ones
    $ratio1 = $old_x / $new_w;
    $ratio2 = $old_y / $new_h;
    if ($ratio1 > $ratio2) {
        $thumb_w = $new_w;
        $thumb_h = $old_y / $ratio1;
    } else {
        $thumb_h = $new_h;
        $thumb_w = $old_x / $ratio2;
    }
    // we create a new image with the new dimmensions
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    // resize the big image to the new created one
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    // output the created image to the file. Now we will have the thumbnail into the file named by $filename
    if (!strcmp("png", $ext)) {
        imagepng($dst_img, $filename);
    } else {
        imagejpeg($dst_img, $filename);
    }
    //destroys source and destination images.
    imagedestroy($dst_img);
    imagedestroy($src_img);
}
 public function generate($name, $colorScheme, $backgroundStyle)
 {
     list($bgColor1, $bgColor2, $textColor) = self::$colorSchemes[$colorScheme];
     $this->avatar = imageCreateTrueColor($this->width, $this->height);
     imageFill($this->avatar, 0, 0, $bgColor1);
     // Draw some random chars into the background. Unlike the other GD drawing functions
     // (imageFilledArc, imageFilledPolygon etc.) imageTTFText is anti-aliased.
     $sizeFactor = $this->width / 40;
     switch ($backgroundStyle) {
         case 0:
             imageTTFText($this->avatar, 190 * $sizeFactor, 10, 0, 35 * $sizeFactor, $bgColor2, $this->fontFace, 'O');
             break;
         case 1:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 45 * $sizeFactor, $bgColor2, $this->fontFace, 'o');
             break;
         case 2:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 30 * $sizeFactor, $bgColor2, $this->fontFace, '>');
             break;
         case 3:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 45 * $sizeFactor, $bgColor2, $this->fontFace, '//');
             break;
     }
     // Draw the first few chars of the name
     imageTTFText($this->avatar, $this->fontSize, 0, 4, $this->height - $this->fontSize / 2, $textColor, $this->fontFace, mb_substr($name, 0, $this->chars));
     // Copy the overlay on top
     if ($this->overlay) {
         imageCopy($this->avatar, $this->overlay, 0, 0, 0, 0, imageSX($this->overlay), imageSY($this->overlay));
     }
 }
function createthumb($originalImage, $new_w, $new_h)
{
    $src_img = imagecreatefromjpeg("uploads/" . $originalImage);
    # Add the _t to our image name
    list($imageName, $extension) = explode(".", $originalImage);
    $newName = $imageName . "_t." . $extension;
    # Maintain proportions
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    if ($old_x > $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $old_y * ($new_h / $old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w = $old_x * ($new_w / $old_y);
        $thumb_h = $new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    # Create destination-image-resource
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    # Copy source-image-resource to destination-image-resource
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    # Create the final image from the destination-image-resource
    imagejpeg($dst_img, "uploads/" . $newName);
    # Delete our image-resources
    imagedestroy($dst_img);
    imagedestroy($src_img);
    # Show results
    return $newName;
}