PHP - thumbs cuadradas en php

 
Vista:

thumbs cuadradas en php

Publicado por trenth (22 intervenciones) el 10/11/2007 22:29:29
buenas noches amigos, tengo un pequeño inconveniente al generar thumbnails de mi galeria de imagenes...

el detalle principal es que necesito generar imagenes de un tamaño estandar y con php solo se hacer tamaños variables... ejemplo..

si tengo una imagen de 640 x 480 solo se redimencionarla en porcentajes tales como 10% que seria 64 x 48.
en el caso de la imagen de 640 x 480 me funciona a la perfeccion... pero cuando la imagen es vertical. 480 x 640 me genera un thumb vertical. y mi idea es que todos los thumbs tengan la misma medida...

aunque no hace falta... pegare el codigo fuente de la galeria por si alguno lo necesita....
saludos. espero sus respuestas...


<?php
$dirfiles = array();

$handle=opendir('.');
while ($file = readdir($handle)) {
if
((
strtolower(strrchr($file, '.')) == ".jpg" OR
strtolower(strrchr($file, '.')) == ".jpeg" OR
strtolower(strrchr($file, '.')) == ".png" OR
strtolower(strrchr($file, '.')) == ".gif"
)
&&
(
strstr($file, ".thumb.jpg") == ''
))
{
array_push($dirfiles, $file);
}
}
sort ($dirfiles);
closedir($handle);

echo "<table width=\"505\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" id=\"structure\"><tr>";


foreach($dirfiles as $aktuellesfile)
{
$dateiendung = strrchr( $aktuellesfile, '.' );
$dateiname = substr_replace ($aktuellesfile, '', -strlen($dateiendung) );

createthumb ($dateiname, $dateiendung);
echo "<td>";
showthumb ($dateiname, $dateiendung);
echo "</td>";
if(++$cnt % 5 == 0) echo "</tr>";
}

exit;


function createthumb ($thumbdateiname, $thumbdateiendung)
{
$fullname = $thumbdateiname.$thumbdateiendung;
$fullthumbname = $thumbdateiname.$thumbdateiendung.".thumb.jpg";

if (file_exists($fullthumbname) OR strstr($fullname, ".thumb.jpg") != '')
{
}
else
{
if ((strtolower($thumbdateiendung) == ".jpg") OR (strtolower($thumbdateiendung) == ".jpeg")){
$src_img = imagecreatefromjpeg($fullname);
}
if (strtolower($thumbdateiendung) == ".gif"){
$src_img = imagecreatefromgif($fullname);
}
if (strtolower($thumbdateiendung) == ".png"){
$src_img = imagecreatefrompng($fullname);
}

$origx=imagesx($src_img);
$origy=imagesy($src_img);

$max_x = 90;
$max_y = 90;

if($origx >= $origy AND $origx > $max_x)
{
$faktor = $origx / $max_x;
$new_x = $origx / $faktor;
$new_y = $origy / $faktor;
}

elseif($origy > $origx AND $origy > $max_y)
{
$faktor = $origy / $max_y;
$new_x = $origx / $faktor;
$new_y = $origy / $faktor;
}

else
{
$new_x = $origx;
$new_y = $origy;
}

$dst_img = imagecreatetruecolor($new_x,$new_y);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_x,$new_y,imagesx($src_img),imagesy($src_img));
imagejpeg($dst_img, $fullthumbname, 50);
}
}

function showthumb ($thumbdateiname, $thumbdateiendung)
{
$fullname = $thumbdateiname.$thumbdateiendung;
$fullthumbname = $thumbdateiname.$thumbdateiendung.".thumb.jpg";
if (file_exists($fullthumbname))
{
echo "<a href=\"$fullname\"><img src =\"$fullthumbname\" border=\"0\"></a>";

}
else
{
}

}
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder