note 37803 deleted from ref.image by vincent
| From: | vincent@php.net | Date: | Thu, 27 Nov 2003 19:49:29 +0000 |
| Subject: | note 37803 deleted from ref.image by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-61045@lists.php.net to get a copy of this message | ||
Note Submitter: rhallado@vspmail.com.br
----
# ------------------------------------------------------------- #
# FUNÇÃO 'THUMB' GERA UM THUMBS DE UMA IMAGEM DO FORMULÁRIO #
# FOR GD >= 2.0 #
# SCRIPT BY RHALLADO #
# $arquivo_origem = Arquivo de origem com diretório #
# $arquivo_destino = Arquivo de Destino com diretório #
# max_w = Tamanho maximo Horizontal da nova imagem #
# max_h = Tamanho maximo Vertical da nova imagem #
# qualidade = Qualidade da nova imagem #
# ------------------------------------------------------------- #
function thumb($arquivo_origem, $arquivo_destino, $max_w, $max_h, $qualidade) {
if (!is_uploaded_file($arquivo_origem) ) {
$error[] = 'O arquivo de origem: "' . $arquivo_origem . '" é
inválido!';
}
if ( $arquivo_destino == '' ) {
$error[] = 'O arquivo de destino inválido!';
}
if ( $max_w < '1' ) {
$error[] = 'Tamanho horinzontal inválido!';
}
if ( $max_h < '1' ) {
$error[] = 'Tamanho vertical inválido!';
}
if ( $qualidade < '1' ) {
$error[] = 'Qualidade de compactação inválida!';
}
if ( $error == '' ) {
copy($arquivo_origem,$arquivo_destino);
$pic = @imagecreatefromjpeg($arquivo_destino);
$real_width = imagesx($pic);
$real_height = imagesy($pic);
$scale = min($max_w/$real_width, $max_h/$real_height);
if($scale <1){
$max_w = floor($scale*$real_width);
$max_h = floor($scale*$real_height);
}
$thumb = @imagecreatetruecolor ($max_w, $max_h);
ImageCopyResampled($thumb, $pic, 0, 0, 0, 0, $max_w, $max_h, $real_width, $real_height);
Imagejpeg($thumb,$arquivo_destino,$qualidade);
}
for ($i = 0; $i < count($error); $i++){
echo "$error[$i]<br>";
}
}
if ( $file != '' ) {
thumb($_FILES['file']['tmp_name'],'deu.jpg', '400',
'300','70');
}