Foros del Web » Programando para Internet » PHP »

aligerar codigo

Estas en el tema de aligerar codigo en el foro de PHP en Foros del Web. Hola amigos tengo un script en php con el cual guardo una captura de pantalla exa desde flash, el tema es que tarda como un ...
  #1 (permalink)  
Antiguo 22/11/2010, 04:16
 
Fecha de Ingreso: junio-2008
Mensajes: 292
Antigüedad: 15 años, 10 meses
Puntos: 4
aligerar codigo

Hola amigos tengo un script en php con el cual guardo una captura de pantalla exa desde flash, el tema es que tarda como un millon de oras en crear la imagen mi pregunta es la siguiente ¿sabeis de algun otro modo de crear esta imagen? o si este codigo se puede aligerar de alguna mananera, no se?¿?? quitarle calidad a al jpg...o algo parecido...yo he intentado hacer la la captura mas pequeña pero sigue tardando mucho. muchas gracias por vuestra colaboracion

Código PHP:

<?php
    
//If GD library is not installed, say sorry
    
if(!function_exists("imagecreate")) die("Sorry, you need GD library to run this example");
    
//Capture Post data
    
$data explode(","$_POST['img']);
    
$width $_POST['width'];
    
$height $_POST['height'];

   
    
    
//Allocate image
    
$image=(imagecreate$width ,$height ));
    
imagefill($image000xFFFFFF);
    
//Copy pixels
    
$i 0;
    for(
$x=0$x<=$width$x++){
        for(
$y=0$y<=$height$y++){
            
$r hexdec("0x".substr$data[$i] , ));
            
$g hexdec("0x".substr$data[$i] , ));
            
$b hexdec("0x".substr$data[$i++] , ));
            
$color imagecolorallocate($image$r$g$b);
            
imagesetpixel ($image,$x,$y,$color);
        }
    }

por si os puede ayudar aqui os dejo la parte flash AS 2

Código PHP:
function capture(nr)
{
    
   
    
snapshot = new BitmapData(950520);
    
//draw the current state of the Video object into 
    //the bitmap object with no transformations applied
    
snapshot.draw(_root ,new Matrix());
    
    var 
t:MovieClip createEmptyMovieClip("bitmap_mc"0);
    
t._x 0;
    
t._y 0;
    
t._xscale t._yscale 100;
    
//display the specified bitmap object inside the movie clip
    
t.attachBitmap(snapshot,1);
    var 
filterArray = new Array(myFilters[nr]);
    
t.filters filterArray;
    
attachMovie("print_but","bot",100,{_x:t._x t._width -450_y:t._y t._height 2});
    
    
}
//Create a new bitmapdata, resize it 50 %, pass image data to a server script
// using a LoadVars object (large packet)
function output(who)
{
    
//preloader visible 
    
preloader._visible true;
    
//Here we will copy pixels data
    
var pixels:Array = new Array();
    
//Create a new BitmapData
    
var snap = new BitmapData(who.widthwho.height);
    
//Matrix to scale the new image
    
myMatrix = new Matrix();
    
myMatrix.scale(0.5,0.5);
    
//Copy video image
    
snap.draw(who,myMatrix);
    
//Uncoment this line if you want to apply filters instead of just capturing source
    // results should be adjusted based on your library version, not recomended
    //snap.applyFilter(snap, snap.rectangle, snap.rectangle.topLeft, myFilters[nr])
    
var w:Number snap.widthtmp;
    var 
h:Number snap.height;
    
//Build pixels array using an onEnterframe to avoid timeouts, capture a row per iteration, show a progressbar
    
var a:Number 0;
    
this.onEnterFrame = function()
    {
        for (var 
0<= hb++)
        {
            var 
alpha:String = (snap.getPixel32(ab) >> 24 0xFF).toString(16);
            var 
red:String = (snap.getPixel32(ab) >> 16 0xFF).toString(16);
            var 
green:String = (snap.getPixel32(ab) >> 0xFF).toString(16);
            var 
blue:String = (snap.getPixel32(ab) & 0xFF).toString(16);
            
tmp "0x" red green blue;
            
pixels.push(tmp);
        }
        
perc int((100) / w);
        
preloader.perc.text perc " %";
        
preloader.barra._xscale perc;
        
a++;
        if (
w)
        {
//Finish capturing
            
preloader._visible false;
            
sendData(pixels,h,w,nombre);
            
//free memory
            
snap.dispose();
            
delete this.onEnterFrame;
        }
    };
}
//Capture a clip into a BitmapData object and pass whitout resizing
function outputClip(who)
{
    
//preloader visible 
    
preloader._visible true;
    
//Here we will copy pixels data
    
var pixels:Array = new Array();
    
//Create a new BitmapData
    
var snap = new BitmapData(who._widthwho._height);
    
snap.draw(who);
    var 
w:Number snap.widthtmp;
    var 
h:Number snap.height;
    
//Build pixels array using an onEnterframe to avoid timeouts, capture a row per iteration, show a progressbar
    
var a:Number 0;
    
this.onEnterFrame = function()
    {
        for (var 
0<= hb++)
        {
            
tmp snap.getPixel32(ab).toString(16);
            
pixels.push(tmp.substr(1));
        }
        
perc int((100) / w);
        
preloader.perc.text perc " %";
        
preloader.barra._xscale perc;
        
a++;
        if (
w)
        {
//Finish capturing
            
preloader._visible false;
            
sendData(pixels,h,w,nombre);
            
//free memory
            
snap.dispose();
            
delete this.onEnterFrame;
        }
    };
}
function 
sendData(pixels:Array, h:Numberw:Number)
{
    
//Create the LoadVars object and pass data to PHP script
    
    
var output:LoadVars = new LoadVars();
    
output.img pixels.toString();
    
output.height h;
    
output.width w;
    
output.nombre nombre;     
    
output.archivo=archivo;
    
output.precio teeTotals.myTotal;
    
output.imgdelantera=imgdelantera;
    
output.imgtrasera=imgtrasera;
    
output.menS=menS;
    
output.menM=menM;
    
output.menL=menL;
    
output.menXL=menXL;
    
output.menXXL=menXXL;
    
output.menXXXL=menXXXL;
    
output.womenXS=womenXS;
    
output.womenS=womenS;
    
output.womenM=womenM;
    
output.womenL=womenL;
    
output.womenXL=womenXL;
    
output.womenXXL=womenXXL;
    
//The page (and this movie itself) should be in a server to work
    
output.send("show.php","output","POST"); 
  #2 (permalink)  
Antiguo 22/11/2010, 07:20
Avatar de mayid
Colaborador
 
Fecha de Ingreso: marzo-2009
Ubicación: BsAs
Mensajes: 4.014
Antigüedad: 15 años, 1 mes
Puntos: 101
Respuesta: aligerar codigo

Muy interesante. Quiero aprender :O)

Esto pasa solo con flash o con captura de pantalla de cualquier pagina?

Y qué recibis en $data?
  #3 (permalink)  
Antiguo 23/11/2010, 00:49
 
Fecha de Ingreso: junio-2008
Mensajes: 292
Antigüedad: 15 años, 10 meses
Puntos: 4
Respuesta: aligerar codigo

gracias por tu respuesta, me imagino que se podra hacer desde cualquier pagina, solo que yo lo hago desde flash. En $data envio la imagen, es decir flash envia los pixeles y el php los junta, por decirlo de alguna manera...pero como he dixo antes tarda como mil oras.
Puede ver la aplicacion aki.
He leido por algun lado que se puede hacer sobre AS 3 pero ya mi pelicula esta exa en AS2 y tiene codigo asociado a los simbolos x lo que lo veo complicao de cambiar, pero en mi opinion lo que tarda es el php en volver a montar la imagen. debe de haber una manera de "aligerar" esto. a ver si viendo la aplicacion ves otra manera de hacerlo. gracias por tu interes :D

Etiquetas: Ninguno
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 11:52.