Jump to content


Photo

Ajuda Com A Função: Imagecopyresampled


  • Faça o login para participar
1 reply to this topic

#1 Junior Rodrigues

Junior Rodrigues

    Novato no fórum

  • Usuários
  • 2 posts
  • Sexo:Não informado

Posted 12/04/2006, 14:20

Olá amigos! (y)
Estou tentando fazer um sistema com thumbnails com qualidade, ou seja, com uma boa resolução. Mas meu conhecimento em php é meio limitado, estudo a pouco tempo...
Mas indo ao que interessa, quero fazer thumb pegando apenas parte de uma foto grande, pois o thumb seria em um tamanho "quadrado", e se eu puchá-lo da foto toda, ele ficaria distorcido...
afunção que eu posso pegar apenas a area desejada de uma imagem pra fazer um thumb seria a imagecopyresampled??

ja tentei a partir disso aqui:

imagecopymerge($original , $meu_logo , $imagem_x - ($logo_x + 3) , $imagem_y - ( $logo_y + 3 ) , 0 , 0 , $logo_x , $logo_y , 100);
	$nova		= imagecreatetruecolor($largurad,$alturad);
	imagecopyresampled($nova,$original,0,0,0,0,$largurad,$alturad,$imagem_x,$imagem_y);

mas os numeros que atribuo a esses "zeros" que tem, so mudam a imagem de posição, mas não mechem no tamanho...

alguém pode me ajudar? :(

Edição feita por: Junior Rodrigues, 12/04/2006, 14:27.


#2 rEd nEcK *

rEd nEcK *

    |̲̅<̲̅Θ̲̅>̲̅|

  • Usuários
  • 164 posts
  • Sexo:Masculino
  • Localidade:São Paulo

Posted 13/04/2006, 00:51

Olha eu tive esse problema também cara..

A solução foi a seguinte:

Eu crio uma imagem do tamanho da que quero, dentro dela ponho o thumb e a assinatura, no imagecopyresized que copia a assinatura é só por o tamanho certo, que funciona...

Vou estar postando aqui uma class que fiz para trabalhar com Thumb's, provavelmente não vai servir para você, pois está baseada em path's e tudo do meu sistema... Mas sempre é bom olhar para tirar umas ideias

<?php

include "Config.php";
include "bmpfix.php";

class Thumb{
var $img, $file, $percent;
var $imgWidth, $imgHeight;
var $sign, $signWidth, $signHeight;

function Thumb($file,$percent){
$this->file = $file;
$this->percent = $percent;
$this->sign = SIGN;
list($this->imgWidth, $this->imgHeight) = getimagesize('../Uploads/'.md5(strtolower($this->file)));
if( file_exists('../Uploads/'.md5(strtolower($this->sign))) ) list($this->signWidth, $this->signHeight) = getimagesize('../Uploads/'.md5(strtolower($this->sign)));
}
function ImageCreateFromAll($file){
$extension = pathinfo($file, PATHINFO_EXTENSION);
if( $extension == "jpg" )
return imagecreatefromjpeg('../Uploads/'.md5(strtolower($file)));
elseif( $extension == "png" )
return imagecreatefrompng('../Uploads/'.md5(strtolower($file)));
elseif( $extension == "gif" )
return imagecreatefromgif('../Uploads/'.md5(strtolower($file)));
elseif( $extension == "bmp" )
return imagecreatefrombmp('../Uploads/'.md5(strtolower($file)));
else
return false;
}
function AddSign(){
#header('Content-type: image/jpeg');
$sign = $this->ImageCreateFromAll($this->sign);

$newwidth = ($this->imgWidth*$this->percent);
$newheight = ($this->imgHeight*$this->percent);

imagecopyresized($this->img, $sign, 3, 3, 0, 0, $this->signWidth, $this->signHeight, $this->signWidth, $this->signHeight);
#imagecopymerge($this->img , $sign, 0, 0, 0, 0, $this->signWidth, $this->signHeight, 100);

#imagejpeg($this->img);
#imagedestroy($this->img);
}
function MakeThumb(){
#header('Content-type: image/jpeg');
$file = $this->ImageCreateFromAll($this->file);

$newwidth = ($this->imgWidth*$this->percent);
$newheight = ($this->imgHeight*$this->percent);

$this->img = imagecreatetruecolor($newwidth, $newheight);
imagecopyresized($this->img, $file, 0, 0, 0, 0, $newwidth, $newheight, $this->imgWidth, $this->imgHeight);

#imagejpeg($this->img);
#imagedestroy($this->img);
}
function Show(){
header('Content-type: image/jpeg');
$filename = ($this->percent >= 1) ? str_replace(" ","_",$this->file) : str_replace(" ","_","Thumb_".$this->file);
header("Content-Disposition: inline; filename={$filename}");

$this->MakeThumb();
if( $this->percent >= 1 && file_exists('../Uploads/'.md5(strtolower($this->sign))) ) $this->AddSign();

imagejpeg($this->img);
imagedestroy($this->img);
}
}

$thumb = new Thumb($_GET["source"],$_GET["percent"]);
$thumb->Show();

?>


Qualquer duvida só postar ai
Abraços

Edição feita por: rEd nEcK *, 13/04/2006, 00:54.

~/ ArrastoMemo.Com - Porque ganhar não é tudo, tem que humilhar o adversário /~




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq