Foros del Web » Programando para Internet » PHP »

Editor de imágenes HTML5 + jQuery + PHP

Estas en el tema de Editor de imágenes HTML5 + jQuery + PHP en el foro de PHP en Foros del Web. Hola a todos. Hasta hace poco estaba usando Cropzoom como pequeño editor de imágenes para mis Webs. El problema es que necesito ampliar un poco... ...
  #1 (permalink)  
Antiguo 27/09/2013, 02:32
Avatar de el_javi  
Fecha de Ingreso: marzo-2005
Ubicación: MAdrid
Mensajes: 844
Antigüedad: 19 años
Puntos: 10
Editor de imágenes HTML5 + jQuery + PHP

Hola a todos.

Hasta hace poco estaba usando Cropzoom como pequeño editor de imágenes para mis Webs.

El problema es que necesito ampliar un poco... necesito poder hacer alguna cosa más, inicialmente, poder cambiar el fondo de color de mis imágenes generadas.

Osea, que si reduzco y recorto una imagen en la web X, el fondo sea negro, pero en la web Y, el fondo será blanco... Así que necesito poder hacer algo similar.


Por ello, busco un buen editor de imágenes, HTML5 (dado que mis clientes usan iPad como herramienta de trabajo) y que me de estas funcionalidades mínimas:
- Poder usar GRANDES imágenes (3000px, 5000px)
- Zoom (ampliar y reducir la imagen original)
- Recortar
- Cambiar color de fondo
---- Esto me da igual si desde el interface o desde la configuración (incluso, preferiría desde la configuración, para que el cliente no destroce la web con colores inadecuados).


Espero vuestras aportaciones.

Saludos.
  #2 (permalink)  
Antiguo 29/09/2013, 23:01
Avatar de Carlangueitor
Moderador ლ(ಠ益ಠლ)
 
Fecha de Ingreso: marzo-2008
Ubicación: México
Mensajes: 10.037
Antigüedad: 16 años, 1 mes
Puntos: 1329
Respuesta: Editor de imágenes HTML5 + jQuery + PHP

Pues podrías usar directamente GD en el servidor, y canvas en el frontend. Quizá es algo muy especifico.

Saludos
__________________
Grupo Telegram Docker en Español
  #3 (permalink)  
Antiguo 30/09/2013, 00:46
Avatar de el_javi  
Fecha de Ingreso: marzo-2005
Ubicación: MAdrid
Mensajes: 844
Antigüedad: 19 años
Puntos: 10
Respuesta: Editor de imágenes HTML5 + jQuery + PHP

¿Es algo muy específico?
¿y los CMS o gestores de contenidos de las webs no llevan editor de imagen para que el cliente recorte o encuadre las imágenes de su producto a su gusto?

Yo pensaba que podría existir alguna herramienta "medianamente y ahecha"

Yo lo tengo hecho ya con Cropzoom pero me falta poder cambiar el color de fondo...

¿Alguien podría ayudarme a editar el PHP de Cropzoom para que se pueda configurar el color de fondo de la imagen de salida cuando sea JPG?

Este es el PHP del generador de imagen:
Código PHP:
<?php
    
//    echo("<pre>");
//    var_dump($_POST);
//    echo("</pre>");
    
    
    
if (!isset($_POST["imageSource"])) {
        
$_POST["imageSource"] = "test.jpg";
    }
    
    list(
$width$height) = getimagesize($_POST["imageSource"]);
    
    
$viewPortW $_POST["viewPortW"];
    
$viewPortH $_POST["viewPortH"];
    
$pWidth $_POST["imageW"];
    
$pHeight =  $_POST["imageH"];
    
$ext end(explode(".",$_POST["imageSource"]));
    
$function returnCorrectFunction($ext);
    
$image $function($_POST["imageSource"]);
    
$width imagesx($image);
    
$height imagesy($image);
    
// Resample
    
$image_p imagecreatetruecolor($pWidth$pHeight);
    
setTransparency($image,$image_p,$ext);
    
imagecopyresampled($image_p$image0000$pWidth$pHeight$width$height);
    
imagedestroy($image);
    
$widthR imagesx($image_p);
    
$hegihtR imagesy($image_p);
    
    
$selectorX $_POST["selectorX"];
    
$selectorY $_POST["selectorY"];
    
    if(
$_POST["imageRotate"]){
        
$angle 360 $_POST["imageRotate"];
        
$image_p imagerotate($image_p,$angle,0);
        
        
$pWidth imagesx($image_p);
        
$pHeight imagesy($image_p);
        
        
//print $pWidth."---".$pHeight;
        
        
$diffW abs($pWidth $widthR) / 2;
        
$diffH abs($pHeight $hegihtR) / 2;
        
        
$_POST["imageX"] = ($pWidth $widthR $_POST["imageX"] - $diffW $_POST["imageX"] + $diffW);
        
$_POST["imageY"] = ($pHeight $hegihtR $_POST["imageY"] - $diffH $_POST["imageY"] + $diffH);
    }
    
    
    
    
$dst_x $src_x $dst_y $src_y 0;
    
    if(
$_POST["imageX"] > 0){
        
$dst_x abs($_POST["imageX"]);
    }else{
        
$src_x abs($_POST["imageX"]);
    }
    if(
$_POST["imageY"] > 0){
        
$dst_y abs($_POST["imageY"]);
    }else{
        
$src_y abs($_POST["imageY"]);
    }
    
    
    
$viewport imagecreatetruecolor($_POST["viewPortW"],$_POST["viewPortH"]);
    
setTransparency($image_p,$viewport,$ext);
    
    
imagecopy($viewport$image_p$dst_x$dst_y$src_x$src_y$pWidth$pHeight);
    
imagedestroy($image_p);
    
    
    
$selector imagecreatetruecolor($_POST["selectorW"], $_POST["selectorH"]);
    
setTransparency($viewport,$selector,$ext);
    
imagecopy($selector$viewport00$selectorX$selectorY$_POST["viewPortW"], $_POST["viewPortH"]);
    
    if (isset(
$_GET["destino"]) && !empty($_GET["destino"])) {
        
$file "../../".$_GET["destino"];
    } else {
        
$file "test".time().".".$ext;
    }
    
    
parseImage($ext,$selector,$file);
    
imagedestroy($viewport);
    
//Return value
    
echo $file;
    
/* Functions */
    
    
function determineImageScale($sourceWidth$sourceHeight$targetWidth$targetHeight) {
        
$scalex =  $targetWidth $sourceWidth;
        
$scaley =  $targetHeight $sourceHeight;
        return 
min($scalex$scaley);
    }
    
    function 
returnCorrectFunction($ext){
        
$function "";
        switch(
$ext){
            case 
"png":
                
$function "imagecreatefrompng";
                break;
            case 
"jpeg":
                
$function "imagecreatefromjpeg";
                break;
            case 
"jpg":
                
$function "imagecreatefromjpeg";
                break;
            case 
"gif":
                
$function "imagecreatefromgif";
                break;
        }
        return 
$function;
    }
    
    function 
parseImage($ext,$img,$file null){
        switch(
$ext){
            case 
"png":
                
imagepng($img,($file != null $file ''));
                break;
            case 
"jpeg":
                
imagejpeg($img,($file $file ''),100);
                break;
            case 
"jpg":
                
imagejpeg($img,($file $file ''),100);
                break;
            case 
"gif":
                
imagegif($img,($file $file ''));
                break;
        }
    }
    
    function 
setTransparency($imgSrc,$imgDest,$ext){
    
        if(
$ext == "png" || $ext == "gif"){
            
$trnprt_indx imagecolortransparent($imgSrc);
            
// If we have a specific transparent color
            
if ($trnprt_indx >= 0) {
                
// Get the original image's transparent color's RGB values
                
$trnprt_color    imagecolorsforindex($imgSrc$trnprt_indx);
                
// Allocate the same color in the new image resource
                
$trnprt_indx    imagecolorallocate($imgDest$trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
                
// Completely fill the background of the new image with allocated color.
                
imagefill($imgDest00$trnprt_indx);
                
// Set the background color for new image to transparent
                
imagecolortransparent($imgDest$trnprt_indx);
            }
            
// Always make a transparent background color for PNGs that don't have one allocated already
            
elseif ($ext == "png") {
                
// Turn off transparency blending (temporarily)
                
imagealphablending($imgDesttrue);
                
// Create a new transparent color for image
                
$color imagecolorallocatealpha($imgDest000127);
                
// Completely fill the background of the new image with allocated color.
                
imagefill($imgDest00$color);
                
// Restore transparency blending
                
imagesavealpha($imgDesttrue);
            }
    
        }
    }
    
?>
Si alguien aquí sabe cómo cambiar el color de fondo para JPG, por favor, que me lo diga o me ayude :)

Gracias!!!

Javier
  #4 (permalink)  
Antiguo 30/09/2013, 07:56
Avatar de el_javi  
Fecha de Ingreso: marzo-2005
Ubicación: MAdrid
Mensajes: 844
Antigüedad: 19 años
Puntos: 10
Modificar código para cambiar color de imagen generada

Hola a todos.

Tengo este código PHP

Código PHP:
if (!isset($_POST["imageSource"])) {
    
$_POST["imageSource"] = "test.jpg";
}

list(
$width$height) = getimagesize($_POST["imageSource"]);

$viewPortW $_POST["viewPortW"];
$viewPortH $_POST["viewPortH"];
$pWidth $_POST["imageW"];
$pHeight =  $_POST["imageH"];
$ext end(explode(".",$_POST["imageSource"]));
$function returnCorrectFunction($ext);
$image $function($_POST["imageSource"]);
$width imagesx($image);
$height imagesy($image);
// Resample
$image_p imagecreatetruecolor($pWidth$pHeight);
setTransparency($image,$image_p,$ext);
imagecopyresampled($image_p$image0000$pWidth$pHeight$width$height);
imagedestroy($image);
$widthR imagesx($image_p);
$hegihtR imagesy($image_p);

$selectorX $_POST["selectorX"];
$selectorY $_POST["selectorY"];

if(
$_POST["imageRotate"]){
    
$angle 360 $_POST["imageRotate"];
    
$image_p imagerotate($image_p,$angle,0);

    
$pWidth imagesx($image_p);
    
$pHeight imagesy($image_p);

    
//print $pWidth."---".$pHeight;

    
$diffW abs($pWidth $widthR) / 2;
    
$diffH abs($pHeight $hegihtR) / 2;

    
$_POST["imageX"] = ($pWidth $widthR $_POST["imageX"] - $diffW $_POST["imageX"] + $diffW);
    
$_POST["imageY"] = ($pHeight $hegihtR $_POST["imageY"] - $diffH $_POST["imageY"] + $diffH);
}



$dst_x $src_x $dst_y $src_y 0;

if(
$_POST["imageX"] > 0){
    
$dst_x abs($_POST["imageX"]);
}else{
    
$src_x abs($_POST["imageX"]);
}
if(
$_POST["imageY"] > 0){
    
$dst_y abs($_POST["imageY"]);
}else{
    
$src_y abs($_POST["imageY"]);
}


$viewport imagecreatetruecolor($_POST["viewPortW"],$_POST["viewPortH"]);
setTransparency($image_p,$viewport,$ext);

imagecopy($viewport$image_p$dst_x$dst_y$src_x$src_y$pWidth$pHeight);
imagedestroy($image_p);


$selector imagecreatetruecolor($_POST["selectorW"], $_POST["selectorH"]);
setTransparency($viewport,$selector,$ext);
imagecopy($selector$viewport00$selectorX$selectorY$_POST["viewPortW"], $_POST["viewPortH"]);

if (isset(
$_GET["destino"]) && !empty($_GET["destino"])) {
    
$file "../../".$_GET["destino"];
} else {
    
$file "test".time().".".$ext;
}

parseImage($ext,$selector,$file);
imagedestroy($viewport);
//Return value
echo $file;
/* Functions */

function determineImageScale($sourceWidth$sourceHeight$targetWidth$targetHeight) {
    
$scalex =  $targetWidth $sourceWidth;
    
$scaley =  $targetHeight $sourceHeight;
    return 
min($scalex$scaley);
}

function 
returnCorrectFunction($ext){
    
$function "";
    switch(
$ext){
        case 
"png":
            
$function "imagecreatefrompng";
            break;
        case 
"jpeg":
            
$function "imagecreatefromjpeg";
            break;
        case 
"jpg":
            
$function "imagecreatefromjpeg";
            break;
        case 
"gif":
            
$function "imagecreatefromgif";
            break;
    }
    return 
$function;
}

function 
parseImage($ext,$img,$file null){
    switch(
$ext){
        case 
"png":
            
imagepng($img,($file != null $file ''));
            break;
        case 
"jpeg":
            
imagejpeg($img,($file $file ''),100);
            break;
        case 
"jpg":
            
imagejpeg($img,($file $file ''),100);
            break;
        case 
"gif":
            
imagegif($img,($file $file ''));
            break;
    }
}

function 
setTransparency($imgSrc,$imgDest,$ext){

    if(
$ext == "png" || $ext == "gif"){
        
$trnprt_indx imagecolortransparent($imgSrc);
        
// If we have a specific transparent color
        
if ($trnprt_indx >= 0) {
            
// Get the original image's transparent color's RGB values
            
$trnprt_color    imagecolorsforindex($imgSrc$trnprt_indx);
            
// Allocate the same color in the new image resource
            
$trnprt_indx    imagecolorallocate($imgDest$trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
            
// Completely fill the background of the new image with allocated color.
            
imagefill($imgDest00$trnprt_indx);
            
// Set the background color for new image to transparent
            
imagecolortransparent($imgDest$trnprt_indx);
        }
        
// Always make a transparent background color for PNGs that don't have one allocated already
        
elseif ($ext == "png") {
            
// Turn off transparency blending (temporarily)
            
imagealphablending($imgDesttrue);
            
// Create a new transparent color for image
            
$color imagecolorallocatealpha($imgDest000127);
            
// Completely fill the background of the new image with allocated color.
            
imagefill($imgDest00$color);
            
// Restore transparency blending
            
imagesavealpha($imgDesttrue);
        }

    }

Es de la herramienta Cropzoom

El código tal cual de la herramienta, genera imágenes con fondo NEGRO.

Yo necesito poder administrar (controlar desde el código) el color de fondo.
Unas veces negro, otras gris, otras blanco...

¿Alguien sabría decirme cómo puedo hacer que el color de fondo cambie en este código?


El resto de funcionalidades de Cropzoom son correctas.

Gracias y un saludo.
  #5 (permalink)  
Antiguo 30/09/2013, 09:14
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: Editor de imágenes HTML5 + jQuery + PHP

Si la imagen original es transparente, puedes usar imagefill sobre $selector con el color de fondo que tú quieras, antes de copiar la imagen, esto va a hacer que se quede el fondo del color definido.

Si la imagen NO es transparente, entonces vas a tener que usar manipulación de bits para ir cambiando el fondo (no es algo sencillo), y menos con archivos que tienen cierta pérdida como JPG, con GIF puedes cambiar el color del index de la paleta de colores, es más fácil, pero con JPG o PNG es más complicado ya que tendrías que ir buscando los contornos para evitar cambiarles el color.

Saludos.
  #6 (permalink)  
Antiguo 30/09/2013, 09:32
Avatar de NSD
NSD
Colaborador
 
Fecha de Ingreso: mayo-2012
Ubicación: Somewhere
Mensajes: 1.332
Antigüedad: 11 años, 11 meses
Puntos: 320
Respuesta: Modificar código para cambiar color de imagen generada

Hola, desconozco completamente que es CropZoom lo que puedo decirte es que las funciones que yo arme para tratar imagenes son estas:
Código PHP:
Ver original
  1. <?php
  2. //-----------------FUNCIONES PARA EL TRATAMIENTO DE IMAGENES JPG-PNG-GIF----------
  3.     function imagen_cargar($Imagen){
  4.         $Informacion = pathinfo($Imagen);
  5.         switch($Informacion['extension']){
  6.             case 'png':
  7.                 $ImgOriginalOriginal = imagecreatefrompng($Imagen);
  8.             break;
  9.             case 'gif':
  10.                 $ImgOriginalOriginal = imagecreatefromgif($Imagen);
  11.             break;
  12.             default:
  13.                 $ImgOriginalOriginal = imagecreatefromjpeg($Imagen);
  14.             break;
  15.         }
  16.         return $ImgOriginalOriginal;
  17.     }
  18.    
  19.     function imagen_guardar_objeto($ImgFinal , $Imagen , $Calidad){
  20.         $Informacion = pathinfo($Imagen);
  21.         switch($Informacion['extension']){
  22.             case 'png':
  23.                 imagepng($ImgFinal , $Imagen , $Calidad);
  24.             break;
  25.             case 'gif':
  26.                 imagegif($ImgFinal , $Imagen , $Calidad);
  27.             break;
  28.             default:
  29.                 imagejpeg($ImgFinal , $Imagen , $Calidad);
  30.             break;
  31.         }
  32.         return true;
  33.     }
  34.    
  35.     function imagen_formato_color($Color){ return round(round(($Color / 0x33)) * 0x33); }
  36.    
  37.     function imagen_colores_frecuentes($Imagen , $NumColores = 3 , $Ruido = 5) {
  38.         $Ruido = max(1 , abs((int)$Ruido));
  39.         $Colores = array();
  40.  
  41.         list($AnchoIMG , $AltoIMG) = getimagesize($Imagen);
  42.         $ImgOriginal = imagen_cargar($Imagen);
  43.  
  44.         for($x = 0; $x < $AnchoIMG; $x += $Ruido) {
  45.             for($y = 0; $y < $AltoIMG; $y += $Ruido) {
  46.              $RGB = imagecolorsforindex($ImgOriginal , imagecolorat($ImgOriginal, $x, $y));
  47.              $Rojo = imagen_formato_color($RGB['red']);
  48.              $Verde = imagen_formato_color($RGB['green']);
  49.              $Azul = imagen_formato_color($RGB['blue']);
  50.              $thisRGB = sprintf('%02X%02X%02X' , $Rojo , $Verde , $Azul);
  51.              if(array_key_exists($thisRGB , $Colores)) {
  52.                 $Colores[$thisRGB]++;
  53.              } else {
  54.                 $Colores[$thisRGB] = 1;
  55.              }
  56.           }
  57.        }
  58.        arsort($Colores);
  59.        return array_slice(array_keys($Colores) , 0 , $NumColores);
  60.     }
  61.  
  62.  
  63.  
  64.     function imagen_redimensionar($Imagen , $Ancho = 640 , $Alto = 480 , $Fondo = 'FFFFFF' , $MinAncho = 480 , $MinAlto = 360 ){
  65.  
  66.         list($AnchoIMG , $AltoIMG) = getimagesize($Imagen);
  67.         if(($AnchoIMG == '') or ($AltoIMG == '')){
  68.             return 'La imagen no se pudo cargar correctamente.';
  69.         }
  70.         if(($AnchoIMG < $MinAncho) or ($AltoIMG < $MinAlto)){
  71.             return 'La imagen no alcanza el tamaño minimo ('.$MinAncho.' x '.$MinAlto.') ('.$AnchoIMG.' x '.$AltoIMG.')';
  72.         }
  73.  
  74.         $ImgOriginal = imagen_cargar($Imagen);
  75.  
  76.         $ImgFinal=imagecreatetruecolor($Ancho , $Alto);
  77.        
  78.         if($Fondo == 'automatico'){
  79.             $imagen_colores_frecuentes = imagen_colores_frecuentes($Imagen);
  80.             $Fondo = $imagen_colores_frecuentes[0];
  81.         }
  82.        
  83.         $Fondo = '0x'.$Fondo;
  84.         imagefilledrectangle($ImgFinal , 0 , 0 , $Ancho-1 , $Alto-1 , ($Fondo*1));
  85.  
  86.  
  87.         if( $AnchoIMG > $AltoIMG){
  88.             $RelacionX = $Ancho / $AnchoIMG;
  89.             $AnchoDestino = $Ancho;
  90.             $AltoDestino = ceil($RelacionX * $AltoIMG);
  91.         } else {
  92.             $RelacionY = $Alto / $AltoIMG;
  93.             $AnchoDestino = ceil($RelacionY * $AnchoIMG);
  94.             $AltoDestino = $Alto;
  95.         }
  96.  
  97.         imagecopyresampled($ImgFinal , $ImgOriginal , (($Ancho-$AnchoDestino)/2) , (($Alto-$AltoDestino)/2) , 0 , 0 , $AnchoDestino  , $AltoDestino , $AnchoIMG , $AltoIMG);
  98.         imagedestroy($ImgOriginal);
  99.        
  100.         imagen_guardar_objeto($ImgFinal , $Imagen , 85);
  101.        
  102.         return 'ok';
  103.     }
  104. ?>

capaz te sirvan, aunque sea para canibalizarlas.

imagen_cargar = carga una imagen en jpg, gif o png desde el disco.
imagen_guardar_objeto = guarda una imagen en el disco.
imagen_formato_color = devuelve un color formateado.
imagen_colores_frecuentes = devuelve un array con los colores mas frecuentes en la imagen.
imagen_redimensionar = cambia el tamaño de una imagen
__________________
Maratón de desafíos PHP Junio - Agosto 2015 en FDW | Reglamento - Desafios
  #7 (permalink)  
Antiguo 01/10/2013, 01:24
Avatar de el_javi  
Fecha de Ingreso: marzo-2005
Ubicación: MAdrid
Mensajes: 844
Antigüedad: 19 años
Puntos: 10
Respuesta: Editor de imágenes HTML5 + jQuery + PHP

Hola a todos.

Ya he solucionado el problema.

NSD

Gracias a estas líneas tuyas
Código PHP:
 $Fondo '0x'.$Fondo;
imagefilledrectangle($ImgFinal $Ancho-$Alto-, ($Fondo*1)); 
Las adapté y las he incorporado a mi programación, funcionando perfectamente.

Aquí dejo el resultado:
Código PHP:
   
    
// Set the Background color    
    
$background_color "FFFFFF";
    
$background_color "0x".$background_color;
    
    if (!isset(
$_POST["imageSource"])) {
        
$_POST["imageSource"] = "test.jpg";
    }
    
    list(
$width$height) = getimagesize($_POST["imageSource"]);
    
    
$viewPortW $_POST["viewPortW"];
    
$viewPortH $_POST["viewPortH"];
    
$pWidth $_POST["imageW"];
    
$pHeight =  $_POST["imageH"];
    
$ext end(explode(".",$_POST["imageSource"]));
    
$function returnCorrectFunction($ext);
    
$image $function($_POST["imageSource"]);
    
$width imagesx($image);
    
$height imagesy($image);
    
// Resample
    
//    Original
//    $image_p = imagecreatetruecolor($pWidth, $pHeight);
    
    // Modified to set background color
    
$image_p imagecreatetruecolor($pWidth$pHeight);
    
    
// ****************************************************************
      // ********** NEXT LINE IS NEW TO SET BACKGROUND COLOR **************
    // ****************************************************************
    
imagefilledrectangle($viewport00$pWidth$pHeight, ($background_color 1));
    
    
setTransparency($image,$image_p,$ext);
    
imagecopyresampled($image_p$image0000$pWidth$pHeight$width$height);
    
imagedestroy($image);
    
$widthR imagesx($image_p);
    
$hegihtR imagesy($image_p);
    
    
$selectorX $_POST["selectorX"];
    
$selectorY $_POST["selectorY"];
    
    if(
$_POST["imageRotate"]){
        
$angle 360 $_POST["imageRotate"];
        
$image_p imagerotate($image_p,$angle,0);
        
        
$pWidth imagesx($image_p);
        
$pHeight imagesy($image_p);
        
        
//print $pWidth."---".$pHeight;
        
        
$diffW abs($pWidth $widthR) / 2;
        
$diffH abs($pHeight $hegihtR) / 2;
        
        
$_POST["imageX"] = ($pWidth $widthR $_POST["imageX"] - $diffW $_POST["imageX"] + $diffW);
        
$_POST["imageY"] = ($pHeight $hegihtR $_POST["imageY"] - $diffH $_POST["imageY"] + $diffH);
    }
    
    
    
    
$dst_x $src_x $dst_y $src_y 0;
    
    if(
$_POST["imageX"] > 0){
        
$dst_x abs($_POST["imageX"]);
    }else{
        
$src_x abs($_POST["imageX"]);
    }
    if(
$_POST["imageY"] > 0){
        
$dst_y abs($_POST["imageY"]);
    }else{
        
$src_y abs($_POST["imageY"]);
    }
    
    
    
$viewport imagecreatetruecolor($_POST["viewPortW"],$_POST["viewPortH"]);
    
    
// ****************************************************************
     // ********** NEXT LINE IS NEW TO SET BACKGROUND COLOR **************
    // ****************************************************************
    
imagefilledrectangle($viewport00$_POST["viewPortW"], $_POST["viewPortH"], ($background_color 1));

    
    
setTransparency($image_p,$viewport,$ext);
    
    
imagecopy($viewport$image_p$dst_x$dst_y$src_x$src_y$pWidth$pHeight);
    
imagedestroy($image_p);
    
    
    
$selector imagecreatetruecolor($_POST["selectorW"], $_POST["selectorH"]);

    
setTransparency($viewport,$selector,$ext);
    
imagecopy($selector$viewport00$selectorX$selectorY$_POST["viewPortW"], $_POST["viewPortH"]);
    
    if (isset(
$_GET["destino"]) && !empty($_GET["destino"])) {
        
$file "../../".$_GET["destino"];
    } else {
        
$file "test".time().".".$ext;
    }
    
    
parseImage($ext,$selector,$file);
    
imagedestroy($viewport);
    
//Return value
    
echo $file;
    
/* Functions */
    
    
function determineImageScale($sourceWidth$sourceHeight$targetWidth$targetHeight) {
        
$scalex =  $targetWidth $sourceWidth;
        
$scaley =  $targetHeight $sourceHeight;
        return 
min($scalex$scaley);
    }
    
    function 
returnCorrectFunction($ext){
        
$function "";
        switch(
$ext){
            case 
"png":
                
$function "imagecreatefrompng";
                break;
            case 
"jpeg":
                
$function "imagecreatefromjpeg";
                break;
            case 
"jpg":
                
$function "imagecreatefromjpeg";
                break;
            case 
"gif":
                
$function "imagecreatefromgif";
                break;
        }
        return 
$function;
    }
    
    function 
parseImage($ext,$img,$file null){
        switch(
$ext){
            case 
"png":
                
imagepng($img,($file != null $file ''));
                break;
            case 
"jpeg":
                
imagejpeg($img,($file $file ''),100);
                break;
            case 
"jpg":
                
imagejpeg($img,($file $file ''),100);
                break;
            case 
"gif":
                
imagegif($img,($file $file ''));
                break;
        }
    }
    
    function 
setTransparency($imgSrc,$imgDest,$ext){
    
        if(
$ext == "png" || $ext == "gif"){
            
$trnprt_indx imagecolortransparent($imgSrc);
            
// If we have a specific transparent color
            
if ($trnprt_indx >= 0) {
                
// Get the original image's transparent color's RGB values
                
$trnprt_color    imagecolorsforindex($imgSrc$trnprt_indx);
                
// Allocate the same color in the new image resource
                
$trnprt_indx    imagecolorallocate($imgDest$trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
                
// Completely fill the background of the new image with allocated color.
                
imagefill($imgDest00$trnprt_indx);
                
// Set the background color for new image to transparent
                
imagecolortransparent($imgDest$trnprt_indx);
            }
            
// Always make a transparent background color for PNGs that don't have one allocated already
            
elseif ($ext == "png") {
                
// Turn off transparency blending (temporarily)
                
imagealphablending($imgDesttrue);
                
// Create a new transparent color for image
                
$color imagecolorallocatealpha($imgDest000127);
                
// Completely fill the background of the new image with allocated color.
                
imagefill($imgDest00$color);
                
// Restore transparency blending
                
imagesavealpha($imgDesttrue);
            }
    
        }
    } 
Con los 3 añadidos que marco en el código NEXT LINE IS NEW TO SET BACKGROUND COLOR me funciona perfectamente


Gracias y saludos!!!!


Javier

Última edición por el_javi; 01/10/2013 a las 04:22

Etiquetas: color, editor, html, html5, ipad, jquery, modificar, select
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 17:23.