public function src($src, $ext = null)
 {
     if (!is_file($src)) {
         throw new FileNotFoundException($src);
     }
     $this->src = $src;
     if (!$ext) {
         $info = new \SplFileInfo($src);
         $this->ext = strtoupper($info->getExtension());
     } else {
         $this->ext = strtoupper($ext);
     }
     if (is_file($src) && ($this->ext == "JPG" or $this->ext == "JPEG")) {
         $this->image = ImageCreateFromJPEG($src);
     } else {
         if (is_file($src) && $this->ext == "PNG") {
             $this->image = ImageCreateFromPNG($src);
         } else {
             throw new FileNotFoundException($src);
         }
     }
     $this->input_width = imagesx($this->image);
     $this->input_height = imagesy($this->image);
     return $this;
 }
 function thumbnail($imgfile)
 {
     //detect image format
     //$this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile);
     $this->img["format"] = preg_replace('/.*\\.(.*)$/', "\\1", $imgfile);
     $this->img["format"] = strtoupper($this->img["format"]);
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         //JPEG
         $this->img["format"] = "JPEG";
         $this->img["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->img["format"] == "PNG") {
         //PNG
         $this->img["format"] = "PNG";
         $this->img["src"] = ImageCreateFromPNG($imgfile);
     } elseif ($this->img["format"] == "GIF") {
         //GIF
         $this->img["format"] = "GIF";
         $this->img["src"] = ImageCreateFromGIF($imgfile);
     } elseif ($this->img["format"] == "WBMP") {
         //WBMP
         $this->img["format"] = "WBMP";
         $this->img["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         echo "Not Supported File";
         exit;
     }
     @($this->img["lebar"] = imagesx($this->img["src"]));
     @($this->img["tinggi"] = imagesy($this->img["src"]));
     //default quality jpeg
     $this->img["quality"] = 75;
 }
Exemple #3
0
function ResizeImage($image_from, $image_to, $fitwidth = 200, $fitheight = 270, $quality = 75)
{
    $os = $originalsize = getimagesize($image_from);
    if ($originalsize[2] != 2 && $originalsize[2] != 3 && $originalsize[2] != 6 && ($originalsize[2] < 9 or $originalsize[2] > 12)) {
        return false;
    }
    if ($originalsize[0] > $fitwidth or $originalsize[1] > $fitheight) {
        $h = getimagesize($image_from);
        if ($h[0] / $fitwidth > $h[1] / $fitheight) {
            $fitheight = $h[1] * $fitwidth / $h[0];
        } else {
            $fitwidth = $h[0] * $fitheight / $h[1];
        }
        if ($os[2] == 2 or $os[2] >= 9 && $os[2] <= 12) {
            $i = ImageCreateFromJPEG($image_from);
        }
        $o = ImageCreateTrueColor($fitwidth, $fitheight);
        imagecopyresampled($o, $i, 0, 0, 0, 0, $fitwidth, $fitheight, $h[0], $h[1]);
        imagejpeg($o, $image_to, $quality);
        chmod($image_to, 0777);
        imagedestroy($o);
        imagedestroy($i);
        return 2;
    }
    if ($originalsize[0] <= $fitwidth && $originalsize[1] <= $fitheight) {
        $i = ImageCreateFromJPEG($image_from);
        imagejpeg($i, $image_to, $quality);
        chmod($image_to, 0777);
        return 1;
    }
}
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);
    }
}
Exemple #5
0
 /**
  * Contructor method. Will create a new image from the target file.
  * Accepts an image filename as a string. Method also works out how
  * big the image is and stores this in the $image array.
  *
  * @param string $imgFile The image filename.
  */
 public function ImageManipulation($imgfile)
 {
     //detect image format
     $this->image["format"] = strtolower(substr(strrchr($imgfile, '.'), 1));
     $this->image["format"] = strtoupper($this->image["format"]);
     // convert image into usable format.
     if ($this->image["format"] == "JPG" || $this->image["format"] == "JPEG") {
         //JPEG
         $this->image["format"] = "JPEG";
         $this->image["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->image["format"] == "PNG") {
         //PNG
         $this->image["format"] = "PNG";
         $this->image["src"] = imagecreatefrompng($imgfile);
     } elseif ($this->image["format"] == "GIF") {
         //GIF
         $this->image["format"] = "GIF";
         $this->image["src"] = ImageCreateFromGif($imgfile);
     } elseif ($this->image["format"] == "WBMP") {
         //WBMP
         $this->image["format"] = "WBMP";
         $this->image["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         return false;
     }
     // Image is ok
     $this->imageok = true;
     // Work out image size
     $this->image["sizex"] = imagesx($this->image["src"]);
     $this->image["sizey"] = imagesy($this->image["src"]);
 }
Exemple #6
0
 /**
  * Create the banners
  * @return jpeg
  */
 private function create_banner()
 {
     //Load image
     $rImg = ImageCreateFromJPEG($this->imgpath);
     //Define colours
     $textcolour1 = imagecolorallocate($rImg, $this->colour1['0'], $this->colour1['1'], $this->colour1['2']);
     $textcolour2 = imagecolorallocate($rImg, $this->colour2['0'], $this->colour2['1'], $this->colour2['2']);
     //Make text uppercase
     $text1 = strtoupper($this->banner_line1);
     $text2 = strtoupper($this->banner_line2);
     //Get string length
     $count1 = strlen($text1);
     $count2 = strlen($text2);
     //Select font size depending on string length
     $fsize1 = $this->fontsize($count1);
     $fsize2 = $this->fontsize($count2);
     //Center align the text
     $xalign1 = $this->aligntext($count1, $fsize1, $text1);
     $xalign2 = $this->aligntext($count2, $fsize2, $text2);
     // Adds text to image
     imagettftext($rImg, $fsize1, 0, $xalign1, $this->valign1, $textcolour1, $this->font, $text1);
     imagettftext($rImg, $fsize2, 0, $xalign2, $this->valign2, $textcolour2, $this->font, $text2);
     //Output image
     header('Content-type: image/jpeg');
     imagejpeg($rImg, NULL, 100);
     imagedestroy($rImg);
 }
Exemple #7
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 make_thumbnail($_pic_src, $_im_ziel, $_br = 150, $_ho = 150, $_qual = 75)
{
    if (file_exists($_im_ziel)) {
        return false;
    }
    $_size = getimagesize($_pic_src);
    $_pic_src_x = $_size[0];
    $_pic_src_y = $_size[1];
    $_im_src = ImageCreateFromJPEG($_pic_src);
    if ($_im_src) {
        $_im_dst = imagecreatetruecolor($_br, $_ho);
        if ($_im_dst) {
            $_x_verschiebung = 0;
            $_y_verschiebung = 0;
            $_x_breite = $_pic_src_x;
            $_y_hoehe = $_pic_src_y;
            if ($_pic_src_x > $_pic_src_y) {
                # Breite größer als Höhe, nach Höhe richten
                $_x_breite = $_y_hoehe;
                $_x_verschiebung = ($_pic_src_x - $_y_hoehe) / 2;
            }
            if ($_pic_src_y > $_pic_src_x) {
                # Höhe größer als Breite, nach Breite richten
                $_y_hoehe = $_x_breite;
                $_y_verschiebung = ($_pic_src_y - $_x_breite) / 2;
            }
            @imagecopyresized($_im_dst, $_im_src, 0, 0, $_x_verschiebung, $_y_verschiebung, $_br, $_ho, $_x_breite, $_y_hoehe);
            @imagerectangle($_im_dst, 0, 0, $_br - 1, $_ho - 1, 0);
            @imagejpeg($_im_dst, $_im_ziel, $_qual);
        } else {
            @imagedestroy($_im_src);
        }
    }
}
Exemple #9
0
 function thumbnail($imgfile, $format = "image/jpeg")
 {
     //detect image format
     $pos = strpos($format, "/");
     $this->img["format"] = strtoupper(substr($format, $pos + 1));
     //$this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile);
     //$this->img["format"]=strtoupper($this->img["format"]);
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         //JPEG
         $this->img["format"] = "JPEG";
         $this->img["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->img["format"] == "PNG") {
         //PNG
         $this->img["format"] = "PNG";
         $this->img["src"] = ImageCreateFromPNG($imgfile);
     } elseif ($this->img["format"] == "GIF") {
         //GIF
         $this->img["format"] = "GIF";
         $this->img["src"] = ImageCreateFromGIF($imgfile);
     } elseif ($this->img["format"] == "WBMP") {
         //WBMP
         $this->img["format"] = "WBMP";
         $this->img["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         echo "Not Supported File ";
         $this->is_img = false;
         return;
         //exit();
     }
     @($this->img["lebar"] = imagesx($this->img["src"]));
     @($this->img["tinggi"] = imagesy($this->img["src"]));
     //default quality jpeg
     $this->img["quality"] = 75;
 }
 private function cropBilde($sti, $filnavn, $nyttFilnavn, $cropBredde, $cropHoyde)
 {
     $gammeltBilde = $sti . $filnavn;
     $bi = @ImageCreateFromJPEG($gammeltBilde) or $bi = @ImageCreateFromPNG($gammeltBilde) or $bi = @ImageCreateFromGIF($gammeltBilde) or $bi = false;
     if ($bi) {
         $naStorrelse = @getimagesize($gammeltBilde);
         $bredde = $naStorrelse[0];
         $hoyde = $naStorrelse[1];
         $nyBreddeNy = $bredde / $cropBredde;
         $nyHoydeNy = $hoyde / $cropHoyde;
         $halvertHoyde = $cropHoyde / 2;
         $halvertBredde = $cropBredde / 2;
         $thumb = @ImageCreateTrueColor($cropBredde, $cropHoyde);
         if ($bredde > $hoyde) {
             $tilpassetBredde = $bredde / $nyHoydeNy;
             $halvBredde = $tilpassetBredde / 2;
             $intBredde = $halvBredde - $halvertBredde;
             @ImageCopyResampled($thumb, $bi, -$intBredde, 0, 0, 0, $tilpassetBredde, $cropHoyde, $bredde, $hoyde);
         } elseif ($bredde < $hoyde || $bredde == $hoyde) {
             $tilPassetHoyde = $hoyde / $nyBreddeNy;
             $halvHoyde = $tilPassetHoyde / 2;
             $intHoyde = $halvHoyde - $halvertHoyde;
             @ImageCopyResampled($thumb, $bi, 0, -$intHoyde, 0, 0, $cropBredde, $tilPassetHoyde, $bredde, $hoyde);
         } else {
             @ImageCopyResampled($thumb, $bi, 0, 0, 0, 0, $cropBredde, $cropHoyde, $bredde, $hoyde);
         }
         @imagejpeg($thumb, $sti . $nyttFilnavn, 50);
         return $nyttFilnavn;
     } else {
         return -1;
     }
 }
Exemple #11
0
 private function thumbnail($imgfile)
 {
     //detect image format
     $this->acHWArr = getimagesize($imgfile);
     $this->img["format"] = ereg_replace(".*\\.(.*)\$", "\\1", $imgfile);
     $this->img["format"] = strtoupper($this->img["format"]);
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         //JPEG
         $this->img["format"] = "JPEG";
         $this->img["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->img["format"] == "PNG") {
         //PNG
         $this->img["format"] = "PNG";
         $this->img["src"] = ImageCreateFromPNG($imgfile);
     } elseif ($this->img["format"] == "GIF") {
         //GIF
         $this->img["format"] = "GIF";
         $this->img["src"] = ImageCreateFromGIF($imgfile);
     } elseif ($this->img["format"] == "WBMP") {
         //WBMP
         $this->img["format"] = "WBMP";
         $this->img["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         echo "Not Supported File <a href='" . $_SERVER[HTTP_REFERER] . "'>Back</a>";
         exit;
     }
     @($this->img["lebar"] = imagesx($this->img["src"]));
     @($this->img["tinggi"] = imagesy($this->img["src"]));
     //default quality jpeg
     $this->img["quality"] = 75;
 }
Exemple #12
0
 function open_image($file = null)
 {
     $image_type = $this->image_type($file);
     if (!$image_type) {
         trigger_error("Invalid image file: {$file}.", E_USER_ERROR);
     }
     $this->type = $image_type[0];
     $this->width = $image_type[1];
     $this->height = $image_type[2];
     if (!in_array($this->type, $this->supported_img_types)) {
         trigger_error("File type '{$this->type}' not supported.", E_USER_ERROR);
     }
     // Destroy if already open
     if ($this->image) {
         ImageDestroy($this->image);
     }
     switch ($this->type) {
         case 'JPG':
             $this->image = ImageCreateFromJPEG($file);
             break;
         case 'GIF':
             $this->image = ImageCreateFromGIF($file);
             break;
         case 'PNG':
             $this->image = ImageCreateFromPNG($file);
             break;
     }
 }
 /** 
  * @private
  */
 function thumbnail($imgfile)
 {
     //detect image format
     $this->img["format"] = ereg_replace(".*\\.(.*)\$", "\\1", $imgfile);
     $this->img["format"] = strtoupper($this->img["format"]);
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         $this->img["format"] = "JPEG";
         $this->img["src"] = @ImageCreateFromJPEG($imgfile);
     } elseif ($this->img["format"] == "PNG") {
         $this->img["format"] = "PNG";
         $this->img["src"] = @ImageCreateFromPNG($imgfile);
     } elseif ($this->img["format"] == "GIF") {
         $this->img["format"] = "GIF";
         if (function_exists("imagecreatefromgif")) {
             $this->img["src"] = @ImageCreateFromGIF($imgfile);
         } else {
             return false;
         }
     } else {
         // not a recognized format
         throw new Exception("Trying to generate a thumbnail of an unsupported format!");
         //die();
     }
     // check for errors
     if (!$this->img["src"]) {
         return false;
     }
     // if no errors, continue
     @($this->img["lebar"] = imagesx($this->img["src"]));
     @($this->img["tinggi"] = imagesy($this->img["src"]));
     //default quality jpeg
     $this->img["quality"] = 85;
     return true;
 }
Exemple #14
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);
}
 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;
 }
Exemple #16
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);
         }
     }
 }
Exemple #17
0
 function img($sourceFile)
 {
     if (file_exists($sourceFile)) {
         $this->image = ImageCreateFromJPEG($sourceFile);
     } else {
         $this->errorHandler();
     }
     return;
 }
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);
    }
}
Exemple #19
0
 function makeIcon($type = 1)
 {
     //$img_des = ImageCreateTrueColor ( $this->size, $this->size );
     $img_des = ImageCreateTrueColor($this->size, $this->size);
     $background = imagecolorallocate($img_des, 255, 255, 255);
     imagefill($img_des, 0, 0, $background);
     switch ($this->t) {
         case 'gif':
             $img_src = ImageCreateFromGIF($this->path);
             break;
         case 'jpg':
             $img_src = ImageCreateFromJPEG($this->path);
             break;
         case 'png':
             $img_src = ImageCreateFromPNG($this->path);
             break;
     }
     if ($type == 1) {
         imagecopyresampled($img_des, $img_src, 0, 0, ($this->nw - $this->size) / 2, 0, $this->nw, $this->nh, $this->w, $this->h);
     } else {
         imagecopyresampled($img_des, $img_src, 0, 0, 0, ($this->nh - $this->size) / 2, $this->nw, $this->nh, $this->w, $this->h);
     }
     /*
     imageline( $img_des , 0 , 0 , 0 , ($this->size-1) , imagecolorallocate( $img_des , 220 , 220 , 220 )  );
     imageline( $img_des , 0 , ($this->size-1) , ($this->size-1) , ($this->size-1) , imagecolorallocate( $img_des , 220 , 220 , 220 )  );
     imageline( $img_des , ($this->size-1) , ($this->size-1) , ($this->size-1) , 0 , imagecolorallocate( $img_des , 220 , 220 , 220 )  );
     imageline( $img_des , ($this->size-1) , 0 , 0 , 0 , imagecolorallocate( $img_des , 220 , 220 , 220 )  );
     */
     //echo $this->dest ;
     switch ($this->t) {
         case 'gif':
             if (empty($this->dest)) {
                 header("Content-type: image/gif");
                 return ImageGIF($img_des);
             } else {
                 return ImageGIF($img_des, $this->dest);
             }
             break;
         case 'jpg':
             if (empty($this->dest)) {
                 header("Content-type: image/jpeg");
                 return ImageJPEG($img_des);
             } else {
                 return ImageJPEG($img_des, $this->dest);
             }
             break;
         case 'png':
             if (empty($this->dest)) {
                 header("Content-type: image/png");
                 return ImagePNG($img_des);
             } else {
                 return ImagePNG($img_des, $this->dest);
             }
             break;
     }
 }
 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;
 }
Exemple #21
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);
}
Exemple #22
0
 private static function _transform($fileName, $toWidth, $toHeight, $typeTransform)
 {
     //funkcja zwraca uchwyt do zasobu
     //zasob jest przeskalowanym odpowiednio obrazkiem
     $inImage = ImageCreateFromJPEG($fileName);
     $imgWidth = ImageSX($inImage);
     $imgHeight = ImageSY($inImage);
     $size = ImageTransform::_compute_size($imgWidth, $imgHeight, $toWidth, $toHeight, $typeTransform);
     $outImage = ImageCreatetruecolor($size['width'], $size['height']);
     imagecopyresampled($outImage, $inImage, 0, 0, 0, 0, $size['width'], $size['height'], $imgWidth, $imgHeight);
     return $outImage;
 }
Exemple #23
0
 function __construct($path)
 {
     $this->image = null;
     $oldErrorReporting = error_reporting();
     error_reporting(0);
     if ($this->imageLibSupported()) {
         switch (br()->fs()->fileExt($path)) {
             case 'png':
                 if ($this->image = @ImageCreateFromPNG($path)) {
                     $this->format = 'png';
                 }
                 break;
             case 'jpg':
             case 'jpeg':
                 if ($this->image = @ImageCreateFromJPEG($path)) {
                     $this->format = 'jpg';
                 }
                 break;
             case 'gif':
                 if ($this->image = @ImageCreateFromGIF($path)) {
                     $this->format = 'gif';
                 }
                 break;
         }
         if ($this->image) {
         } else {
             $this->image = @ImageCreateFromPNG($path);
             if ($this->image) {
                 $this->format = 'png';
             } else {
                 $this->image = @ImageCreateFromJPEG($path);
                 if ($this->image) {
                     $this->format = 'jpg';
                 } else {
                     $this->image = @ImageCreateFromGIF($path);
                     if ($this->image) {
                         $this->format = 'gif';
                     }
                 }
             }
         }
     } else {
         throw new Exception('It seems GD is not installed.');
     }
     if ($this->image) {
         $this->width = imagesx($this->image);
         $this->height = imagesy($this->image);
     } else {
         throw new Exception($path . ' is not valid image file.');
     }
     $this->filePath = $path;
     error_reporting($oldErrorReporting);
 }
Exemple #24
0
function SetImgSize($img, $W = 0, $H = 0, $Key = 1)
{
    //echo("$img , $W ,$H , $Key");
    $rasshr = substr(strrchr($img, '.'), 1);
    //организация работы с форматами GIF JPEG PNG
    switch ($rasshr) {
        default:
        case "gif":
            $srcImage = @ImageCreateFromGIF($img);
            break;
        case "jpg":
            $srcImage = @ImageCreateFromJPEG($img);
            break;
        case "png":
            $srcImage = @ImageCreateFromPNG($img);
            break;
    }
    //определяем изначальную длинну и высоту
    $srcWidth = @ImageSX($srcImage);
    $srcHeight = @ImageSY($srcImage);
    //ресайз по заданной ширине
    if ($W != 0 && $H == 0 && $W < $srcWidth) {
        $res = ResNoDel($srcWidth, $srcHeight, $W, 0);
    }
    //ресайз по заданной высоте
    if ($W == 0 && $H != 0 && $H < $srcHeight) {
        $res = ResNoDel($srcWidth, $srcHeight, 0, $H);
    }
    //ресайз с обрезкой
    if ($W != 0 && $H != 0 && ($H < $srcHeight || $W < $srcWidth)) {
        $res = ResDel($srcWidth, $srcHeight, min($W, $srcWidth), min($H, $srcHeight), $Key);
    }
    //создаем картинку
    if ($res) {
        $endImage = @ImageCreateTrueColor($res[2], $res[3]);
        ImageCopyResampled($endImage, $srcImage, 0, 0, $res[0], $res[1], $res[2], $res[3], $res[4], $res[5]);
        unlink($img);
        switch ($rasshr) {
            case "gif":
                ImageGif($endImage, $img);
                break;
            default:
            case "jpg":
                imagejpeg($endImage, $img);
                break;
            case "png":
                imagepng($endImage, $img);
                break;
        }
        ImageDestroy($endImage);
    }
}
 /**
  * Image_Graph_ImageFill [Constructor]
  * @param string $filename The filename and path of the image to use for filling 
  */
 function &Image_Graph_Fill_Image($fileName)
 {
     parent::__construct();
     if (file_exists($fileName)) {
         if (strtolower(substr($fileName, -4)) == ".png") {
             $this->_image = ImageCreateFromPNG($this->_fileName = $fileName);
         } else {
             $this->_image = ImageCreateFromJPEG($this->_fileName = $fileName);
         }
     } else {
         $this->_image = false;
     }
 }
Exemple #26
0
 protected function _createResource($ext, $path)
 {
     if ($ext == 'gif') {
         $res = @ImageCreateFromGIF($path);
     } elseif ($ext == 'jpg' || $ext == 'jpeg') {
         $res = @ImageCreateFromJPEG($path);
     } elseif ($ext == 'png') {
         $res = @ImageCreateFromPNG($path);
     } else {
         $res = false;
     }
     return $res;
 }
 /**
  * Logo [Constructor]
  * @param string $filename The filename and path of the image to use for logo 
  */
 function &Image_Graph_Logo($fileName, $alignment = IMAGE_GRAPH_ALIGN_TOP_RIGHT)
 {
     parent::__construct();
     if (file_exists($fileName)) {
         if (strtolower(substr($fileName, -4)) == ".png") {
             $this->_image = ImageCreateFromPNG($this->_fileName = $fileName);
         } else {
             $this->_image = ImageCreateFromJPEG($this->_fileName = $fileName);
         }
     } else {
         $this->_image = false;
     }
     $this->_alignment = $alignment;
 }
Exemple #28
0
function dzthumb($srcfile,$dstfile,$dstw,$dsth=0,$mode=0,$data=''){
	//mode=0为固定宽高,画质裁切不变形
	//mode=1为固定宽高,画质会拉伸变形
	//mode=2为可变宽高,宽高不超过指定大小
	//mode=3为固定宽度,高度随比例变化
	$data=$data==''?@GetImageSize($srcfile):$data;
	if(!$data) return false;
	if($data[2]==2) $im=@ImageCreateFromJPEG($srcfile);
	elseif ($data[2]==1) $im=@ImageCreateFromGIF($srcfile);
	elseif($data[2]==3) $im=@ImageCreateFromPNG($srcfile);
	list($img_w, $img_h) = $data;
	if($dsth==0) $mode=3;
	if($mode==0){
		$imgratio = $img_w / $img_h;
		$thumbratio = $dstw / $dsth;
		if($imgratio >= 1 && $imgratio >= $thumbratio || $imgratio < 1 && $imgratio > $thumbratio) {
			$cuty = $img_h;
			$cutx = $cuty * $thumbratio;
		} elseif($imgratio >= 1 && $imgratio <= $thumbratio || $imgratio < 1 && $imgratio < $thumbratio) {
			$cutx = $img_w;
			$cuty = $cutx / $thumbratio;
		}
		$cx = $cutx;
		$cy = $cuty;
	}elseif($mode==1){
		$cx = $img_w;
		$cy = $img_h;
	}elseif ($mode==2){
		$cx = $img_w;
		$cy = $img_h;
		$bit=$img_w/$img_h;
		if($dstw/$dsth>$bit){
			$dstw=($img_w/$img_h)*$dsth;
		}else{
			$dsth=($img_h/$img_w)*$dstw;
		}
	}
	elseif($mode==3){
		$cx = $img_w;
		$cy = $img_h;
		$dsth=$dstw * $img_h / $img_w;
	}
	$ni=imagecreatetruecolor($dstw,$dsth);
	ImageCopyResampled($ni,$im,0,0,0,0,$dstw,$dsth, $cx, $cy);
	clearstatcache();
	if($data[2]==2) ImageJPEG($ni,$dstfile,60);
	elseif($data[2]==1) ImageGif($ni,$dstfile);
	elseif($data[2]==3) ImagePNG($ni,$dstfile);
	return true;
}
Exemple #29
-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!";
     }
 }
 /**
  * Contructor method. Will create a new image from the target file.
  * Accepts an image filename as a string. Method also works out how
  * big the image is and stores this in the $image array.
  *
  * @param string $imgFile The image filename.
  */
 public function ImageManipulation($imgfile)
 {
     //detect image format
     $this->image["format"] = preg_replace("/.*\\.(.*)\$/", "\\1", $imgfile);
     //$this->image["format"] = preg_replace(".*\.(.*)$", "\\1", $imgfile);
     $this->image["format"] = strtoupper($this->image["format"]);
     // convert image into usable format.
     if ($this->image["format"] == "JPG" || $this->image["format"] == "JPEG") {
         //JPEG
         $this->image["format"] = "JPEG";
         $this->image["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->image["format"] == "PNG") {
         //PNG
         $this->image["format"] = "PNG";
         $this->image["src"] = imagecreatefrompng($imgfile);
     } elseif ($this->image["format"] == "GIF") {
         //GIF
         $this->image["format"] = "GIF";
         $this->image["src"] = ImageCreateFromGif($imgfile);
     } elseif ($this->image["format"] == "WBMP") {
         //WBMP
         $this->image["format"] = "WBMP";
         $this->image["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         return false;
     }
     // Image is ok
     $this->imageok = true;
     // Work out image size
     $this->image["sizex"] = imagesx($this->image["src"]);
     $this->image["sizey"] = imagesy($this->image["src"]);
 }