Jump to content
Fórum Script Brasil
  • 0

(Resolvido) Redimensionar igual do Orkut


Dexter Morgan

Question

Olá consegui desenvolver um código pegando um pouco aqui e ali que faz redimenciona a imagem igual no orkut exe:

se Horizontal for maior que 800 ele faz o resize para 800 proporcionamente com o tamanho verticcal então fica +- assim

1280 x 800 = 800 x 533 +- isso ..

e o legal que faz extamento o mesmo se de em vez de horizontal a vertical for maior assim:

800 X 1280 = 533 x 800

mas tem alguns erros que não consegui corrigir segue o código

resize.php

<?php

function redimensionar($imagem, $name, $medida, $pasta){
$img = imagecreatefromjpeg($imagem['tmp_name']);
$x = imagesx($img);
$y = imagesy($img);
if($x>$y){
$medida[0]=800;
$medida[1]=($medida[0] * $y)/$x;
}
else{
$medida[1]=800;
$medida[0]=($medida[1] * $x)/$y;
}
$nova = imagecreatetruecolor($medida[0],$medida[1]);
imagecopyresampled($nova, $img, 0, 0, 0, 0, $medida[0], $medida[1],imagesx($img), imagesy($img));
imagejpeg($nova, "$pasta/$name");
imagedestroy($img);
imagedestroy($nova);
return $name;
}

?>
quero implementar ele nesse código de mullti envio
<?php

if(isset($_POST['submit'])){
$id_noticias = $_GET["id_noticias"];
$fotos = $_FILES["img"];
$pasta = 'fotos/';
foreach($_FILES["img"]["error"] as $key => $error){
if($error == UPLOAD_ERR_OK){
$tmp_name = $_FILES["img"]["tmp_name"][$key];
$ext = array("jpeg","jpg","png","gif");
$fotos = md5(uniqid(time())) . "." . $ext[1];
$uploadfile = $pasta . basename($fotos);
if(move_uploaded_file($tmp_name, $uploadfile)){
echo "<script>alert('Publicado com Sucesso!');document.location.href='java script:history.back()';</script>";
$insert = mysql_query("INSERT INTO fotos (id_noticias, fotos) VALUES ('$id_noticias', '$fotos')");
}
else{
echo "<script>alert('Erro ao Publicar!');document.location.href='java script:history.back()';</script>";
}
}
}
}

?>

o erro no resize é que se foto for menor que 800 ele faz ela ficar com 800 se 10 po 10 ele faz ficar com 800 por 800 tenso isso rsr quem puder ajudar vlw.

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Oi Dexter,

eu criei um arquivo que uso pra dimensionar na hora de mostrar. Vê se te ajuda.

pra chamar uso assim:

<img src="thumb_maker.php?img=ENDERECOIMAGEM&x=100&y=100" border="0">
img é o endereço, x é a largura e y a altura da imagem. Se passar só o valor de x
<img src="thumb_maker.php?img=ENDERECOIMAGEM&x=100" border="0">
vai redimencionar proporcionalmente, mesma coisa se passar só o valor de y. o arquivo é esse: thumb_maker.php
<?
        ini_set("memory_limit","1000M");
    ini_set('allow_url_fopen', 'on');
    $MaxLarg = $largura = $_GET["x"] != ''?$_GET["x"]:'';
    $MaxAlt = $altura = $_GET["y"] != ''?$_GET["y"]:'';
    
    $tb_x = $_GET["tb_x"] != ''?$_GET["tb_x"]:'';
    $tb_y = $_GET["tb_y"] != ''?$_GET["tb_y"]:'';
    
    $foto = $_GET["img"];
    
    $Ext = substr($foto,-4);
    if(strtoupper($Ext) == ".JPG") 
    {        
        $ExtFunc = "jpeg";    
    }elseif(strtoupper($Ext) == ".GIF")
    {
        $ExtFunc = "gif";
    }elseif(strtoupper($Ext) == ".PNG")
    {
        $ExtFunc = "png";
    }
    
    $CriarImagemDe = "imagecreatefrom" . $ExtFunc;
    
    $img = $img_origem = $CriarImagemDe($foto);
    
    $numWdt = $origX = imagesx($img_origem);
    $numHgt = $origY = imagesy($img_origem);
    
    if($largura != '' && $altura != '')
    {                                
        if(($tb_x == '' && $tb_y == '') || ($tb_x == 0 && $tb_y == 0))
        {
            if( ($MaxLarg > $numWdt) && ($MaxAlt > $numHgt) ) 
            {
                $nova = $img_origem;
                $width = $numWdt;
                $height = $numHgt;
            }else
            {
                $areanova = $MaxLarg*$MaxAlt; 
                $largarea = $MaxAlt * $numWdt;
                $altarea = $MaxLarg * $numHgt; 
                $maxlargarea = $areanova / $largarea;
                $maxaltarea = $areanova / $altarea; 
                if($maxlargarea > $maxaltarea) 
                {
                    $width = $maxlargarea*$numWdt;
                    $height = $maxlargarea*$numHgt;
                }else
                {
                    $width = $maxaltarea*$numWdt;
                    $height = $maxaltarea*$numHgt;
                };
                $nova = imagecreatetruecolor($width,$height);
                
                imagesavealpha($nova, true);
                $trans_colour = imagecolorallocatealpha($nova, 0, 0, 0, 127);
                imagefill($nova, 0, 0, $trans_colour);

                imagecopyresampled($nova, $img_origem, 0,0,0,0,$width,$height,$numWdt-1,$numHgt);
            };
     
            if($width > $MaxLarg) 
            {
                $nx = ($width-$MaxLarg)/2;
            }else 
            {
                $nx = 0;
            }
            if($height < $MaxAlt) 
            {
                $ny = ($height-$MaxAlt)/2;
            }else 
            {
                $ny = 0;
            }
             
            $i = imagecreatetruecolor($MaxLarg,$MaxAlt);
            
            imagesavealpha($i, true);
            $trans_colour = imagecolorallocatealpha($i, 0, 0, 0, 127);
            imagefill($i, 0, 0, $trans_colour);
                
            imagecopy($i, $nova, 0, 0, $nx, $ny,$MaxLarg,$MaxAlt);
        }else
        {            
            $destX = $largura;
            $destY = $altura;
            if($origY>$origX)
            {
                $porc = ($largura*100)/$origX;
                $destY = $tamY = ($origY*$porc)/100;
                if($destY<=$MaxAlt) $destY=$MaxAlt;
            }else
            {
                
                $porc = ($altura*100)/$origY;
                $destX = $tamX = ($origX*$porc)/100;
                if($destX<=$MaxLarg) $destX=$MaxLarg;                
            }
            $img_destino = imagecreatetruecolor($destX,$destY);
            
            imagesavealpha($img_destino, true);
            $trans_colour = imagecolorallocatealpha($img_destino, 0, 0, 0, 127);
            imagefill($img_destino, 0, 0, $trans_colour);
            
            imagecopyresampled( $img_destino, $img_origem, 0, 0, 0, 0, $destX, $destY, $origX, $origY );
            
            $porcy = ($tb_y*100)/$origY;
            $ny = ($MaxAlt*$porcy)/100;
            
            $porcx = ($tb_x*100)/$origX;
            $nx = ($MaxLarg*$porcx)/100;
            
            if(($destY-$ny)<$MaxAlt) $ny = $destY-$MaxAlt;
            if(($destX-$nx)<$MaxLarg) $nx = $destX-$MaxLarg;
            
            $i = imagecreatetruecolor($MaxLarg,$MaxAlt);
            
            imagesavealpha($i, true);
            $trans_colour = imagecolorallocatealpha($i, 0, 0, 0, 127);
            imagefill($i, 0, 0, $trans_colour);
            
            imagecopy($i, $img_destino, 0, 0, $nx, $ny,$destX,$destY);            
        }
        $img = $i;
    }else
    {
        $destX = $largura;
        $destY = $altura;
        if($largura != '')
        {
            $porc = ($largura*100)/$origX;
            $destY = $tamY = ($origY*$porc)/100;
        }
        if($altura != '')
        {    
            $porc = ($altura*100)/$origY;
            $destX = $tamX = ($origX*$porc)/100;
        }    
        $img_destino = imagecreatetruecolor($destX,$destY);
        
        imagesavealpha($img_destino, true);
        $trans_colour = imagecolorallocatealpha($img_destino, 0, 0, 0, 127);
        imagefill($img_destino, 0, 0, $trans_colour);
        
        imagecopyresampled( $img_destino, $img_origem, 0, 0, 0, 0, $destX, $destY, $origX, $origY );
        imagedestroy($img_origem); 
        $img = $img_destino;
    }

    header('Content-type: image/'.$ExtFunc); 
    $aux = 'image'.$ExtFunc;        
    
    if($ExtFunc == 'png') $aux($img);    
        else $aux($img,NULL,100);    
    imagedestroy($img);
?>
Olá consegui desenvolver um código pegando um pouco aqui e ali que faz redimenciona a imagem igual no orkut exe: se Horizontal for maior que 800 ele faz o resize para 800 proporcionamente com o tamanho verticcal então fica +- assim 1280 x 800 = 800 x 533 +- isso .. e o legal que faz extamento o mesmo se de em vez de horizontal a vertical for maior assim: 800 X 1280 = 533 x 800 mas tem alguns erros que não consegui corrigir segue o código resize.php
<?php

function redimensionar($imagem, $name, $medida, $pasta){
$img = imagecreatefromjpeg($imagem['tmp_name']);
$x = imagesx($img);
$y = imagesy($img);
if($x>$y){
$medida[0]=800;
$medida[1]=($medida[0] * $y)/$x;
}
else{
$medida[1]=800;
$medida[0]=($medida[1] * $x)/$y;
}
$nova = imagecreatetruecolor($medida[0],$medida[1]);
imagecopyresampled($nova, $img, 0, 0, 0, 0, $medida[0], $medida[1],imagesx($img), imagesy($img));
imagejpeg($nova, "$pasta/$name");
imagedestroy($img);
imagedestroy($nova);
return $name;
}

?>
quero implementar ele nesse código de mullti envio
<?php

if(isset($_POST['submit'])){
$id_noticias = $_GET["id_noticias"];
$fotos = $_FILES["img"];
$pasta = 'fotos/';
foreach($_FILES["img"]["error"] as $key => $error){
if($error == UPLOAD_ERR_OK){
$tmp_name = $_FILES["img"]["tmp_name"][$key];
$ext = array("jpeg","jpg","png","gif");
$fotos = md5(uniqid(time())) . "." . $ext[1];
$uploadfile = $pasta . basename($fotos);
if(move_uploaded_file($tmp_name, $uploadfile)){
echo "&lt;script>alert('Publicado com Sucesso!');document.location.href='java script:history.back()';</script>";
$insert = mysql_query("INSERT INTO fotos (id_noticias, fotos) VALUES ('$id_noticias', '$fotos')");
}
else{
echo "&lt;script>alert('Erro ao Publicar!');document.location.href='java script:history.back()';</script>";
}
}
}
}

?>

o erro no resize é que se foto for menor que 800 ele faz ela ficar com 800 se 10 po 10 ele faz ficar com 800 por 800 tenso isso rsr quem puder ajudar vlw.

Link to comment
Share on other sites

  • 0

Tiago Biage , esse código aí funciona beleza e é bastante util ,,mas para esse meu código não serve pois também quero evitar fotos grandes no servidor , mas esse teu código vai me ser util em outro projeto,,

uma pergunta tipo ali testei e vi que ele faz a proporção corretamente ,,mas teria como tipo fazer outro valor para ele diferenciar em qual parte tem a medida maior??

ex foto tem a largura maior que a altura então ficaria 800 com a altura proporcional certo

<img src="thumb_maker.php?img=ENDERECOIMAGEM&outrovalor=800" border="0">
ex foto tem a altura maior que a largura então ficaria 800 com a largura proporcional certo
<img src="thumb_maker.php?img=ENDERECOIMAGEM&outrovalor=800" border="0">

agora se os valores da imagem forem menor que 800 mostra o tamanho real.

vlw cara mesmo assim,,,,

Edited by Dexter Morgan
Link to comment
Share on other sites

  • 0

[28-Sep-2011 00:42:00] PHP Warning: imagecreatefromjpeg() [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: gd-jpeg: JPEG library reports unrecoverable error: in /home/jornalv/public_html/administracao/fotos/resize.php on line 21
[28-Sep-2011 00:42:00] PHP Warning: imagecreatefromjpeg() [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: '34df8473ab6f61af670b1b3ae4a50d93.jpg' is not a valid JPEG file in /home/jornalv/public_html/administracao/fotos/resize.php on line 21
[28-Sep-2011 00:42:00] PHP Warning: imagesx(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 22
[28-Sep-2011 00:42:00] PHP Warning: imagesy(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 23
[28-Sep-2011 00:42:00] PHP Warning: Division by zero in /home/jornalv/public_html/administracao/fotos/resize.php on line 105
[28-Sep-2011 00:42:00] PHP Warning: imagecreatetruecolor() [<a href='function.imagecreatetruecolor'>function.imagecreatetruecolor</a>]: Invalid image dimensions in /home/jornalv/public_html/administracao/fotos/resize.php on line 112
[28-Sep-2011 00:42:00] PHP Warning: imagesavealpha(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 113
[28-Sep-2011 00:42:00] PHP Warning: imagecolorallocatealpha(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 114
[28-Sep-2011 00:42:00] PHP Warning: imagefill(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 115
[28-Sep-2011 00:42:00] PHP Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 116
[28-Sep-2011 00:42:00] PHP Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 117
[28-Sep-2011 00:42:00] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/jornalv/public_html/administracao/fotos/resize.php:21) in /home/jornalv/public_html/administracao/fotos/resize.php on line 120
[28-Sep-2011 00:42:00] PHP Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 123
[28-Sep-2011 00:42:00] PHP Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 124
[28-Sep-2011 00:43:00] PHP Warning: imagecreatefromjpeg() [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: gd-jpeg: JPEG library reports unrecoverable error: in /home/jornalv/public_html/administracao/fotos/resize.php on line 21
[28-Sep-2011 00:43:00] PHP Warning: imagecreatefromjpeg() [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: '34df8473ab6f61af670b1b3ae4a50d93.jpg' is not a valid JPEG file in /home/jornalv/public_html/administracao/fotos/resize.php on line 21
[28-Sep-2011 00:43:00] PHP Warning: imagesx(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 22
[28-Sep-2011 00:43:00] PHP Warning: imagesy(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 23
[28-Sep-2011 00:43:00] PHP Warning: Division by zero in /home/jornalv/public_html/administracao/fotos/resize.php on line 105
[28-Sep-2011 00:43:00] PHP Warning: imagecreatetruecolor() [<a href='function.imagecreatetruecolor'>function.imagecreatetruecolor</a>]: Invalid image dimensions in /home/jornalv/public_html/administracao/fotos/resize.php on line 112
[28-Sep-2011 00:43:00] PHP Warning: imagesavealpha(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 113
[28-Sep-2011 00:43:00] PHP Warning: imagecolorallocatealpha(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 114
[28-Sep-2011 00:43:00] PHP Warning: imagefill(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 115
[28-Sep-2011 00:43:00] PHP Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 116
[28-Sep-2011 00:43:00] PHP Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 117
[28-Sep-2011 00:43:00] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/jornalv/public_html/administracao/fotos/resize.php:21) in /home/jornalv/public_html/administracao/fotos/resize.php on line 120
[28-Sep-2011 00:43:00] PHP Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 123
[28-Sep-2011 00:43:00] PHP Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 124
[28-Sep-2011 00:52:14] PHP Warning: imagecreatefromjpeg() [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: gd-jpeg: JPEG library reports unrecoverable error: in /home/jornalv/public_html/administracao/fotos/resize.php on line 21
[28-Sep-2011 00:52:14] PHP Warning: imagecreatefromjpeg() [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: 'c5c78c75d60724a4f9879171493e0893.jpg' is not a valid JPEG file in /home/jornalv/public_html/administracao/fotos/resize.php on line 21
[28-Sep-2011 00:52:14] PHP Warning: imagesx(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 22
[28-Sep-2011 00:52:14] PHP Warning: imagesy(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 23
[28-Sep-2011 00:52:14] PHP Warning: Division by zero in /home/jornalv/public_html/administracao/fotos/resize.php on line 105
[28-Sep-2011 00:52:14] PHP Warning: imagecreatetruecolor() [<a href='function.imagecreatetruecolor'>function.imagecreatetruecolor</a>]: Invalid image dimensions in /home/jornalv/public_html/administracao/fotos/resize.php on line 112
[28-Sep-2011 00:52:14] PHP Warning: imagesavealpha(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 113
[28-Sep-2011 00:52:14] PHP Warning: imagecolorallocatealpha(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 114
[28-Sep-2011 00:52:14] PHP Warning: imagefill(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 115
[28-Sep-2011 00:52:14] PHP Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 116
[28-Sep-2011 00:52:14] PHP Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 117
[28-Sep-2011 00:52:14] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/jornalv/public_html/administracao/fotos/resize.php:21) in /home/jornalv/public_html/administracao/fotos/resize.php on line 120
[28-Sep-2011 00:52:14] PHP Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 123
[28-Sep-2011 00:52:14] PHP Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/jornalv/public_html/administracao/fotos/resize.php on line 124

cara as vezez ocorre esse erro nas fotos, parece que é invalidas tem como corrigir?

Edited by Dexter Morgan
Link to comment
Share on other sites

  • 0

deu certo agora se a foto for menor deixa como esta ficou assim

<?php

function redimensionar($imagem, $name, $medida, $pasta){
$img = imagecreatefromjpeg($imagem['tmp_name']);
$x = imagesx($img);
$y = imagesy($img);
$medida[0]=800;
$medida[1]=800;
if($x>$medida[0] || $y>$medida[1]){
if($x>$y){
$medida[1]=($medida[0] * $y)/$x;
}
elseif($y>$x){
$medida[0]=($medida[1] * $x)/$y;
}
else{
$medida[0]=$x/($x/$medida[0]);
$medida[1]=$y/($y/$medida[1]);
}
}
else{
$medida[0]=$x;
$medida[1]=$y;
}
$nova = imagecreatetruecolor($medida[0],$medida[1]);
imagecopyresampled($nova, $img, 0, 0, 0, 0, $medida[0], $medida[1], imagesx($img), imagesy($img));
imagejpeg($nova, "$pasta/$name");
imagedestroy($img);
imagedestroy($nova);
return $name;
}

?>
<?php

if(isset($_POST['acao']) && $_POST['acao'] == 'cadastrar'){
$foto = $_FILES['foto'];
if($foto['type'] == 'image/jpeg'){
require("resize.php");
$name = 'foto='.md5(uniqid(rand(), true)).".jpg";
redimensionar($foto, $name, $medida, "fotos");
}
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Redimensionar Imagem</title>
</head>

        <body>

<form method="post" action="" enctype="multipart/form-data">
<font face="verdana" color="#888888" size="2">Fotos</font><br />
<input type="file" name="foto" /><br /><br />
<input type="submit" value="enviar fotos" />
<input type="hidden" name="acao" value="cadastrar" />
</form>

        </body>

</html>
mas agora precisava implementar ele nesse código como disse acima
<?php

if(isset($_POST['submit'])){
$id_noticias = $_GET["id_noticias"];
$fotos = $_FILES["img"];
$pasta = 'fotos/';
foreach($_FILES["img"]["error"] as $key => $error){
if($error == UPLOAD_ERR_OK){
$tmp_name = $_FILES["img"]["tmp_name"][$key];
$ext = array("jpeg","jpg","png","gif");
$fotos = md5(uniqid(time())) . "." . $ext[1];
$uploadfile = $pasta . basename($fotos);
if(move_uploaded_file($tmp_name, $uploadfile)){
echo "<script>alert('Publicado com Sucesso!');document.location.href='java script:history.back()';</script>";
$insert = mysql_query("INSERT INTO fotos (id_noticias, fotos) VALUES ('$id_noticias', '$fotos')");
}
else{
echo "<script>alert('Erro ao Publicar!');document.location.href='java script:history.back()';</script>";
}
}
}
}

?>

já tentei e não consegui ...

Link to comment
Share on other sites

  • 0

<?php

class redimensionar{
var $image;
var $image_type;
function load($filename){
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if($this->image_type == IMAGETYPE_JPEG){
$this->image = imagecreatefromjpeg($filename);
}
elseif($this->image_type == IMAGETYPE_GIF){
$this->image = imagecreatefromgif($filename);
}
elseif($this->image_type == IMAGETYPE_PNG){
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null){
if($image_type == IMAGETYPE_JPEG){
imagejpeg($this->image,$filename,$compression);
}
elseif($image_type == IMAGETYPE_GIF){
imagegif($this->image,$filename);
}
elseif($image_type == IMAGETYPE_PNG){
imagepng($this->image,$filename);
}
if($permissions != null){
chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG){
if($image_type == IMAGETYPE_JPEG){
imagejpeg($this->image);
}
elseif($image_type == IMAGETYPE_GIF){
imagegif($this->image);
}
elseif($image_type == IMAGETYPE_PNG){
imagepng($this->image);
}
}
function getWidth(){
return imagesx($this->image);
}
function getHeight(){
return imagesy($this->image);
}
function resizeToScale($width){
$width=800;
$height=800;
if($this->getWidth()>$width || $this->getHeight()>$height){
if($this->getWidth()>$this->getHeight()){
$height=($width * $this->getHeight())/$this->getWidth();
$this->resize($width,$height);
}
elseif($this->getHeight()>$this->getWidth()){
$width=($height * $this->getWidth())/$this->getHeight();
$this->resize($width,$height);
}
else{
$width=$this->getWidth()/($this->getWidth()/$width);
$height=$this->getHeight()/($this->getHeight()/$height);
$this->resize($width,$height);
}
}
else{
$width=$this->getWidth();
$height=$this->getHeight();
$this->resize($width,$height);
}
}
function resize($width,$height){
$new_image = imagecreatetruecolor($width,$height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
}

?>
if(move_uploaded_file($tmp_name, $uploadfile)){
include_once('redimensiona.php');
$image = new redimensionar();
$image->load($uploadfile);
$image->resizeToScale(800);
$image->save($uploadfile);

ta aí

funciona beleza ...

Link to comment
Share on other sites

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...