<style type="text/css">
#imasetDLayer {
background-color: black;
width: 100%;
left: 0%;
top: 0%;
z-index: 1001;
height: 2000px;
position: absolute;
-moz-opacity: 0.7;
opacity: .7;
filter: alpha(opacity=70)
}
#imasetLoading {
display: none;
background: #FFF url(<?php echo bloginfo( 'wpurl' ); ?>/wp-content/plugins/imaset/img/ajax-loader.gif) no-repeat left 50%;
padding: 5px;
padding-left: 40px;
font-size:1.8em;
position:absolute;
left:25%;
top: 40px;
-moz-opacity: 0.8;
opacity: .8;
filter: alpha(opacity=80);
}
#imasetContent {
background-color: white;
border: 4px solid #CCC;
width: 80%;
left: 10%;
top: 10%;
z-index: 1002;
height: 80%;
position: absolute;
padding: 10px;
overflow:auto;
}
#imasetContent .sidebar {
width:30%;
background-color:#E8F3F8;
border: 1px solid #74B1CD;
float:right;
z-index: 1003;
}
#imasetContent .sidebar h3 {
margin: 8px;
padding: 0;
}
#imasetContent .sidebar a.filtro {
width: 50px;
height: 50px;
margin: 4px;
display: block;
float: left;
border: 1px solid #6c7074;
background-color: #FFF;
}
#imasetContent .deshacer {
display:block;
clear:left;
text-align:center;
padding:4px;
background-color: #BADB76;
color: #3B6100;
}
#imasetContent .deshacer:hover {
background-color: #D8FF88;
}
#imasetContent .sidebar #imasetMsg {
clear: left;
border: 1px solid #FFBE76;
background-color: #FFF9C4;
padding: 4px;
margin: 5px;
}
#imasetContent .view {
width: 60%;
}
#imasetContent .view #imasetImg {
margin: 10px auto;
display: block;
}
#imasetContent .view #imasetImg.proceso {
-moz-opacity: 0.5;
opacity: .5;
filter: alpha(opacity=50)
}
#imasetContent .view #imasetPrevw {
margin-top: 5px;
border-top: 4px solid #45648B;
}
#imasetContent .view #imasetPrevw a.img {
width: 128px;
height: 128px;
display: block;
float: left;
margin: 3px;
}
</style>
<?php ## Licencia: GNU/GPL v3+ ## class Imaset { var $error; // array que contiene los errores ocurridos durante la ejecucion var $content; //la direccion hasta wp-content var $dir; // directorio del plugin var $ims; // imagenes de un directorio var $num; //Cantidad de imagenes var $filtros; //Filtros disponibles function Imaset($dir='') { $this->dir = str_replace('imasetClass.php','',__FILE__); $this->content = substr(__FILE__,0,strpos(__FILE__,'plugins')); //Filtros disponibles $this->filtros = array(); $this->filtros[] = array('nom'=>'sombra','alt'=>'Crea una sombra alrededor'); $this->filtros[] = array('nom'=>'marcus','alt'=>'Crea un marco agradable'); $this->filtros[] = array('nom'=>'reflekt','alt'=>'Crea un efecto de reflejo'); $this->filtros[] = array('nom'=>'brillo','alt'=>'Dibuja un brillo curvo'); $this->filtros[] = array('nom'=>'perspectiva','alt'=>'Aplica un efecto de perspectiva'); $this->filtros[] = array('nom'=>'wave','alt'=>'Ondula la imagen'); $this->filtros[] = array('nom'=>'marca','alt'=>'Aplica una marca de agua'); } function ddir($dir) //por cuestion de estetica y de espacio, se considera raiz al directorio desde donde testea { return str_replace($this->content,'',$dir); } function explora() { if(empty($this->ims)) $this->lee_dir($this->content.$dir); if(!empty($this->ims)) { krsort($this->ims); //ordeno inversamente por claves, para mostrarlas en orden de modificacion, las mas nuevas primero foreach($this->ims as $i) //coloco indices ordenados $ims[] = $i; $this->ims = $ims; $this->num = count($this->ims); } return $this->ims; } function lee_dir($dir) //lee todo un directorio: todos sus archivos y los directorios hijos { if(substr($dir,-1)!='/') $dir .= '/'; //importante que acabe en "/" if (is_dir($dir)) { if ($gd = @opendir($dir)) { while (($ar = @readdir($gd)) !== false) { if($ar != '.' AND $ar != '..') //Evito el propio directorio y el directorio padre { if(is_dir($dir . $ar)) { if(!eregi('(plugins|languages|themes)',$ar)) $this->lee_dir($dir.$ar); } else { if(eregi('\.(jpg|gif|png)',$ar) AND !eregi('\.(thumbnail|miniatura|old)',$ar)) { $tm = filemtime($dir.$ar); if(empty($tm)) $tm = 0; $this->ims[$tm] = $this->ddir($dir).$ar; } } } } closedir($gd); } else $this->error[] = 'Imposible abrir el directorio '.$dir ; } else $this->error[] = $dir.' no es un directorio.' ; } function dir_marcas() { $gd = @opendir($this->dir.'img/marcas/'); while (($ar = @readdir($gd)) !== false) { if(eregi('\.(jpg|gif|png)',$ar)) $mar[] = $ar; } return $mar; } //Funciones para manipular en String Query function getQuery() //obtiene el querystring en un array asociativo { $qs = $_SERVER['QUERY_STRING']; $aqs = explode('&',$qs); foreach($aqs as $q) { $q = explode('=',$q); $cla=$q[0]; $vqs[$cla] = $q[1]; } return $vqs; } function implodeQuery($q) { foreach($q as $c=>$v) $nqs[] = "$c=$v"; $nqs = implode('&',$nqs); return $nqs; } function addToQuery($ar) //añade la variable $c[lave] =>$v[alor] al query_string. { $vqs = $this->getQuery(); foreach($ar as $c=>$v) { if(!$v) unset($vqs[$c]); else $vqs[$c] = $v; } return $this->implodeQuery($vqs); } function unsetQuery($unset) //quita variables del querystring { $vqs = $this->getQuery(); foreach($unset as $u) { if($u) unset($vqs[$u]);} return $this->implodeQuery($vqs); } //Funciones para poner y quitar extension .old function ponPre($f) { return ereg_replace( "\.(jpg|gif|png)", ".old.\\1", $f ); } function quitaPre($f) { return str_replace('.old','',$f); } // Funciones de retoque function nuevaImagen($img) { $im = false; switch(true) { case ereg('\.jpg',$img): $im = imagecreatefromjpeg($img); break; case ereg('\.gif',$img): $im = imagecreatefromgif($img); break; case ereg('\.png',$img): $im = imagecreatefrompng($img); break; } return $im; } function creaImagen($im,$img) { $t = false; switch(true) { case ereg('\.jpg',$img): $t = imagejpeg($im,$img); break; case ereg('\.gif',$img): $t = imagegif($im,$img); break; case ereg('\.png',$img): $t = imagepng($im,$img); break; } return $t; } function exportaImagen($im,$img) { $t = false; switch(true) { case ereg('\.jpg',$img): $t = imagejpeg($im); break; case ereg('\.gif',$img): $t = imagegif($im); break; case ereg('\.png',$img): $t = imagepng($im); break; } return $t; } function marcus($im) { $sx = imagesx($im); $sy = imagesy($im); $x = $sx+20; $y = $sy+20; $marcus = imagecreatetruecolor($x,$y); $color = imagecolorallocate($marcus, 255,255,255); //Blanco imagefilledrectangle($marcus, 0, 0, ($sx+20), ($sy+20), $color); //Relleno el fondo imagecopy($marcus, $im, 10, 10, 0, 0, $sx, $sy); $esquinas = array(array('tl',0,0),array('tr',$x-15,0),array('br',$x-15,$y-15),array('bl',0,$y-15)); $bordes = array(array('t',0,0,$x,10),array('r',$x-10,0,10,$y),array('b',0,$y-10,$x,10),array('l',0,0,10,$y)); foreach($bordes as $bo) imagecopyresampled ($marcus, imagecreatefrompng($this->dir."img/b_".$bo[0].'.png'), $bo[1], $bo[2], 0, 0, $bo[3], $bo[4], 10, 10); foreach($esquinas as $es) imagecopy($marcus, imagecreatefrompng($this->dir."img/b_".$es[0].'.png'), $es[1], $es[2], 0, 0, 15, 15); return $marcus; } function reflekt($im) { $sx = imagesx($im); $sy = imagesy($im); $x = $sx; $y = $sy+30; $reflekt = imagecreatetruecolor($x,$y); $color = imagecolorallocate($reflekt, 255,255,255); //Blanco imagefilledrectangle($reflekt, 0, 0, $x, $y, $color); //Relleno el fondo imagecopy($reflekt, $im, 0, 0, 0, 0, $sx, $sy); for($i=0;$i<=30;$i++) imagecopymerge($reflekt, $im, 0, $sy+$i, 0, $sy-($i+1), $x, 1, 60-$i*2); return $reflekt; } function marca($im,$mar) { $ma = $this->nuevaImagen($this->dir.'img/marcas/'.$mar); $mx = imagesx($ma); $my = imagesy($ma); imagecopy($im, $ma, 0, 0, 0, 0, $mx, $my); return $im; } function wave($im, $amplitude = 5,$period = 30) { $width = imagesx($im); $height = imagesy($im); $img2 = imagecreatetruecolor($width * 2, $height * 2); imagecopyresampled ($img2,$im,0,0,$x,$y,$width * 2,$height * 2,$width, $height); // Wave it for ($i = 0;$i < ($width * 2);$i += 2) { imagecopy($img2,$img2, $x + $i - 2,$y + sin($i / $period) * $amplitude, // dest $x + $i,$y, // src 2,($height * 2)); } // Resample it down again imagecopyresampled ($im,$img2,$x,$y,0,0,$width, $height,$width * 2,$height * 2); imagedestroy($img2); return $im; } function brillo($im) { $w = imagesx($im); $h = imagesy($im); $imblanc = imagecreatetruecolor(1,$h); $color = imagecolorallocate($imblanc, 255,255,255); //Blanco imagefilledrectangle($imblanc, 0, 0, $w, $h, $color); //Relleno el fondo for($i=0; $i<$w; $i++) { imagecopymerge($im, $imblanc, $i, 0, 0, 0, 1, ($h/2+($h/25)*sin(6.3/$w*$i)), 25); } return $im; } function perspectiva($im) // int $porc = porcentaje de perspectiva (100=nada, 0=completa) { $porc = 20; // el porcentaje de reducción $x = imagesx($im); $y = imagesy($im); $ampl = 2; //a cuanto ampliar la imagen para mejorar la resolucion $pers = imagecreatetruecolor($x*$ampl,$y*$ampl); $color = imagecolorallocate($pers, 255,255,255); //Blanco imagefilledrectangle($pers, 0, 0, $x*$ampl, $y*$ampl, $color); //Relleno el fondo $factor = ($porc/100)/$x ; for($i=0;$i<$x*$ampl;$i++) { $hy = round($y*$ampl-($y*($i+1)*$factor*$ampl)); $py = round(($y*$ampl - $hy)/2); imagecopyresampled ( $pers, $im, $i, $py, $i/$ampl, 0, 1, $hy, 1, $y ); } $pers2 = imagecreatetruecolor(0.7*$x,$y); imagecopyresampled($pers2, $pers, 0, 0, 0, 0, 0.7*$x, $y, $x*$ampl, $y*$ampl); return $pers2; } function sombra($im) { $sx = imagesx($im); $sy = imagesy($im); $x = $sx+16; $y = $sy+16; $sombra = imagecreatetruecolor($x,$y); $color = imagecolorallocate($sombra, 255,255,255); //Blanco imagefilledrectangle($sombra, 0, 0, ($sx+20), ($sy+20), $color); //Relleno el fondo imagecopy($sombra, $im, 8, 8, 0, 0, $sx, $sy); $esquinas = array(array('tl',0,0),array('tr',$x-12,0),array('br',$x-12,$y-12),array('bl',0,$y-12)); $bordes = array(array('t',0,0,$x,8),array('r',$x-8,0,8,$y),array('b',0,$y-8,$x,8),array('l',0,0,8,$y)); foreach($bordes as $bo) imagecopyresampled ($sombra, imagecreatefrompng($this->dir."img/s_".$bo[0].'.png'), $bo[1], $bo[2], 0, 0, $bo[3], $bo[4], 8, 8); foreach($esquinas as $es) imagecopy($sombra, imagecreatefrompng($this->dir."img/s_".$es[0].'.png'), $es[1], $es[2], 0, 0, 12, 12); return $sombra; } function aplicaFiltro($im,$n,$e=false) //resource im, nombre n, extra e { switch($n) { case 'marcus': return $this->marcus($im); break; case 'sombra': return $this->sombra($im); break; case 'reflekt': return $this->reflekt($im); break; case 'marca': return $this->marca($im,$e); break; case 'wave': return $this->wave($im); break; case 'brillo': return $this->brillo($im); break; case 'perspectiva': return $this->perspectiva($im); break; default: return $im; break; } } } ?>
<?php /* Plugin Name: Imaset Plugin URI: http://boozox.net Description: Trata tus imágenes almacenadas en Wordpress con interesantes efectos Version: 1.0 Author: Alex Barros Author URI: http://boozox.net */ ## Licencia: GNU/GPL v3+ ## session_start(); include_once 'imasetClass.php'; // JavaScript y CSS function imasetPS() { wp_print_scripts( array( 'sack' )); include('imasetJS.html'); include('imasetStyle.html'); } function imasetAjax() { $q = $_POST['q']; $imaset = new Imaset; if($q == 'ini') { $imaset->explora(); //explora los directorios en busca de imagenes session_destroy(); $html = "<div class=\"sidebar\"><h3>Filtros:</h3>"; foreach($imaset->filtros as $f) { $n = $f['nom']; $html .= '<a href="#'.$n.'" onClick="imasetAjax(\'filtro:'.$n.'\')" onMouseOver="imasetMsg(\''.$f['alt'].'\')" class="filtro"><img src="../wp-content/plugins/imaset/img/logo_'.$n.'.jpg" alt="'.$f['alt'].'"/></a>'; } $html .= "<a class=\"deshacer\" onClick=\"imasetAjax('deshaz')\" href=\"#\">«Deshacer</a><div id=\"imasetMsg\">Pasa el ratón por encima de los filtros...</div><input type=\"button\" class=\"button\" value=\"Guardar Cambios\" onClick=\"imasetAjax('guardar'); imasetMsg('Por favor, <u>espera</u>...');\" /><input type=\"button\" class=\"button delete\" value=\"Salir del editor\" onClick=\"imasetClose()\" /></div>"; $html .= "<div class=\"view\"><p id=\"imasetLoading\">Cargando...</p><img onLoad=\"imasetImgLoaded()\" id=\"imasetImg\" src=\"../wp-content/plugins/imaset/prev.php?save=1&img=".$imaset->content.$imaset->ims[0]."&r=".rand()."\" /><div id=\"imasetPrevw\">"; if($imaset->num > 12) $html .= "<p style=\"text-align:center;\"><a onClick=\"imasetAjax('desde:12')\" href=\"#\">Anteriores »</a></p>"; if($imaset->num < 12) $max = $imaset->num; else $max = 12; for($i=0;$i<$max;$i++) { $html .= "<a class=\"img\" href=\"#\" onClick=\"imasetToogleImg('save=1&img=".$imaset->content.$imaset->ims[$i]."')\"><img src=\"../wp-content/plugins/imaset/prev.php?snap=1&img=".$imaset->content.$imaset->ims[$i]."&r=".rand()."\" /></a>"; } $html .= '<div style="clear:left;"></div>'; $html .="</div></div>"; $_SESSION['acimg'] = $imaset->ims[0]; $_SESSION['hist'] = ''; die('imasetContent(\''.str_replace(array("\n","'"),array('',"\'"),$html).'\');'); } elseif($q=='guardar') { $im = $imaset->nuevaImagen($imaset->content.$_SESSION['acimg']); if(!empty($_SESSION['hist'])) { $filtros = explode(';',$_SESSION['hist']); $cant = count($filtros); for($i=1;$i<$cant;$i++) { $im = $imaset->aplicaFiltro($im,$filtros[$i]); } } $s = $imaset->creaImagen($im,$imaset->content.$_SESSION['acimg']); if($s) $msg = '<strong style=\\"color:green;\\">Imagen guardada satisfactoriamente</strong>'; else $msg = '<strong style=\\"color:red;\\">Ha ocurrido algun problema</strong>'; die('imasetToogleImg("save=1&img='.$imaset->content.$_SESSION['acimg'].'"); imasetMsg("'.$msg.'");'); } elseif(ereg("filtro",$q)) { $pts = explode(':',$q); $_SESSION['hist'] .= ';'.$pts[1]; if(!isset($_SESSION['acimg'])) $_SESSION['acimg'] = 'noimg.ll'; die('imasetToogleImg("img='.$imaset->content.$_SESSION['acimg'].'"); imasetMsg("Espera un poco a que cargue la vista previa...");'); } elseif($q == 'deshaz') { $hist = explode(';',$_SESSION['hist']); $k = count($hist)-1; unset($hist[$k]); $_SESSION['hist'] = implode(';',$hist); die('imasetToogleImg("img='.$imaset->content.$_SESSION['acimg'].'");'); } elseif(ereg("desde",$q)) { $imaset->explora(); //explora los directorios en busca de imagenes $pts = explode(':',$q); $p = $pts[1]; $html = "<p style=\"text-align:center;\">"; if($p >=12) $html .= "<a onClick=\"imasetAjax('desde:".($p-12)."')\" href=\"#\">« Posteriores |</a>"; if($imaset->num > ($p+12)) $html .= "<a onClick=\"imasetAjax('desde:".($p+12)."')\" href=\"#\">| Anteriores »</a>"; $html .= "</p>"; if($imaset->num < ($p+12)) $max = $imaset->num; else $max = $p+12; for($i=$p;$i<$max;$i++) { $html .= "<a class=\"img\" href=\"#\" onClick=\"imasetToogleImg('save=1&img=".$imaset->content.$imaset->ims[$i]."')\"><img src=\"../wp-content/plugins/imaset/prev.php?snap=1&img=".$imaset->content.$imaset->ims[$i]."&r=".rand()."\" /></a>"; } $html .= '<div style="clear:left;"></div>'; die('imasetPrevw(\''.str_replace(array("\n","'"),array('',"\'"),$html).'\');'); } else { die("alert('No se han recibido datos adecuados.')"); } } function imasetBotonUso(){ echo '<input type="button" class="button" style="padding: 4px; margin:4px;" value="Usar Imaset" onClick="imasetDisplay(1)" />'; } add_action("admin_print_scripts", "imasetPS"); add_action('wp_ajax_imasetAjax', 'imasetAjax' ); add_action("edit_form_advanced", "imasetBotonUso"); ?>
<?php session_start(); header("Cache-Control: no-cache, must-revalidate"); header("Content-type: image/jpg"); include_once 'imasetClass.php'; $imaset = new Imaset; $img = $_GET['img']; $im = $imaset->nuevaImagen($img); //Si me han pedido guardarla como nueva.. if($_GET['save']) { $_SESSION['acimg'] = str_replace($imaset->content,'',$img); //la guardo como la nueva imagen.. $_SESSION['hist'] = ''; //borro el historial } //aplico el historial de filtros elseif(!empty($_SESSION['hist']) AND !$_GET['snap']) { $filtros = explode(';',$_SESSION['hist']); $cant = count($filtros); for($i=1;$i<$cant;$i++) { $im = $imaset->aplicaFiltro($im,$filtros[$i]); } } //Resuelvo los tamaños $dim = false; if($_GET['dim']) $dim = explode('x',$_GET['dim']); if($_GET['snap']) $dim = array(128,128); if($im AND $dim) { $w = imagesx($im); $h = imagesy($im); if($w>$dim[0]) { $nw = $dim[0]; $nh = ($h*$dim[0])/$w; } if($nh>$dim[1]) { $nh = $dim[1]; $nw = ($w*$dim[1])/$h; } if($nh && $nw) { $snap = imagecreatetruecolor($nw,$nh); imagecopyresized($snap, $im, 0, 0, 0, 0, $nw, $nh, $w, $h); $im = $snap; } } $imaset->exportaImagen($im,$img); ?>
<script type="text/javascript">
var imasetON = false;
function ima$et(n)
{
return document.getElementById("imaset"+n);
}
function imasetDisplay()
{
if(imasetON) return false;
imasetDLayer();
imasetContent('<span id="imasetLoading" style="float:left">Cargando...</span>');
imasetAjax('ini');
imasetON = true;
return true;
}
function imasetContent(t)
{
var ct = ima$et("Content");
if (ct == null)
{
var c = document.createElement("div");
c.id = "imasetContent";
document.body.appendChild(c);
ct =c;
}
ct.innerHTML = t;
}
function imasetPrevw(c)
{
ima$et("Prevw").innerHTML = c;
}
function imasetCheckImg(im)
{
<?php echo "alert(1);";?>
}
function imasetClose()
{
var a = ima$et("DLayer");
var b = ima$et("Content");
a.parentNode.removeChild(a);
b.parentNode.removeChild(b);
imasetON = false;
}
function imasetDLayer(t)
{
document.location = '#';
if (ima$et("DLayer") != null) return false;
var i = document.createElement("div");
i.id = "imasetDLayer";
i.onClick = function(){ima$et("DLayer").setAttribute('style','');};
document.body.appendChild(i);
}
function imasetMsg(m)
{
ima$et("Msg").innerHTML = m;
}
function imasetToogleImg(src)
{
ima$et("Img").src = '../wp-content/plugins/imaset/prev.php?'+src+'&dim=400x300&r='+Math.floor(Math.random()*800);
ima$et("Img").setAttribute('class','proceso');
}
function imasetImgLoaded()
{
ima$et("Img").setAttribute('class','');
}
function imasetLoading()
{
if(ima$et("Loading"))
ima$et("Loading").style.display = 'block';
}
function imasetLoaded()
{
if(ima$et("Loading"))
ima$et("Loading").style.display = 'none';
}
function imasetAjax(q)
{
var mysack = new sack("<?php bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php" );
mysack.execute = 1;
mysack.method = 'POST';
mysack.setVar( "action", "imasetAjax" );
mysack.setVar( "q", q );
mysack.encVar( "cookie", document.cookie, false );
mysack.onLoading = imasetLoading;
mysack.onLoaded = imasetLoaded;
mysack.onError = function() { alert('Error en la ejecucion AJAX' )};
mysack.runAJAX();
return true;
}
</script>