Cкрипт за генериране на web thumbnails.

1 отговора 107 прегледа
#1

Cкрипт за генериране на web thumbnails.

Трябва ми скрип на php или perl който да генерира
thumbnailsи на картинки качвани през ftp document roota на
web сървъра...Примерно...качил съм 2-3 gb снимки които искам
да се браузват през http но не ми се създава провию на всяка
от тези картинки че да го качвам и тн.Скрипта да може сам да
прави thumbnailsи при първото отваряне на картинката.
За сега намерих само един yappa който иска ImageMagic ама
той не работи както трябва...не иска да прави реглед на
картинката...
плс дайте някакви идеи...

Отговор
в отговор на edi #2

Re: Cкрипт за генериране на web thumbnails.

imam edin no neznam kak raboty vij nateb moje da ti e ot polza

<?
/*############################################
Sample :
$thumb=new thumbnail("./shiegege.jpg"); // generate image_file, set filename to resize
$thumb->size_width(100); // set width for thumbnail, or
$thumb->size_height(300); // set height for thumbnail, or
$thumb->size_auto(200); // set the biggest width or height for thumbnail
$thumb->jpeg_quality(75); // [OPTIONAL] set quality for jpeg only (0 - 100) (worst - best), default = 75
$thumb->show(); // show your thumbnail
$thumb->save("./huhu.jpg"); // save your thumbnail to file
----------------------------------------------
Note :
- GD must Enabled
- Autodetect file extension (.jpg/jpeg, .png, .gif, .wbmp)
but some server can't generate .gif / .wbmp file types
- If your GD not support 'ImageCreateTrueColor' function,
change one line from 'ImageCreateTrueColor' to 'ImageCreate'
(the position in 'show' and 'save' function)
*/############################################
error_reporting(E_ALL);


class thumbnail
{
var $img;

function thumbnail($imgfile)
{
global $imgnamepic;
$imgnamepic=ereg_replace(".*\/(.*)$","\\1",$imgfile);
//detect image format
$this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile);
$this->img["name"]=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";
exit();
}
@$this->img["lebar"] = imagesx($this->img["src"]);
@$this->img["tinggi"] = imagesy($this->img["src"]);
//default quality jpeg
$this->img["quality"]=80;
}

function size_height($size=100)
{
//height
$this->img["tinggi_thumb"]=$size;
@$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"];
}

function size_width($size=100)
{
//width
$this->img["lebar_thumb"]=$size;
@$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"];
}

function size_auto($size=100)
{
//size
if ($this->img["lebar"]>=$this->img["tinggi"]) {
$this->img["lebar_thumb"]=$size;
@$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"];
} else {
$this->img["tinggi_thumb"]=$size;
@$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"];
}
}

function jpeg_quality($quality=80)
{
//jpeg quality
$this->img["quality"]=$quality;
}

function show($reklama)
{
//show thumb
@Header("Content-Type: image/".$this->img["format"]);

/* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/
$this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]);
@imagecopyresized ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]);
if ((((imagesx($this->img["des"]))>=130)||((imagesy($this->img["des"]))>=130))&&($reklama == true))
{
$tour_w = 130;
$tour_h = 10;
$this->img["text_w"]=($this->img["lebar_thumb"]- $tour_w - 5);
$this->img["text_h"]=($this->img["tinggi_thumb"]- $tour_h - 5);
$this->img["text_ws"]=($this->img["lebar_thumb"]- $tour_w - 4);
$this->img["text_hs"]=($this->img["tinggi_thumb"]- $tour_h - 4);
$mark_shadow=imagecolorallocate($this->img["des"], 0, 0, 0);
imagestring($this->img["des"], 2, $this->img["text_ws"], $this->img["text_hs"], '[линк]', $mark_shadow);
$mark_col=imagecolorallocate($this->img["des"], 200, 200, 200);
imagestring($this->img["des"], 2, $this->img["text_w"], $this->img["text_h"], '[линк]', $mark_col);
}
if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {
//JPEG
imageJPEG($this->img["des"],"",$this->img["quality"]);
} elseif ($this->img["format"]=="PNG") {
//PNG
imagePNG($this->img["des"]);
} elseif ($this->img["format"]=="GIF") {
//GIF
imageGIF($this->img["des"]);
} elseif ($this->img["format"]=="WBMP") {
//WBMP
imageWBMP($this->img["des"]);
}
}

function save($save="")
{
//save thumb
if (empty($save)) $save=strtolower("./thumb.".$this->img["format"]);
/* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/
$this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]);
@imagecopyresized ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]);
if (((imagesx($this->img["des"]))>=100)||((imagesy($this->img["des"]))>=100))
{
$tour_w = 130;
$tour_h = 10;
$this->img["text_w"]=($this->img["lebar_thumb"]- $tour_w - 4);
$this->img["text_h"]=($this->img["tinggi_thumb"]- $tour_h - 4);
$mark_col=imagecolorallocate($this->img["des"], 0, 0, 0);
// ako iska6 da ne zapisva faila s nadpisa premahni sledva6tia red, a ako iska6 da e s 4erna sianka naprvi go kato v gornata funkcia show()
imagestring($this->img["des"], 2, $this->img["text_w"], $this->img["text_h"], '[линк]', $mark_col);
}

if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {
//JPEG
imageJPEG($this->img["des"],"$save",$this->img["quality"]);
} elseif ($this->img["format"]=="PNG") {
//PNG
imagePNG($this->img["des"],"$save");
} elseif ($this->img["format"]=="GIF") {
//GIF
imageGIF($this->img["des"],"$save");
} elseif ($this->img["format"]=="WBMP") {
//WBMP
imageWBMP($this->img["des"],"$save");
}
}
}
?>

Отговор