<?php /* Translation of "imaset" wordpress plugin Imaset by Alex Barros 2007 < http://boozox.net > < zumbenet@gmail.com > If you want to translate this plugin to any other language, feel free to send me the translated file to zumbenet@gmail.com it will become avaliable for anyone. */ $imaset_lang = array( //Panel 'use' => 'Use Imaset', 'filters' => 'Filters', 'undo' => 'Undo', 'choose_filter' => 'Choose any filter for the image', 'save' => 'Save changes', 'import' => 'Import image', 'exit' => 'Close', 'apply' => 'Apply', //Messages 'wait' => 'Please, <strong>wait</strong>...', 'saved_YES' => 'The image was correctly saved', 'saved_NO' => 'The image could not be saved', 'error' => 'Something went wrong', 'inserted' => 'Now the image is in the editor', 'loading' => 'Loading...', 'loading_image' => 'Loading image ...', 'alert_not_saved' => 'The image is not saved.\nIf you want to save changes press _Cancel_ and save it.\n\nDo you want to close Imaset?', //Categorias 'decoration' => 'Decoration', 'color' => 'Color', 'effect' => 'Effects', 'custom' => 'Custom', //Filtros 'sombra' => 'Shadow', 'marcus' => 'Nice frame', 'reflekt' => 'Reflection', 'brillo' => 'Shine', 'perspectiva' => 'Perspective', 'wave' => 'Wave', 'invertir' => 'Invert', 'bn' => 'Greyscale', 'sepia' => 'Sepia', 'colorizar' => 'Colorize', 'softblur' => 'Soft Blur', 'hardblur' => 'Stronger Blur', 'bordes' => 'Find edges', 'marca' => 'Watermark', //Filtros extendido 'reflekt_param_s' => 'Size in pixels', 'reflekt_param_oi' => 'Initial opacity percentage', 'perspectiva_param_lado' => 'Perspective direction', 'perspectiva_opt_izq' => 'Left', 'perspectiva_opt_der' => 'Right', 'colorizar_param_color' => 'Hexadecimal colour for colorize' ); ?>
<?php /* Translation of "imaset" wordpress plugin Imaset by Alex Barros 2007 < http://boozox.net > < zumbenet@gmail.com > If you want to translate this plugin to any other language, feel free to send me the translated file to zumbenet@gmail.com it will become avaliable for anyone. */ $imaset_lang = array( //Panel 'use' => 'Usar Imaset', 'filters' => 'Filtros', 'undo' => 'Deshacer', 'choose_filter' => 'Elije un filtro para aplicar', 'save' => 'Guardar Cambios', 'import' => 'Enviar al editor', 'exit' => 'Salir del editor', 'apply' => 'Aplicar', //Mensajes 'wait' => 'Por favor, <strong>espera</strong>...', 'saved_YES' => 'Imagen guardada satisfactoriamente', 'saved_NO' => 'Ha ocurrido algun problema', 'error' => 'Ha ocurrido algun error', 'inserted' => 'Imagen insertada en el editor', 'loading' => 'Cargando...', 'loading_image' => 'Cargando imagen ...', 'alert_not_saved' => 'La imagen no ha sido guardada.\nSi quieres guardar los cambios pulsa _Cancelar_ y guarda la imagen.\n\nDeseas cerrar ahora Imaset?', //Categorias 'decoration' => 'Decoración', 'color' => 'Color', 'effect' => 'Efectos', 'custom' => 'Personalizado', //Filtros 'sombra' => 'Sombra', 'marcus' => 'Marco', 'reflekt' => 'Reflejo', 'brillo' => 'Brillo', 'perspectiva' => 'Perspectiva', 'wave' => 'Ondular', 'invertir' => 'Invertir colores', 'bn' => 'Escala de grises', 'sepia' => 'Sepia', 'colorizar' => 'Colorizar', 'softblur' => 'Desenfoque suave', 'hardblur' => 'Desenfoque fuerte', 'bordes' => 'Encontrar bordes', 'marca' => 'Marca de agua', //Filtros extendido 'reflekt_param_s' => 'Tamaño del reflejo en píxeles.', 'reflekt_param_oi' => 'Opacidad inicial del degradado', 'perspectiva_param_lado' => 'Dirección de la perspectiva', 'perspectiva_opt_izq' => 'Izquierda', 'perspectiva_opt_der' => 'Derecha', 'colorizar_param_color' => 'Color hexadecimal para colorar' ); ?>
var imasetON = false; var imasetFContent = <? echo '"'.substr(__FILE__,0,strpos(__FILE__,'plugins')).'"; '; ?> var imasetSrc = false; var imasetSaved = true; var imasetLLF = 0; function ima$et(n) { return document.getElementById("imaset"+n); } function imasetDisplay() { if(imasetON) return false; imasetDLayer(); imasetContent('<span id="imasetLoading" style="float:left"><?php echo _i('loading')?></span>'); imasetAjax('ini'); imasetON = true; return true; } function imasetContent(t) { var ct = ima$et("Content"); if (ct == null) { var ct = document.createElement("div"); ct.id = "imasetContent"; document.body.appendChild(ct); } ct.innerHTML = t; } function imasetPrevw(c) { ima$et("Prevw").innerHTML = c; } function imasetClose() { if(!imasetSaved) { if(confirm("<?php echo _i('alert_not_saved')?>")) { imasetSaved = true; imasetClose(); } } else { var a = ima$et("DLayer"); var b = ima$et("Content"); a.parentNode.removeChild(a); b.parentNode.removeChild(b); imasetON = false; return true; } return false; } function imasetDLayer(t) { document.location = '#'; if (ima$et("DLayer") != null) return false; var i = document.createElement("div"); i.id = "imasetDLayer"; document.body.appendChild(i); } function imasetMsg(m) { if(ima$et("Msg") && imasetLLF!=2) ima$et("Msg").innerHTML = m; } function imasetSidebarHideAll() { var i,ty,ctd; ty = document.getElementsByTagName('h4'); ctd = ty.length; for(i=0;i<ctd;i++) { document.getElementById(ty[i].id+'L').style.display = 'none'; } } function imasetSidebarShow(id) { var l = document.getElementById(id+'L'); if(l.style.display == 'block') { imasetSidebarHideAll(); } else { imasetSidebarHideAll(); l.style.display = 'block'; } } function imasetToogleImg(src,s,llf) { imasetLLF = llf; imasetSrc = src; ima$et("Img").src = '../wp-content/plugins/imaset/prev.php?img='+imasetFContent+src+'&dim=400x300&save='+s+'&r='+Math.floor(Math.random()*800); ima$et("Img").setAttribute('class','proceso'); ima$et("BackLoad").setAttribute('class','proceso'); imasetMsg("<?php echo _i('loading_image')?>"); } function imasetAddImg() { return imasetAjax('alt:'+imasetSrc); } function imasetAddToEd(alt) { var url = '<?php bloginfo( 'wpurl' ); ?>/wp-content/'+imasetSrc; image = new Image(); image.src = url+'?r='+Math.random(); h = "<img src='" + url + "' alt='"+alt+"' />"; var win = window.opener ? window.opener : window.dialogArguments; if ( !win ) win = top; tinyMCE = win.tinyMCE; if ( typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content') ) { tinyMCE.selectedInstance.getWin().focus(); tinyMCE.execCommand('mceInsertContent', false, h); } else win.edInsertContent(win.edCanvas, h); } function imasetImgLoaded() { ima$et("Img").setAttribute('class',''); ima$et("BackLoad").setAttribute('class',''); imasetMsg("<?php echo _i('choose_filter')?>"); } function imasetLoading() { if(ima$et("Loading")) ima$et("Loading").style.display = 'block'; imasetMsg("<?php echo _i('loading_image')?>"); } 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('AJAX Failed' )}; mysack.runAJAX(); return true; }
<?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='') { $BG = 'FFFFFF'; // Escribe en hexadecimal el color que quieres poner de fondo a las imagenes con transparencia $this->BGred = hexdec($BG[0].$BG[1]); $this->BGgreen = hexdec($BG[2].$BG[3]); $this->BGblue = hexdec($BG[4].$BG[5]); $this->dir = str_replace('imasetClass.php','',__FILE__); $this->content = substr(__FILE__,0,strpos(__FILE__,'plugins')); //Filtros disponibles $this->filtros = array(); $this->filtros['decoration'][] = array('nom'=>'sombra','param'=>false); $this->filtros['decoration'][] = array('nom'=>'marcus','param'=>false); $this->filtros['decoration'][] = array('nom'=>'reflekt','param'=>array('s'=>30,'oi'=>60)); $this->filtros['decoration'][] = array('nom'=>'brillo','param'=>false); $this->filtros['decoration'][] = array('nom'=>'perspectiva','param'=>array('lado'=>array('izq','der'))); $this->filtros['decoration'][] = array('nom'=>'wave','param'=>false); $this->filtros['color'][] = array('nom'=>'invertir','param'=>false); $this->filtros['color'][] = array('nom'=>'bn','param'=>false); $this->filtros['color'][] = array('nom'=>'sepia','param'=>false); $this->filtros['color'][] = array('nom'=>'colorizar','param'=>array('color'=>'FFFFFF')); $this->filtros['effect'][] = array('nom'=>'softblur','param'=>false); $this->filtros['effect'][] = array('nom'=>'hardblur','param'=>false); $this->filtros['effect'][] = array('nom'=>'bordes','param'=>false); //$this->filtros['custom'][] = array('nom'=>'marca','param'=>'marcas'); } 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; } // Manejo de imagenes en GD function nuevaImagen($img) { $im = false; switch(true) { case ereg('\.jpg',$img): $im = imagecreatefromjpeg($img); break; case ereg('\.gif',$img): $imp = imagecreatefromgif($img); $x = imagesx($imp); $y = imagesy($imp); $im = imagecreatetruecolor($x,$y); imagefilledrectangle($im,0,0,$x,$y,imagecolorallocate($im,$this->BGred,$this->BGgreen,$this->BGblue)); imagecopy($im,$imp,0,0,0,0,$x,$y); break; case ereg('\.png',$img): $imp = imagecreatefrompng($img); $x = imagesx($imp); $y = imagesy($imp); $im = imagecreatetruecolor($x,$y); imagefilledrectangle($im,0,0,$x,$y,imagecolorallocate($im,$this->BGred,$this->BGgreen,$this->BGblue)); imagecopy($im,$imp,0,0,0,0,$x,$y); 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; } if($t) imagedestroy($im); 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; } if($t) imagedestroy($im); return $t; } // Funciones de retoque 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,$s=30,$oi=60) // s: tamaño reflejo; oi: opacidad inicial { //controlo los limites if($s>300) $s = 300; if($oi>100) $oi = 100; if($s<1) $s = $s = 1; if($oi<5) $s = 5; $sx = imagesx($im); $sy = imagesy($im); $x = $sx; $y = $sy+$s; $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<=$s;$i++) imagecopymerge($reflekt, $im, 0, $sy+$i, 0, $sy-($i+1), $x, 1, round($oi-($i*$oi/$s))); 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); $nh = $h*2; $nw = $w*2; //amplio, para ganar calidad $imblanc = imagecreatetruecolor(1,$nh); $color = imagecolorallocate($imblanc, 255,255,255); //Blanco imagefilledrectangle($imblanc, 0, 0, 1, $nh, $color); //Relleno el fondo $im2 = imagecreatetruecolor($nw,$nh); imagefilledrectangle($im2, 0, 0, $nw, $nh, $color); //Relleno el fondo imagecopyresampled ($im2,$im,0,0,0,0,$nw,$nh,$w, $h); for($i=0; $i<$nw; $i++) { imagecopymerge($im2, $imblanc, $i, 0, 0, 0, 1, ($nh/2+($nh/25)*sin(6.3/$nw*$i)), 25); } imagecopyresampled ($im,$im2,0,0,0,0,$w, $h,$nw,$nh); imagedestroy($im2); return $im; } function perspectiva($im,$dir = 'der') // 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 $tx = $x * $ampl; $ty = $y * $ampl; $pers = imagecreatetruecolor($tx,$ty); $color = imagecolorallocate($pers, 255,255,255); //Blanco imagefilledrectangle($pers, 0, 0, $tx, $ty, $color); //Relleno el fondo $factor = ($porc/100)/$x ; for($i=0;$i<$tx;$i++) { $hy = round($ty-($y*($i+1)*$factor*$ampl)); $py = round(($ty-$hy)/2); if($dir == 'der') $j = $i; else $j = $tx-$i; imagecopyresampled( $pers, $im, $j, $py, $j/$ampl, 0, 1, $hy, 1, $y ); } $pers2 = imagecreatetruecolor(0.7*$x,$y); imagecopyresampled($pers2, $pers, 0, 0, 0, 0, 0.7*$x, $y, $tx, $ty); 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 invertir($im) { $sx = imagesx($im); $sy = imagesy($im); for($x=0;$x<$sx;$x++) { for($y=0;$y<$sy;$y++) { $rgb = ImageColorAt($im, $x, $y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; $c = imagecolorallocate($im,(255-$r),(255-$g),(255-$b)); //genero el color inverso imagesetpixel($im,$x,$y,$c); //lo aplico en la imagen } } return $im; } function mono(&$im, $hex = 'FFFFFF') { //hex2dec $tint_r = hexdec($hex[0].$hex[1]); $tint_g = hexdec($hex[2].$hex[3]); $tint_b = hexdec($hex[4].$hex[5]); $width = imagesx($im); $height = imagesy($im); $dest = imagecreate ($width, $height); for ($i=0; $i<256; $i++) imagecolorallocate ($dest, $i, $i, $i); imagecopyresized ($dest, $im, 0, 0, 0, 0, $width, $height, $width, $height); for ($i = 0; $i < 256; $i++) imagecolorset ($dest, $i, min($i * abs($tint_r) / 255, 255), min($i * abs($tint_g) / 255, 255), min($i * abs($tint_b) / 255, 255)); $img = imagecreate ($width, $height); imagecopy ($im, $dest, 0, 0, 0, 0, $width, $height); imagedestroy ($dest); return $im; } function imageconvolution($src, $filter, $filter_div, $offset) //[http://es2.php.net/manual/es/function.imageconvolution.php] { if ($src==NULL) { return 0; } $sx = imagesx($src); $sy = imagesy($src); $srcback = ImageCreateTrueColor ($sx, $sy); ImageCopy($srcback, $src,0,0,0,0,$sx,$sy); if($srcback==NULL){ return 0; } for ($y=0; $y<$sy; ++$y) { for($x=0; $x<$sx; ++$x) { $new_r = $new_g = $new_b = 0; $alpha = imagecolorat($srcback, $pxl[0], $pxl[1]); $new_a = $alpha >> 24; for ($j=0; $j<3; ++$j) { $yv = min(max($y - 1 + $j, 0), $sy - 1); for ($i=0; $i<3; ++$i) { $pxl = array(min(max($x - 1 + $i, 0), $sx - 1), $yv); $rgb = imagecolorat($srcback, $pxl[0], $pxl[1]); $new_r += (($rgb >> 16) & 0xFF) * $filter[$j][$i]; $new_g += (($rgb >> 8) & 0xFF) * $filter[$j][$i]; $new_b += ($rgb & 0xFF) * $filter[$j][$i]; } } $new_r = ($new_r/$filter_div)+$offset; $new_g = ($new_g/$filter_div)+$offset; $new_b = ($new_b/$filter_div)+$offset; $new_r = ($new_r > 255)? 255 : (($new_r < 0)? 0:$new_r); $new_g = ($new_g > 255)? 255 : (($new_g < 0)? 0:$new_g); $new_b = ($new_b > 255)? 255 : (($new_b < 0)? 0:$new_b); $new_pxl = ImageColorAllocateAlpha($src, (int)$new_r, (int)$new_g, (int)$new_b, $new_a); if ($new_pxl == -1) { $new_pxl = ImageColorClosestAlpha($src, (int)$new_r, (int)$new_g, (int)$new_b, $new_a); } if (($y >= 0) && ($y < $sy)) { imagesetpixel($src, $x, $y, $new_pxl); } } } imagedestroy($srcback); return 1; } function convolution($im,$m) { switch($m) { case 'softblur': $matrix = array( array( 1, 1, 1 ), array( 1, 8, 1 ), array( 1, 1, 1) ); break; case 'hardblur': $matrix = array( array( 2, 2, 2 ), array( 2, 2, 2 ), array( 2, 2, 2) ); break; case 'bordes': $matrix = array( array(-16,0,0), array(0,16,0), array(0,0,0) ); break; case 'azar': $matrix = array( array( rand(-3,10), rand(-3,10), rand(-3,10) ), array( rand(-3,10), rand(-3,10), rand(-3,10) ), array( rand(-3,10), rand(-3,10), rand(-3,11) ) ); break; default: $matrix = array( array( 0, 0, 0 ), array( 0, 16, 0 ), array( 0, 0, 0 ) ); break; } if (function_exists('imageconvolution')) { imageconvolution($im, $matrix, 16, 0); } else { $this->imageconvolution($im, $matrix, 16, 0); } return $im; } 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,$e[0],$e[1]); break; case 'marca': return $this->marca($im,$e[0]); break; case 'wave': return $this->wave($im); break; case 'brillo': return $this->brillo($im); break; case 'invertir': return $this->invertir($im); break; case 'bn': return $this->mono($im); break; case 'colorizar': return $this->mono($im,$e[0]); break; case 'sepia': return $this->mono($im,'F1D5A4'); break; case 'softblur': return $this->convolution($im,'softblur'); break; case 'hardblur': return $this->convolution($im,'hardblur'); break; case 'bordes': return $this->convolution($im,'bordes'); break; case 'perspectiva': return $this->perspectiva($im,$e[0]); break; default: return $im; break; } } } ?>
<?php /* Plugin Name: Imaset Plugin URI: http://codis.boozox.net/proyecto/imaset Description: Trata tus imágenes almacenadas en Wordpress con interesantes efectos Version: 2.0 Author: Alex Barros Author URI: http://boozox.net */ ## Licencia: GNU/GPL v3+ ## // JavaScript y CSS function imasetPS() { wp_print_scripts( array( 'sack' )); // biblioteca AJAX de Wordpress echo '<script type="text/javascript">'; include('imasetJS.js'); echo '</script>'; echo '<style type="text/css">'; include('imasetStyle.css'); echo '</style>'; } //control del idioma function _i($c) { if(file_exists(ABSPATH.'wp-content/plugins/imaset/lang/'.WPLANG.'.php')) { include('lang/'.WPLANG.'.php'); $traduce = $imaset_lang; } if(empty($traduce) && file_exists(ABSPATH.'wp-content/plugins/imaset/lang/en.php')) { include('lang/en.php'); $traduce = $imaset_lang; } if(!empty($traduce[$c])) return htmlentities(utf8_decode($traduce[$c])); else return $c; } //funcion a la que llama Ajax function imasetAjax() { session_start(); include_once 'imasetClass.php'; $q = $_POST['q']; $qe = explode(':',$q); $imaset = new Imaset; if($q == 'ini') { $imaset->explora(); //explora los directorios en busca de imagenes session_destroy(); $html = "<div class=\"sidebar\"><h3>"._i('filters').":</h3>"; foreach($imaset->filtros as $c=>$v) { $html .= "<h4 onClick=\"imasetSidebarShow(this.id)\" id=\"imaset".$c."\">"._i($c)."</h4><ul id=\"imaset".$c."L\">"; foreach($v as $f) $html .= "<li><a href=\"#\" onClick=\"imasetAjax('filtro:$f[nom]')\">"._i($f['nom'])."</a></li>"; $html .= "</ul>"; } $html .= "<a class=\"deshacer\" onClick=\"imasetAjax('deshaz')\" href=\"#\">«"._i('undo')."</a><div id=\"imasetMsg\">"._i('choose_filter')."</div><input type=\"button\" class=\"button\" value=\""._i('save')."\" onClick=\"imasetAjax('guardar'); imasetMsg('"._i('wait')."');\" /><input type=\"button\" class=\"button\" value=\""._i('import')."\" onClick=\"imasetAddImg(); imasetMsg('"._i('wait')."')\" /><input type=\"button\" class=\"button delete\" value=\""._i('exit')."\" onClick=\"imasetClose()\" />"; $html .= "</div><div class=\"view\"><p id=\"imasetLoading\">"._i('loading')."</p><div id=\"imasetBackLoad\"><img onLoad=\"imasetImgLoaded()\" id=\"imasetImg\" src=\"../wp-content/plugins/imaset/prev.php?save=1&img=".$imaset->content.$imaset->ims[0]."&dim=400x300&r=".mt_rand()."\" /></div><div id=\"imasetPrevw\">"; $html .= paginacio(0,$imaset->num); if($imaset->num < 12) $max = $imaset->num; else $max = 12; for($i=0;$i<$max;$i++) { $html .= "<a class=\"img\" href=\"#\" onClick=\"imasetToogleImg('".$imaset->ims[$i]."',1,0); imasetSaved = true;\"><img src=\"../wp-content/plugins/imaset/prev.php?snap=1&img=".$imaset->content.$imaset->ims[$i]."&r=".mt_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).'\'); imasetSrc = "'.$imaset->ims[0].'";'); } 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++) { if(ereg('-',$filtros[$i])){ $pts = explode('-',$filtros[$i]); $f = $pts[0]; $e = explode(',',$pts[1]); } else{ $f = $filtros[$i]; $e = false; } $im = $imaset->aplicaFiltro($im,$f,$e); } } $s = $imaset->creaImagen($im,$imaset->content.$_SESSION['acimg']); if($s) $msg = '<strong style=\\"color:green;\\">'._i('saved_YES').'</strong>'; else $msg = '<strong style=\\"color:red;\\">'._i('saved_NO').'</strong>'; die(' imasetMsg("'.$msg.'"); imasetToogleImg("'.$_SESSION['acimg'].'",1,2); imasetSaved = true;'); } elseif(ereg("filtro",$q)) { foreach($imaset->filtros as $c=>$v) { foreach($v as $f) $fs["$f[nom]"] = $f['param']; } if(isset($fs["$qe[1]"])) { $pa = $fs["$qe[1]"]; if($pa) { $msg = ''; if(is_array($pa)) { foreach($pa as $c=>$v) { $id = 'imasetPam_'.$c; $msg .= "<p>"._i($qe[1].'_param_'.$c)."</p>"; if(is_array($v)) { $msg .= '<select id="'.$id.'">'; foreach($v as $vv) $msg .= '<option value="'.$vv.'">'._i($qe[1].'_opt_'.$vv).'</option>'; } else { $msg .= '<input type="text" id="'.$id.'" value="'.$v.'">'; } $pams[] = '\'+ima$et(\'Pam_'.$c.'\').value+\''; } } else { $msg .= "<p>".$imaset->traduce($qe[1].'_param')."</p>"; } $msg .= "<p><input type=\"button\" class=\"button\ type=\"button\" onClick=\"imasetAjax('aplica:$qe[1]:".implode(',',$pams)."');\" value=\""._i('apply')."\"></p>"; die('imasetMsg(\''.str_replace(array("\n","'"),array('',"\'"),$msg).'\');'); } else { $_SESSION['hist'] .= ';'.$qe[1]; die('imasetToogleImg("'.$_SESSION['acimg'].'",0,1); imasetSaved = false;'); } } else { die("imasetMsg('"._i('error')."')"); } } elseif(ereg('aplica:',$q)) { $_SESSION['hist'] .= ';'.$qe[1].'-'.$qe[2]; die('imasetToogleImg("'.$_SESSION['acimg'].'",0,1); imasetSaved = false;'); } elseif($q == 'deshaz') { $hist = explode(';',$_SESSION['hist']); $k = count($hist)-1; unset($hist[$k]); $_SESSION['hist'] = implode(';',$hist); die('imasetToogleImg("'.$_SESSION['acimg'].'",0,1);'); } elseif(ereg("desde",$q)) { $imaset->explora(); //explora los directorios en busca de imagenes $p = $qe[1]; $html = paginacio($p,$imaset->num); 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('".$imaset->ims[$i]."',1,0); imasetSaved = true\"><img src=\"../wp-content/plugins/imaset/prev.php?snap=1&img=".$imaset->content.$imaset->ims[$i]."&r=".mt_rand()."\" /></a>"; } $html .= '<div style="clear:left;"></div>'; die('imasetPrevw(\''.str_replace(array("\n","'"),array('',"\'"),$html).'\');'); } elseif(ereg('alt',$q)) { $pts = explode(':',$q); $p = $pts[1]; global $wpdb; $alt_img = $wpdb->get_var("select post_title from $wpdb->posts where guid LIKE '%".mysql_real_escape_string($p)."'"); die( "imasetAddToEd('$alt_img'); imasetMsg('"._i('inserted').".')" ); } else { die("alert('Error')"); } } function paginate_links2( $args = '' ) { $defaults = array( 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below) 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number 'total' => 1, 'current' => 0, 'show_all' => false, 'prev_next' => true, 'prev_text' => __('« Previous'), 'next_text' => __('Next »'), 'end_size' => 1, // How many numbers on either end including the end 'mid_size' => 2, // How many numbers to either side of current not including current 'type' => 'plain', 'add_args' => false // array of query args to aadd ); foreach($defaults as $dfk => $dfv) { if(empty($args[$dfk])) $args[$dfk] = $dfv; } //$args = wp_parse_args( $args, $defaults ); // No wp v.1 compatible extract($args, EXTR_SKIP); // Who knows what else people pass in $args $total = (int) $total; if ( $total < 2 ) return; $current = (int) $current; $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default. $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2; $add_args = is_array($add_args) ? $add_args : false; $r = ''; $page_links = array(); $n = 0; $dots = false; $per = (int)$per; if ( $prev_next && $current && 1 < $current ) : $link = str_replace('%_%', 2 == $current ? '' : $format, $base); $link = str_replace('%#%', $current - 1, $link); if ( $add_args ) $link = add_query_arg( $add_args, $link ); //$page_links[] = "<a class='prev page-numbers' href='" . clean_url($link) . "'>$prev_text</a>"; $link = ($current-2)*$per; $page_links[] = '<a class="next page-numbers" href="#" onclick="imasetAjax(\'desde:' . $link . '\')">'.$prev_text.'</a>'; endif; for ( $n = 1; $n <= $total; $n++ ) : if ( $n == $current ) : $page_links[] = "<span class='page-numbers current'>$n</span>"; $dots = true; else : if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : $link = str_replace('%_%', 1 == $n ? '' : $format, $base); $link = str_replace('%#%', $n, $link); if ( $add_args ) $link = add_query_arg( $add_args, $link ); // $page_links[] = "<a class='page-numbers' href='" . $link . "'>$n</a>"; $link = ($n-1)*$per; $page_links[] = '<a class="next page-numbers" href="#" onclick="imasetAjax(\'desde:' . $link . '\')">'.$n.'</a>'; $dots = true; elseif ( $dots && !$show_all ) : $page_links[] = "<span class='page-numbers dots'>...</span>"; $dots = false; endif; endif; endfor; if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) : $link = str_replace('%_%', $format, $base); $link = str_replace('%#%', $current + 1, $link); if ( $add_args ) $link = add_query_arg( $add_args, $link ); $link = $current*$per; $page_links[] = '<a class="next page-numbers" href="#" onclick="imasetAjax(\'desde:' . $link . '\')">'.$next_text.'</a>'; endif; switch ( $type ) : case 'array' : return $page_links; break; case 'list' : $r .= "<ul class='page-numbers'>\n\t<li>"; $r .= join("</li>\n\t<li>", $page_links); $r .= "</li>\n</ul>\n"; break; default : $r = join("\n", $page_links); break; endswitch; return $r; } //funcion de paginacion para imaset function paginacio($p,$total,$per=12){ $paged = ceil($p / $per); $paged++; $page_links = paginate_links2( array( 'base' => '%#%',//add_query_arg( 'paged', '%#%' ) 'format' => '', 'total' => ceil($total / $per), 'current' => $paged ? $paged : 1, 'prev_text' => '«', 'next_text' => '»', 'per' => $per )); if ( $page_links ) return '<p style="text-align:center;">'.$page_links.'</p>'; } function imasetBotonUso(){ echo '<input type="button" class="button" style="padding: 4px; margin:4px;" value="'._i('use').'" onClick="imasetDisplay(1)" />'; } add_action("admin_print_scripts", "imasetPS"); add_action('wp_ajax_imasetAjax', 'imasetAjax' ); add_action("edit_form_advanced", "imasetBotonUso"); ?>
#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); } #imasetBackLoad {text-align:center;} #imasetBackLoad.proceso { background: transparent url(<?php echo bloginfo( 'wpurl' ); ?>/wp-content/plugins/imaset/img/ajax-loader.gif) no-repeat 50% 50%; } #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 #3B729E; float:right; z-index: 1003; } #imasetContent .sidebar h3 { margin: 8px; padding: 0; font-family: sans-serif; } #imasetContent .sidebar h4 { margin: 0; padding: 4px 8px; background-color: #ACD4E6; border-bottom: 1px solid #3B729E; cursor: pointer; } #imasetContent .sidebar h4:hover { background-color: #7DB9D4; } #imasetContent .sidebar ul { margin: 4px; padding: 0; display: none; } #imasetContent .sidebar li { list-style: none; margin: 0; padding: 2px 4px; } #imasetContent .sidebar a { } #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.4; opacity: .4; filter: alpha(opacity=40) } #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; }
<?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++) { if(ereg('-',$filtros[$i])){ $pts = explode('-',$filtros[$i]); $f = $pts[0]; $e = explode(',',$pts[1]); } else{ $f = $filtros[$i]; $e = false; } $im = $imaset->aplicaFiltro($im,$f,$e); } } //Resuelvo los tamaños $dim = false; if($_GET['dim']) $max = explode('x',$_GET['dim']); if($_GET['snap']) $max = array(128,128); if($im AND $max) { $ow = imagesx($im); $oh = imagesy($im); //tamanos originales $mw = $max[0]; $mh = $max[1]; // maximos if($oh>$mh){ $nh = $mh; $nw = $nh*$ow/$oh; if($nw>$mw){ $nh = $mw*$mh/$nw; $nw = $mw; } } elseif($ow>$mw) { $nw = $mw; $nh = $nw*$oh/$ow; if($nh>$mh){ $nw = $mh*$mw/$nh; $nh = $mh; } } if($nh && $nw){ $snap = imagecreatetruecolor($nw,$nh); imagecopyresized($snap, $im, 0, 0, 0, 0, $nw, $nh, $ow, $oh); $im = $snap; } } $imaset->exportaImagen($im,$img); ?>