Foros del Web » Programando para Internet » PHP »

expandir imagen al tamaño elegido

Estas en el tema de expandir imagen al tamaño elegido en el foro de PHP en Foros del Web. Hola a todos. Tengo la siguiente función y lo que hace es crear un thumb de una imagen original a un tamaño que yo le ...
  #1 (permalink)  
Antiguo 16/10/2007, 18:06
 
Fecha de Ingreso: enero-2007
Mensajes: 158
Antigüedad: 17 años, 3 meses
Puntos: 2
expandir imagen al tamaño elegido

Hola a todos.

Tengo la siguiente función y lo que hace es crear un thumb de una imagen original a un tamaño que yo le defino.

Pero... existe un problema, y es que me gustaria que si la imagen original es mas pequeña que el tamaño del thumb final, la expanda a ese tamaño.

Código PHP:
<?php

function makeIcons_MergeCenter($src$dst$dstx$dsty){

//$src = original image location
//$dst = destination image location
//$dstx = user defined width of image
//$dsty = user defined height of image

$allowedExtensions 'jpg jpeg gif png';

$name explode("."$src);
$currentExtensions $name[count($name)-1];
$extensions explode(" "$allowedExtensions);

for(
$i=0count($extensions)>$i$i=$i+1){
if(
$extensions[$i]==$currentExtensions)
$extensionOK=1
$fileExtension=$extensions[$i]; 
break; }
}

if(
$extensionOK){

$size getImageSize($src);
$width $size[0];
$height $size[1];

if(
$width >= $dstx AND $height >= $dsty){

$proportion_X $width $dstx;
$proportion_Y $height $dsty;

if(
$proportion_X $proportion_Y ){
$proportion $proportion_Y;
}else{
$proportion $proportion_X ;
}
$target['width'] = $dstx $proportion;
$target['height'] = $dsty $proportion;

$original['diagonal_center'] = 
round(sqrt(($width*$width)+($height*$height))/2);
$target['diagonal_center'] = 
round(sqrt(($target['width']*$target['width'])+
(
$target['height']*$target['height']))/2);

$crop round($original['diagonal_center'] - $target['diagonal_center']);

if(
$proportion_X $proportion_Y ){
$target['x'] = 0;
$target['y'] = round((($height/2)*$crop)/$target['diagonal_center']);
}else{
$target['x'] =  round((($width/2)*$crop)/$target['diagonal_center']);
$target['y'] = 0;
}

if(
$fileExtension == "jpg" OR $fileExtension=='jpeg'){ 
$from ImageCreateFromJpeg($src); 
}elseif (
$fileExtension == "gif"){ 
$from ImageCreateFromGIF($src); 
}elseif (
$fileExtension == 'png'){
 
$from imageCreateFromPNG($src);
}

$new ImageCreateTrueColor ($dstx,$dsty);

imagecopyresampled ($new,  $from,  00$target['x'], 
$target['y'], $dstx$dsty$target['width'], $target['height']);

 if(
$fileExtension == "jpg" OR $fileExtension == 'jpeg'){ 
imagejpeg($new$dst70); 
}elseif (
$fileExtension == "gif"){ 
imagegif($new$dst); 
}elseif (
$fileExtension == 'png'){
imagepng($new$dst);
}
}
}
}

?> 

Esa es la funcion. A ver si alguien me puede hechar una mano.

Un saludo y gracias de antemano.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:32.