Jump to content
Fórum Script Brasil
  • 0

Thumbnail


MTavares

Question

Olá colegas,

tudo bem? eu tenho um sistema de thumbnail, só que agora fui pego de surpresa, do qual eu tenho um cliente que as imagens são de vários tamanhos, com isso, algumas imagens ficam muito pequenas e não quero criar popup para abrí-lo. Alguém conhece algum sistema de thumbnail do qual possa padronizar as imagens?

Segue abaixo o que uso (vale ressaltar que esse sistema não é de minha autoria):

if (!file_exists($diretorio."/thumb_".$foto)){

$thumb=new thumbnail($diretorio."/".$foto);

$thumb->size_auto(100);

$thumb->jpeg_quality(75);

$thumb->save($diretorio."/thumb_".$foto, $gd_version);

}

$ver_imagem = "".$diretorio."/thumb_".$foto."";

<img src="<?=$ver_imagem;?>" border="0" title="<?=$mt_produto->produto;?>">

Na pasta imagens, fica um arquivo, segue abaixo:

<?php

/***************************************************************************

* Copyright: Copyright 2003 http://www.brooky.com

*

***************************************************************************/

// CONFIGURATION FOR THUMBNAILS

// FOR GD VERSION 1.6 (default) SET $gd_version=1;

// FOR GD VERSION 2.0+ FOR IMPROVED THUMBNAILS SET $gd_version=2;

// IF YOU DO NOT HAVE GD SET $gd_version=0;

$gd_version=2;

// HOW CAN I TELL WHAT VERSION I RUN?

// Login to admin and click server environment off the main menu.

// If you have GD you will see a table entitled GD and the

// version number will be displayed there. :o)

// END THUMBNAILS CONFIG

// *************************************************************************

class thumbnail

{

var $img;

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") {

//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);

} else {

//DEFAULT

echo "Arquivo não suportado pelo sistema... favor enviar com imagens com extensão .jpg and .png!";

exit();

}

@$this->img["lebar"] = imagesx($this->img["src"]);

@$this->img["tinggi"] = imagesy($this->img["src"]);

//default quality jpeg

$this->img["quality"]=75;

}

function size_auto($size=50000)

{

//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=75)

{

//jpeg quality

$this->img["quality"]=$quality;

}

function show($gd_version)

{

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

if($gd_version==2)

{

$this->img["des"] = imagecreatetruecolor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]);

@imagecopyresampled ($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($gd_version==1)

{

$this->img["des"] = imagecreate($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 ($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]);

}

}

function save($save="",$gd_version)

{

if($gd_version==2)

{

$this->img["des"] = imagecreatetruecolor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]);

@imagecopyresampled ($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($gd_version==1)

{

$this->img["des"] = imagecreate($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 ($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");

}

}

}

// *************************************************************************

?>

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...