Ver Mensaje Individual
  #3 (permalink)  
Antiguo 11/10/2008, 15:09
Avatar de ElJavista
ElJavista
Colaborador
 
Fecha de Ingreso: marzo-2007
Ubicación: Lima Perú
Mensajes: 2.231
Antigüedad: 17 años, 2 meses
Puntos: 67
Respuesta: Recortar solo un area de una imagen usando GD

Bueno, si haz podido hacer una cosa y no puedes lo otro entonces talvez estés usando un código que otro haya escrito y que no lo entiendes bien, esa sería la única explicación para entender como es que haz tenido el ingenio de hacer una cosa pero no haz podido hacer lo otro. En fin, aquí te dejo el código que hace el recorte:

Código PHP:
function imgCorte($img$cImg$we$he) {
            list(
$w$h$tip) = getimagesize($img);
  
            if (
$w $we $h $he) {
                
$hp $h;
                
$wp round(($we $he) * $hp);
            }  else {
                
$wp $w;
                
$hp round(($he $we) * $wp);
            }

            
$lp round(($w $wp) / 2);
            
$tp round(($h $hp) / 2);

            
$thumb imagecreatetruecolor($we$he);
            if (
$tip == 1) {
                
$source imagecreatefromgif($img);
            }  elseif (
$tip == 2) {
                
$source imagecreatefromjpeg($img);
            }  elseif (
$tip == 3) {
                
$source imagecreatefrompng($img);
            }

            
imagecopyresampled($thumb$source00$lp$tp$we$he$wp$hp);
            
imagejpeg($thumb$cImg);

Espero que te sirva.