Example #1
2
 function generateImage($token)
 {
     $iFont = 5;
     // Font ID
     $iSpacing = 2;
     // Spacing between characters
     $iDisplacement = 5;
     // Vertical chracter displacement
     // Establish font metric and image size
     $iCharWidth = ImageFontWidth($iFont);
     $iCharHeight = ImageFontHeight($iFont);
     $iWidth = strlen($token) * ($iCharWidth + $iSpacing);
     $iHeight = $iCharHeight + 2 * $iDisplacement;
     // Create the image
     $pic = ImageCreate($iWidth, $iHeight);
     // Allocate a background and foreground colour
     $col = array('white' => ImageColorAllocate($pic, 255, 255, 255), 'blue' => ImageColorAllocate($pic, 45, 45, 100), 'green' => ImageColorAllocate($pic, 45, 100, 45), 'red' => ImageColorAllocate($pic, 100, 45, 45), 'purple' => ImageColorAllocate($pic, 100, 45, 100), 'grey' => ImageColorAllocate($pic, 225, 225, 225), 'grey2' => ImageColorAllocate($pic, 200, 200, 200));
     for ($x = 0; $x < $iWidth; $x += 2) {
         for ($y = 0; $y < $iHeight; $y += 2) {
             ImageSetPixel($pic, $x, $y, $col['grey']);
         }
     }
     $iX = 1;
     for ($i = 0; $i < strlen($token); $i++) {
         ImageChar($pic, $iFont - 1, $iX, $iDisplacement - rand(-$iDisplacement, $iDisplacement), $token[$i], $col['grey2']);
         $iX += $iCharWidth + $iSpacing;
     }
     $iX = 2;
     $c = array('blue', 'green', 'red', 'purple');
     for ($i = 0; $i < strlen($token); $i++) {
         $colour = $c[rand(0, count($c) - 1)];
         ImageChar($pic, $iFont, $iX, $iDisplacement - rand(-$iDisplacement, $iDisplacement), $token[$i], $col[$colour]);
         $iX += $iCharWidth + $iSpacing;
     }
     for ($x = 1; $x < $iWidth; $x += 4) {
         for ($y = 1; $y < $iHeight; $y += 4) {
             ImageSetPixel($pic, $x, $y, $col['white']);
         }
     }
     // Draw some lines
     for ($i = 0; $i < 4; $i++) {
         ImageLine($pic, rand(0, $iWidth / 2), rand(0, $iHeight / 2), rand($iWidth / 2, $iWidth), rand($iHeight / 2, $iHeight), $col['white']);
     }
     ob_start();
     if (function_exists('imagejpeg')) {
         ImageJPEG($pic);
     } elseif (function_exists('imagepng')) {
         ImagePNG($pic);
     } else {
         ob_end_clean();
         return false;
     }
     $data = ob_get_contents();
     ob_end_clean();
     ImageDestroy($pic);
     return $data;
 }
Example #2
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);
}
function thumbnail($PicPathIn, $PicPathOut, $PicFilenameIn, $PicFilenameOut, $neueHoehe, $Quality)
{
    // Bilddaten ermitteln
    $size = getimagesize("{$PicPathIn}" . "{$PicFilenameIn}");
    $breite = $size[0];
    $hoehe = $size[1];
    $neueBreite = intval($breite * $neueHoehe / $hoehe);
    if ($size[2] == 1) {
        // GIF
        $altesBild = ImageCreateFromGIF("{$PicPathIn}" . "{$PicFilenameIn}");
        $neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
        imageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
    }
    if ($size[2] == 2) {
        // JPG
        $altesBild = ImageCreateFromJPEG("{$PicPathIn}" . "{$PicFilenameIn}");
        $neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
        ImageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
    }
    if ($size[2] == 3) {
        // PNG
        $altesBild = ImageCreateFromPNG("{$PicPathIn}" . "{$PicFilenameIn}");
        $neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
        ImageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
    }
}
Example #4
0
function resize($src,$dst,$dstw,$dsth,$scala,$percorsosave) {

	$src = $percorsosave.$src;
	$dst = $percorsosave.$dst;
	list($width, $height, $type, $attr) = getimagesize($src);
    switch($type){
      case 1:$im = imagecreatefromgif($src);break;
      case 2:$im = imagecreatefromjpeg($src);break;
      case 3:$im = imagecreatefrompng($src);break;
      case 8:$im = imagecreatefromwbmp($src);break;
      default:break;
    }
	If ($dstw == "0" && $dsth == "0") { 
			$dstw = $width;
			$dsth = $height;
	}
	switch($scala){
		//scala in base alla lunghezza
		case 1:
			$dsth=($height*$dstw)/$width;
			break;
		//scala in base all'altezza
		case 2:
			$dstw=($width*$dsth)/$height;
			break;
		default:break;
	};
	$tim = imagecreatetruecolor($dstw,$dsth);	
    imagesavealpha($tim,true);
    imagealphablending($tim,false);
    imagecopyresampled($tim,$im,0,0,0,0,$dstw,$dsth,$width,$height);
    ImageJPEG($tim,$dst,90);
    imagedestroy($tim);
}
Example #5
0
 function SaveImage($im, $filename)
 {
     $res = null;
     // ImageGIF is not included into some GD2 releases, so it might not work
     // output png if gifs are not supported
     if ($this->image_type == 1 && !function_exists('imagegif')) {
         $this->image_type = 3;
     }
     switch ($this->image_type) {
         case 1:
             if ($this->save_to_file) {
                 header("Content-type: image/gif");
                 $res = ImageGIF($im, $filename);
                 $res = ImageGIF($im, NULL);
             } else {
                 header("Content-type: image/gif");
                 $res = ImageGIF($im, $filename);
                 $res = ImageGIF($im, NULL);
             }
             break;
         case 2:
             if ($this->save_to_file) {
                 header("Content-type: image/jpeg");
                 $res = ImageJPEG($im, $filename, $this->quality);
                 $res = ImageJPEG($im, NULL, $this->quality);
             } else {
                 header("Content-type: image/jpeg");
                 $res = ImageJPEG($im, $filename, $this->quality);
                 $res = ImageJPEG($im, NULL, $this->quality);
             }
             break;
         case 3:
             if (PHP_VERSION >= '5.1.2') {
                 // Convert to PNG quality.
                 // PNG quality: 0 (best quality, bigger file) to 9 (worst quality, smaller file)
                 $quality = 9 - min(round($this->quality / 10), 9);
                 if ($this->save_to_file) {
                     header("Content-type: image/png");
                     $res = ImagePNG($im, $filename, $quality);
                     $res = ImagePNG($im, NULL, $quality);
                 } else {
                     header("Content-type: image/png");
                     $res = ImagePNG($im, $filename, $quality);
                     $res = ImagePNG($im, NULL, $quality);
                 }
             } else {
                 if ($this->save_to_file) {
                     header("Content-type: image/png");
                     $res = ImagePNG($im, $filename);
                     $res = ImagePNG($im);
                 } else {
                     header("Content-type: image/png");
                     $res = ImagePNG($im, $filename);
                     $res = ImagePNG($im);
                 }
             }
             break;
     }
     return $res;
 }
Example #6
0
function Resampling($tmp_name, $directorio, $name)
{
    // Indico el destino del directorio de la imagen
    $imagen_origen = ImageCreateFromJPEG($tmp_name);
    // Calculo el tamaño de la imagen original
    $tam_ancho = imagesx($imagen_origen);
    $tam_alto = imagesy($imagen_origen);
    //Calculo la medida que va a tener
    if ($tam_ancho >= $tam_alto) {
        $ancho = 38;
        $alto = 38 * $tam_alto / $tam_ancho;
    } else {
        $ancho = 38 * $tam_ancho / $tam_alto;
        $alto = 38;
    }
    //Creo una imagen
    $imagen_destino = ImageCreateTrueColor($ancho, $alto);
    //Resize
    imagecopyresized($imagen_destino, $imagen_origen, 0, 0, 0, 0, $ancho, $alto, $tam_ancho, $tam_alto);
    $nombre_destino = $directorio . $name;
    //Genero Copia Destino
    ImageJPEG($imagen_destino, $nombre_destino, 100);
    //Borro imagen virtual
    ImageDestroy($imagen_destino);
}
Example #7
0
 /**
  * Функция сохраняет изображение из дескриптора в файл, в соответствии с типом изображения
  * Тип изображения берется из свойств класса
  * 
  * @param (resource) $resImage - дескриптор (идентификатор) изображения
  * @param (string) $newImg - имя файла, в который сохранить изображение (формат: путь/имя_файла)
  * 
  * @return bool
  */
 static function saveImgToFile($resImage, $newImg)
 {
     // определяем тип изображени и сохраняем его в файл
     switch (self::$arrImgSubj['type']) {
         case '1':
             if (@ImageGIF($resImage, $newImg)) {
                 return true;
             } else {
                 self::setError(ERROR_FILE_NOT_SAVED);
                 return false;
             }
             break;
         case '2':
             if (@ImageJPEG($resImage, $newImg, 80)) {
                 return true;
             } else {
                 self::setError(ERROR_FILE_NOT_SAVED);
                 return false;
             }
             break;
         case '3':
             if (@ImagePNG($resImage, $newImg)) {
                 return true;
             } else {
                 self::setError(ERROR_FILE_NOT_SAVED);
                 return false;
             }
             break;
     }
     self::setError(ERROR_FILE_NOT_SAVED);
     return false;
 }
 public function update_picture()
 {
     if (trim($_FILES["myfile"]["tmp_name"]) != "") {
         $images = $_FILES["myfile"]["tmp_name"];
         $new_images = "thumb_" . $this->session->userdata('std_cardid') . '_' . $_FILES["myfile"]["name"];
         copy($_FILES["myfile"]["tmp_name"], "assets/uploads/photo/" . $_FILES["myfile"]["name"]);
         $width = 150;
         //*** Fix Width & Heigh (Autu caculate) ***//
         $size = GetimageSize($images);
         $height = round($width * $size[1] / $size[0]);
         $images_orig = ImageCreateFromJPEG($images);
         $photoX = ImagesX($images_orig);
         $photoY = ImagesY($images_orig);
         $images_fin = ImageCreateTrueColor($width, $height);
         ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
         ImageJPEG($images_fin, "assets/uploads/photo/" . $new_images);
         ImageDestroy($images_orig);
         ImageDestroy($images_fin);
     }
     $fileName = $_FILES["myfile"]["name"];
     $ret[] = $fileName;
     $data_picture = array('std_picture' => $new_images);
     $this->Students_model->update_student_picture($this->session->userdata('std_cardid'), $data_picture);
     //echo  base_url()."assets/uploads/photo/".$new_images;
     redirect('/front_profiles/student_edit', 'refresh');
     //ChromePhp::log($ret);
     //exit;
 }
Example #9
0
 public function fixOrientation()
 {
     if (exif_imagetype($this->image) == 2) {
         $exif = exif_read_data($this->image);
         if (array_key_exists('Orientation', $exif)) {
             $orientation = $exif['Orientation'];
             $images_orig = ImageCreateFromJPEG($this->image);
             $rotate = "";
             switch ($orientation) {
                 case 3:
                     $rotate = imagerotate($images_orig, 180, 0);
                     break;
                 case 6:
                     $rotate = imagerotate($images_orig, -90, 0);
                     break;
                 case 8:
                     $rotate = imagerotate($images_orig, 90, 0);
                     break;
             }
             if ($rotate != "") {
                 ImageJPEG($rotate, $this->image);
                 ImageDestroy($rotate);
             }
             ImageDestroy($images_orig);
         }
     }
 }
Example #10
0
function marcadeagua($img_original, $img_marcadeagua, $img_nueva, $calidad)
{
    // obtener datos de la fotografia
    $info_original = getimagesize($img_original);
    $anchura_original = $info_original[0];
    $altura_original = $info_original[1];
    // obtener datos de la "marca de agua"
    $info_marcadeagua = getimagesize($img_marcadeagua);
    $anchura_marcadeagua = $info_marcadeagua[0];
    $altura_marcadeagua = $info_marcadeagua[1];
    // calcular la posición donde debe copiarse la "marca de agua" en la fotografia
    /* 
    // Posicion: Centrado
    $horizmargen = ($anchura_original - $anchura_marcadeagua)/2; 
    $vertmargen = ($altura_original - $altura_marcadeagua)/2; 
    */
    // Posicion: abajo a la izquierda
    $horizmargen = 10;
    $vertmargen = $altura_original - $altura_marcadeagua - 10;
    // crear imagen desde el original
    $original = ImageCreateFromJPEG($img_original);
    ImageAlphaBlending($original, true);
    // crear nueva imagen desde la marca de agua
    $marcadeagua = ImageCreateFromPNG($img_marcadeagua);
    // copiar la "marca de agua" en la fotografia
    ImageCopy($original, $marcadeagua, $horizmargen, $vertmargen, 0, 0, $anchura_marcadeagua, $altura_marcadeagua);
    // guardar la nueva imagen
    ImageJPEG($original, $img_nueva, $calidad);
    // cerrar las imágenes
    ImageDestroy($original);
    ImageDestroy($marcadeagua);
}
function twMachThumbnail($serverPfad, $datei, $breiteThumb, $prefix)
{
    // Bild-Datei (mit Pfad)
    $bildDatei = $serverPfad . $datei;
    // wenn dieses Bild nich gefunden wurde: Abbruch
    if (!file_exists($bildDatei)) {
        return false;
    }
    // wenn dieses Bild schon ein Thumbnail ist: Abbruch
    if (substr($datei, 0, strlen($prefix)) == $prefix) {
        //echo $datei. "<br />";
        //echo strlen($prefix). "<br />";
        //echo $prefix. "<br />";
        //echo substr($datei, strlen($prefix)). "<br />";
        //echo "-----<br />";
        return false;
    }
    // Bilddaten zu dieser Bild-Datei
    $bilddaten = getimagesize($bildDatei);
    $imgOrigBreite = $bilddaten[0];
    $imgOrigHoehe = $bilddaten[1];
    $imgOrigTyp = $bilddaten[2];
    // (1=GIF, 2=JPG, 3=PNG, 4=SWF)
    if ($imgOrigBreite < $breiteThumb) {
        $breiteThumb = $imgOrigBreite;
    }
    $Skalierungsfaktor = $imgOrigBreite / $breiteThumb;
    $thumbHoehe = intval($imgOrigHoehe / $Skalierungsfaktor);
    // wenn es ein gif-Bild ist
    if ($imgOrigTyp == 1) {
        $Originalgrafik = ImageCreateFromGIF($bildDatei);
        $Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
        ImageGIF($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
    } elseif ($imgOrigTyp == 2) {
        $Originalgrafik = ImageCreateFromJPEG($bildDatei);
        $Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
        ///ImageJPEG($Thumbnailgrafik, $pfad."thumb_".$bild);
        ImageJPEG($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
    } elseif ($imgOrigTyp == 3) {
        $Originalgrafik = ImageCreateFromPNG($bildDatei);
        $Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
        ImagePNG($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
    } else {
        return false;
    }
    // Speicher leeren
    if ($Originalgrafik) {
        imagedestroy($Originalgrafik);
    }
    if ($Thumbnailgrafik) {
        imagedestroy($Thumbnailgrafik);
    }
}
Example #12
0
 /**
  * Get image
  * @params string
  **/
 function getImage($val)
 {
     $document =& JFactory::getDocument();
     $document->setMimeEncoding('image/jpg');
     $im = @imagecreatetruecolor(100, 40) or die('Cannot create image');
     $text_color = imagecolorallocate($im, 233, 14, 91);
     Imagestring($im, 1, 5, 5, $val, $text_color);
     @ImageJPEG($img, null, 100);
     Imagedestroy($im);
 }
 function Resize($maxwidth = 10000, $maxheight, $imagename, $filetype, $how = 'keep_aspect')
 {
     $target_temp_file = tempnam("jinn/temp", "gdlib_");
     unlink($target_temp_file);
     $target_temp_file .= '.' . $filetype;
     if (!$maxheight) {
         $maxheight = 10000;
     }
     if (!$maxwidth) {
         $maxwidth = 10000;
     }
     $qual = 100;
     $filename = $imagename;
     $ext = $filetype;
     list($curwidth, $curheight) = getimagesize($filename);
     $factor = min($maxwidth / $curwidth, $maxheight / $curheight);
     $sx = 0;
     $sy = 0;
     $sw = $curwidth;
     $sh = $curheight;
     $dx = 0;
     $dy = 0;
     $dw = $curwidth * $factor;
     $dh = $curheight * $factor;
     if ($ext == "JPEG") {
         $src = ImageCreateFromJPEG($filename);
     }
     if ($ext == "GIF") {
         $src = ImageCreateFromGIF($filename);
     }
     if ($ext == "PNG") {
         $src = ImageCreateFromPNG($filename);
     }
     if (function_exists('ImageCreateTrueColor')) {
         $dst = ImageCreateTrueColor($dw, $dh);
     } else {
         $dst = ImageCreate($dw, $dh);
     }
     if (function_exists('ImageCopyResampled')) {
         imageCopyResampled($dst, $src, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh);
     } else {
         imageCopyResized($dst, $src, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh);
     }
     if ($ext == "JPEG") {
         ImageJPEG($dst, $target_temp_file, $qual);
     }
     if ($ext == "PNG") {
         ImagePNG($dst, $target_temp_file, $qual);
     }
     if ($ext == "GIF") {
         ImagePNG($dst, $target_temp_file, $qual);
     }
     ImageDestroy($dst);
     return $target_temp_file;
 }
function show_gd_img($content = "")
{
    $content = '  ' . preg_replace("/(\\w)/", "\\1 ", $content) . ' ';
    $gd_version = 2;
    @header("Content-Type: image/jpeg");
    $tmp_x = 140;
    $tmp_y = 20;
    $image_x = 210;
    $image_y = 65;
    $circles = 3;
    if ($gd_version == 1) {
        $tmp = imagecreate($tmp_x, $tmp_y);
        $im = imagecreate($image_x, $image_y);
    } else {
        $tmp = imagecreatetruecolor($tmp_x, $tmp_y);
        $im = imagecreatetruecolor($image_x, $image_y);
    }
    $white = ImageColorAllocate($tmp, 255, 255, 255);
    $black = ImageColorAllocate($tmp, 0, 0, 0);
    $grey = ImageColorAllocate($tmp, 210, 210, 210);
    imagefill($tmp, 0, 0, $white);
    for ($i = 1; $i <= $circles; $i++) {
        $values = array(0 => rand(0, $tmp_x - 10), 1 => rand(0, $tmp_y - 3), 2 => rand(0, $tmp_x - 10), 3 => rand(0, $tmp_y - 3), 4 => rand(0, $tmp_x - 10), 5 => rand(0, $tmp_y - 3), 6 => rand(0, $tmp_x - 10), 7 => rand(0, $tmp_y - 3), 8 => rand(0, $tmp_x - 10), 9 => rand(0, $tmp_y - 3), 10 => rand(0, $tmp_x - 10), 11 => rand(0, $tmp_y - 3));
        $randomcolor = imagecolorallocate($tmp, rand(100, 255), rand(100, 255), rand(100, 255));
        imagefilledpolygon($tmp, $values, 6, $randomcolor);
    }
    imagestring($tmp, 5, 0, 2, $content, $black);
    //-----------------------------------------
    // Distort by resizing
    //-----------------------------------------
    imagecopyresized($im, $tmp, 0, 0, 0, 0, $image_x, $image_y, $tmp_x, $tmp_y);
    imagedestroy($tmp);
    $white = ImageColorAllocate($im, 255, 255, 255);
    $black = ImageColorAllocate($im, 0, 0, 0);
    $grey = ImageColorAllocate($im, 100, 100, 100);
    $random_pixels = $image_x * $image_y / 10;
    for ($i = 0; $i < $random_pixels; $i++) {
        ImageSetPixel($im, rand(0, $image_x), rand(0, $image_y), $black);
    }
    $no_x_lines = ($image_x - 1) / 5;
    for ($i = 0; $i <= $no_x_lines; $i++) {
        // X lines
        ImageLine($im, $i * $no_x_lines, 0, $i * $no_x_lines, $image_y, $grey);
        // Diag lines
        ImageLine($im, $i * $no_x_lines, 0, $i * $no_x_lines + $no_x_lines, $image_y, $grey);
    }
    $no_y_lines = ($image_y - 1) / 5;
    for ($i = 0; $i <= $no_y_lines; $i++) {
        ImageLine($im, 0, $i * $no_y_lines, $image_x, $i * $no_y_lines, $grey);
    }
    ImageJPEG($im);
    ImageDestroy($im);
    exit;
}
Example #15
0
 function BannerError($Message)
 {
     HTTP::sendHeader('Content-type', 'image/jpg');
     $im = ImageCreate(450, 80);
     $background_color = ImageColorAllocate($im, 255, 255, 255);
     $text_color = ImageColorAllocate($im, 233, 14, 91);
     ImageString($im, 3, 5, 5, $Message, $text_color);
     ImageJPEG($im);
     imagedestroy($im);
     exit;
 }
Example #16
0
function createPhoto ($old) {
global $fold,$pref;
	$q = 100;
	$img = ImageCreateFromJPEG($fold.$old);
	$font = "tahoma.ttf";
	$dom = "Hello World!";
	$color = imagecolorallocate ($img, 0, 0, 0); 
	imagettftext ($img, 50, 0, 55, 625, $color, $font, $dom); 
	ImageJPEG($img, $fold.$pref.$old, $q);
	ImageDestroy($img);
}
Example #17
0
 function createpicture($action)
 {
     foreach ($this->pictures as $this->picture) {
         $imgsize = getimagesize($this->directory . $this->picture);
         $org_width = $imgsize[0];
         $org_height = $imgsize[1];
         $new_width = $this->width;
         // if ( $org_width > $new_width || $org_height > $this->height_max || $action == 'thumb' )  {
         $new_height = $org_height / $org_width * $new_width;
         $imgfile = substr($this->picture, strlen($this->picture) - 3);
         if (preg_match('/".$imgfile."/i', 'jpg') || preg_match('/".$imgfile."/i', 'jpeg')) {
             $org_picture = imagecreatefromjpeg($this->directory . $this->picture);
         } else {
             if (preg_match('/".$imgfile."/i', 'png')) {
                 $org_picture = imagecreatefrompng($this->directory . $this->picture);
             } else {
                 if (preg_match('/".$imgfile."/i', 'gif')) {
                     $org_picture = imagecreatefromgif($this->directory . $this->picture);
                 }
             }
         }
         if ($org_width < $new_width) {
             $new_width = $org_width;
         }
         if ($org_height < $new_height) {
             $new_height = $org_height;
         }
         if ($new_height > $this->height_max) {
             $new_height = $this->height_max;
             $new_width = $new_height / $org_height * $org_width;
         }
         if (!preg_match($imgfile / i, 'gif')) {
             $newpicture = ImageCreateTrueColor($new_width, $new_height);
         } else {
             if (preg_match($imgfile / i, 'gif')) {
                 $newpicture = imagecreate($new_width, $new_height);
             }
         }
         ImageCopyresampled($newpicture, $org_picture, 0, 0, 0, 0, $new_width, $new_height, $org_width, $org_height);
         if (preg_match('/".$imgfile."/i', 'jpg') || preg_match('/".$imgfile."/i', 'jpeg')) {
             ImageJPEG($newpicture, $this->dir_target . $this->picture);
         } else {
             if (preg_match('/".$imgfile."/i', 'png')) {
                 ImagePNG($newpicture, $this->dir_target . $this->picture);
             } else {
                 if (preg_match('/".$imgfile."/i', 'gif')) {
                     ImageGIF($newpicture, $this->dir_target . $this->picture);
                 }
             }
         }
         //   }
     }
 }
Example #18
0
 private function saveImageToFile($image, $filepath, $fileformat = 'jpg')
 {
     switch ($fileformat) {
         case "jpg":
         case "jpeg":
             ImageJPEG($image, $filepath);
             break;
         case "png":
             ImagePNG($image, $filepath);
             break;
     }
 }
Example #19
0
function create_avatar($imgpath, $thumbpath, $neueBreite, $neueHoehe)
{
    $size = getimagesize($imgpath);
    $breite = $size[0];
    $hoehe = $size[1];
    $RatioW = $neueBreite / $breite;
    $RatioH = $neueHoehe / $hoehe;
    if ($RatioW < $RatioH) {
        $neueBreite = $breite * $RatioW;
        $neueHoehe = $hoehe * $RatioW;
    } else {
        $neueBreite = $breite * $RatioH;
        $neueHoehe = $hoehe * $RatioH;
    }
    $neueBreite = round($neueBreite, 0);
    $neueHoehe = round($neueHoehe, 0);
    if (function_exists('gd_info')) {
        $tmp = gd_info();
        $imgsup = $tmp['GIF Create Support'] ? 1 : 2;
        unset($tmp);
    } else {
        $imgsup = 2;
    }
    if ($size[2] < $imgsup or $size[2] > 3) {
        return false;
    }
    if ($size[2] == 1) {
        $altesBild = imagecreatefromgif($imgpath);
    } elseif ($size[2] == 2) {
        $altesBild = imagecreatefromjpeg($imgpath);
    } elseif ($size[2] == 3) {
        $altesBild = imagecreatefrompng($imgpath);
    }
    if (function_exists('imagecreatetruecolor') and $size[2] != 1) {
        $neuesBild = png_create_transparent($neueBreite, $neueHoehe);
        imagecopyresampled($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
    } elseif (function_exists('imagecreatetruecolor') and $size[2] == 1) {
        $neuesBild = imageCreate($neueBreite, $neueHoehe);
        gif_create_transparent($neuesBild, $altesBild);
        imagecopyresampled($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
    } else {
        $neuesBild = imageCreate($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
    }
    if ($size[2] == 1) {
        ImageGIF($neuesBild, $thumbpath);
    } elseif ($size[2] == 2) {
        ImageJPEG($neuesBild, $thumbpath);
    } elseif ($size[2] == 3) {
        ImagePNG($neuesBild, $thumbpath);
    }
    return true;
}
Example #20
0
 function IndexAction()
 {
     $str = "23456789ABCDEFGHJKMNPQRSTUVWXYZ";
     $code_str = str_shuffle($str);
     $code = str_split(substr($code_str, 0, 4));
     $_SESSION['VerifyCode'] = strtolower(implode('', $code));
     $width = 115;
     $height = 29;
     $im = ImageCreate($width, $height);
     // 创建图形
     ImageColorAllocate($im, 255, 255, 255);
     // 填充背景颜色为白色
     // 用淡色给图形添加杂色
     for ($i = 0; $i < 100; $i++) {
         $pxcolor = ImageColorAllocate($im, 230, 104, 66);
         ImageSetPixel($im, mt_rand(0, $width), mt_rand(0, $height), $pxcolor);
     }
     // 用深色调绘制边框
     $bordercolor = ImageColorAllocate($im, 255, 255, 255);
     ImageRectangle($im, 0, 0, $width - 1, $height - 1, $bordercolor);
     $offset = rand(10, 30);
     $font = array('View/font/UniversityRomanStd.otf');
     foreach ($code as $char) {
         $textcolor = ImageColorAllocate($im, 230, 104, 106);
         shuffle($font);
         imagettftext($im, 22, rand(-20, 40), $offset, 26, $textcolor, $font[0], $char);
         $offset += $width / 5 - rand(0, 2);
     }
     $code_str = str_shuffle($str);
     $code = str_split(substr($code_str, 0, 5));
     // 干扰字符
     $offset = rand(10, 30);
     foreach ($code as $char) {
         $textcolor = ImageColorAllocate($im, 230, 104, 66);
         shuffle($font);
         imagettftext($im, 8, rand(-20, 40), $offset, 26, $textcolor, $font[0], $char);
         $offset += rand(5, 10);
     }
     // 禁止缓存
     header("pragma:no-cache\r\n");
     header("Cache-Control:no-cache\r\n");
     header("Expires:0\r\n");
     if (ImageTypes() & IMG_PNG) {
         header('Content-Type:image/png');
         ImagePNG($im);
     } elseif (ImageTypes() & IMG_JPEG) {
         header('Content-Type:image/jpeg');
         ImageJPEG($im);
     } else {
         header('Content-Type:image/gif');
         ImageGif($im);
     }
 }
Example #21
0
function resize($images, $filename)
{
    $width = 500;
    $size = getimagesize($images);
    $height = round($width * $size[1] / $size[0]);
    $images_orig = ImageCreateFromJPEG($images);
    $photoX = imagesx($images_orig);
    $photoY = imagesy($images_orig);
    $images_fin = imagecreatetruecolor($width, $height);
    ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
    ImageJPEG($images_fin, $GLOBALS['root'] . '/images/' . $filename);
    ImageDestroy($images_orig);
    ImageDestroy($images_fin);
}
Example #22
0
 function imageSaveX($file, $saveFile = "")
 {
     switch ($this->type) {
         case "JPEG":
             ImageJPEG($file, "{$saveFile}", $this->quality);
             break;
         case "PNG":
             ImagePNG($file, "{$saveFile}");
             break;
         case "GIF":
             ImageGIF($file, "{$saveFile}");
             break;
     }
     return true;
 }
Example #23
0
function resize($image_tmp, $image_name, $width_size, $folder)
{
    $images = $image_tmp;
    $new_images = $image_name;
    $width = $width_size;
    $size = GetimageSize($images);
    $height = round($width * $size[1] / $size[0]);
    $images_orig = ImageCreateFromJPEG($images);
    $photoX = ImagesX($images_orig);
    $photoY = ImagesY($images_orig);
    $images_fin = ImageCreateTrueColor($width, $height);
    ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
    ImageJPEG($images_fin, $folder . $new_images);
    ImageDestroy($images_orig);
    ImageDestroy($images_fin);
}
Example #24
0
 /**
  * Create a simple sume captcha
  */
 public function sumeCaptcha()
 {
     $val1 = rand(1, 9);
     $val2 = rand(1, 9);
     $result = $val1 + $vale;
     $txtCode = $val1 . ' + ' . $val2;
     $img = ImageCreateFromGIF('img/captcha/bg.gif');
     $bg = ImageColorAllocate($img, 240, 240, 240);
     $color = ImageColorAllocate($img, 0, 0, 0);
     $font = 'img/others/arial.ttf';
     // Create the Captcha image
     ImageTTFText($img, 20, 0, 13, 30, $color, $font, $txtCode);
     ImageJPEG($img, 'img/captcha/box.jpg', 75);
     ImageDestroy($img);
     return $result;
 }
 public function saveImage($targetPath)
 {
     switch ($this->ext) {
         case 'image/jpg':
         case 'image/jpeg':
             ImageJPEG($this->targetImage, $targetPath);
             break;
         case 'image/gif':
             ImageGIF($this->targetImage, $targetPath);
             break;
         case 'image/png':
             ImagePNG($this->targetImage, $targetPath);
             break;
     }
     ImageDestroy($this->targetImage);
 }
Example #26
0
 function image_out($data, $image_type = 'png', $filename = '')
 {
     $im = $this->mkimage($data);
     if ($image_type == "jpeg") {
         if (strlen($filename) > 0) {
             return ImageJPEG($im, $filename);
         } else {
             return ImageJPEG($im);
         }
     } else {
         if (strlen($filename) > 0) {
             return ImagePNG($im, $filename);
         } else {
             return ImagePNG($im);
         }
     }
 }
Example #27
0
function graph($name, $w, $h, $bgc, $fgc, $title, $xtitle, $ytitle, $numX, $xTitles, $xValues, $bc)
{
    $top = 15;
    $right = 5;
    $left = 35;
    $bottom = 25;
    $image = ImageCreate($w, $h);
    $cols = colours($image);
    ImageFill($image, 0, 0, $cols[$bgc]);
    drawAxis($image, $w, $h, $cols[$fgc], $top, $right, $left, $bottom);
    drawLines($image, $w, $h, $cols[$fgc], $top, $right, $left, $bottom);
    drawTitles($image, $w, $h, $cols[$fgc], $title, $xtitle, $ytitle);
    drawXLables($image, $w, $h, $right, $left, $cols[$fgc], $numX, $xTitles);
    $max = calcMaxDataItem($xValues, $numX);
    drawYLables($image, $w, $h, $cols[$fgc], $top, $right, $left, $bottom, $max);
    drawData($image, $w, $h, $cols[$bc], $top, $right, $left, $bottom, $numX, $xValues, $max);
    ImageJPEG($image, $name);
    ImageDestroy($image);
}
Example #28
0
 /**
  * Thumbnail kép készítése
  */
 function setThumbnail()
 {
     global $sugar_config;
     if (!empty($this->destination)) {
         $size = getimagesize($this->destination);
         $height = 200;
         $ratio = $size[0] / $size[1];
         $width = round($height * $ratio);
         $images_orig = $this->imagecreatefromfile($this->destination);
         $photoX = ImagesX($images_orig);
         $photoY = ImagesY($images_orig);
         $images_thumb = ImageCreateTrueColor($width, $height);
         if (!ImageCopyResampled($images_thumb, $images_orig, 0, 0, 0, 0, $width, $height, $photoX, $photoY)) {
             die("ERROR: can't resize the image");
         } else {
             ImageJPEG($images_thumb, $sugar_config['cache_dir'] . "images/thumb/" . $this->fileName);
         }
     }
 }
function twMachThumbnail($pfad, $bild, $thumbBreite)
{
    $bildMitPfad = $pfad . $bild;
    // wenn Bild nich gefunden wurde: Abbruch
    if (!file_exists($bildMitPfad)) {
        return false;
    }
    $bilddaten = getimagesize($bildMitPfad);
    $origBreite = $bilddaten[0];
    $origHoehe = $bilddaten[1];
    if ($origBreite < $thumbBreite) {
        $thumbBreite = $origBreite;
    }
    $Skalierungsfaktor = $origBreite / $thumbBreite;
    $thumbHoehe = intval($origHoehe / $Skalierungsfaktor);
    // wenn es ein gif-Bild ist
    if ($bilddaten[2] == 1) {
        $Originalgrafik = ImageCreateFromGIF($bildMitPfad);
        $Thumbnailgrafik = ImageCreateTrueColor($thumbBreite, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $thumbBreite, $thumbHoehe, $origBreite, $origHoehe);
        ImageGIF($Thumbnailgrafik, $pfad . "thumb_" . $bild);
    } elseif ($bilddaten[2] == 2) {
        $Originalgrafik = ImageCreateFromJPEG($bildMitPfad);
        $Thumbnailgrafik = ImageCreateTrueColor($thumbBreite, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $thumbBreite, $thumbHoehe, $origBreite, $origHoehe);
        ///ImageJPEG($Thumbnailgrafik, $pfad."thumb_".$bild);
        ImageJPEG($Thumbnailgrafik, $pfad . "thumb_" . $bild);
    } elseif ($bilddaten[2] == 3) {
        $Originalgrafik = ImageCreateFromPNG($bildMitPfad);
        $Thumbnailgrafik = ImageCreateTrueColor($thumbBreite, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $thumbBreite, $thumbHoehe, $origBreite, $origHoehe);
        ImagePNG($Thumbnailgrafik, $pfad . "thumb_" . $bild);
    } else {
        return false;
    }
    // Speicher leeren
    if ($Originalgrafik) {
        imagedestroy($Originalgrafik);
    }
    if ($Thumbnailgrafik) {
        imagedestroy($Thumbnailgrafik);
    }
}
Example #30
-1
 public static function ResizeImage($Img, $w)
 {
     $filename = $_SERVER["DOCUMENT_ROOT"] . JURI::root(true) . "/" . $Img;
     $images = $filename;
     $new_images = $_SERVER["DOCUMENT_ROOT"] . JURI::root(true) . "/thumb/" . $Img;
     //copy("/images/thumb/"$_FILES,"Photos/".$_FILES["userfile"]["name"]);
     $width = $w;
     //*** Fix Width & Heigh (Autu caculate) ***//
     $size = GetimageSize($images);
     $height = round($width * $size[1] / $size[0]);
     if ($size[0] == "250") {
         return "The logo has the right width. Doesn't make sense resize it! Good job!";
     }
     $images_orig = ImageCreateFromJPEG($images);
     $photoX = ImagesX($images_orig);
     $photoY = ImagesY($images_orig);
     $images_fin = ImageCreateTrueColor($width, $height);
     $result = ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
     ImageJPEG($images_fin, $filename);
     ImageDestroy($images_orig);
     ImageDestroy($images_fin);
     if ($result) {
         return "Logo resized to " . $width . "px by " . $height . "px";
     } else {
         return "mmm It looks like something unexpected just happened, ask Jose!";
     }
 }