Deprecated: Assigning the return value of new by reference is deprecated in /home/controlz/public_html/blog/wp-settings.php on line 472

Deprecated: Assigning the return value of new by reference is deprecated in /home/controlz/public_html/blog/wp-settings.php on line 487

Deprecated: Assigning the return value of new by reference is deprecated in /home/controlz/public_html/blog/wp-settings.php on line 494

Deprecated: Assigning the return value of new by reference is deprecated in /home/controlz/public_html/blog/wp-settings.php on line 530

Strict Standards: Declaration of Walker_Page::start_lvl() should be compatible with Walker::start_lvl(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_Page::end_lvl() should be compatible with Walker::end_lvl(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_Page::start_el() should be compatible with Walker::start_el(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_Page::end_el() should be compatible with Walker::end_el(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_PageDropdown::start_el() should be compatible with Walker::start_el(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 611

Strict Standards: Declaration of Walker_Category::start_lvl() should be compatible with Walker::start_lvl(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_Category::end_lvl() should be compatible with Walker::end_lvl(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_Category::start_el() should be compatible with Walker::start_el(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_Category::end_el() should be compatible with Walker::end_el(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_CategoryDropdown::start_el() should be compatible with Walker::start_el(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 728

Strict Standards: Redefining already defined constructor for class wpdb in /home/controlz/public_html/blog/wp-includes/wp-db.php on line 306

Deprecated: Assigning the return value of new by reference is deprecated in /home/controlz/public_html/blog/wp-includes/cache.php on line 103

Strict Standards: Redefining already defined constructor for class WP_Object_Cache in /home/controlz/public_html/blog/wp-includes/cache.php on line 425

Deprecated: Assigning the return value of new by reference is deprecated in /home/controlz/public_html/blog/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/controlz/public_html/blog/wp-includes/theme.php on line 623

Strict Standards: Redefining already defined constructor for class WP_Dependencies in /home/controlz/public_html/blog/wp-includes/class.wp-dependencies.php on line 15

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/controlz/public_html/blog/wp-settings.php:472) in /home/controlz/public_html/blog/wp-content/plugins/si-captcha-for-wordpress/si-captcha.php on line 31

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/controlz/public_html/blog/wp-settings.php:472) in /home/controlz/public_html/blog/wp-content/plugins/si-captcha-for-wordpress/si-captcha.php on line 31

Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method GoogleSitemapGeneratorLoader::Enable() should not be called statically in /home/controlz/public_html/blog/wp-includes/plugin.php on line 311
Ejemplo Completo Php Redimensionar Imagenes | formatic.cat

Entradas con la etiqueta ‘ejemplo completo php redimensionar imagenes’

script redimensionar imagenes gif’s y png’s transparentes

Viernes, 29 de Agosto de 2008

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/controlz/public_html/blog/wp-content/plugins/ig_syntax_hilite/geshi.php on line 2056

Este post es la continuación de redimensionar imagens gif y png transparentes

Ahora un ejemplo completo donde tenemos una función que nos pasan el string de una imagen y devolvemos ese string redimensionado. Esta preparado para utilizarse al recoger la información de un formulario con imagenes. Del Array $_FILES[] obtendremos el string de la imagen tal que así

PHP:
  1. $stringConLaFoto=file_get_contents($_FILES[$nombre_Foto_Formulario]['tmp_name']);
  2.  
  3. $extensión=$_FILES[$nombre_Foto_Formulario]['type'];
  4.  
  5. $ancho=150;
  6.  
  7. //ahora llamamos a la funcion de redimensionar
  8.  
  9. $imagen_redimensionada=redimensionarImatge($stringConLaFoto,$extension,$ancho)

PHP:
  1. #************************************************************************************
  2. #    redimensionaImatge:
  3. #
  4. #    Donada una imatge es redimensiona a l'amplada o alçada passades com a paràmetre.
  5. #    Si no se li passen les mesures, s'agafaran les dimensions de les variables
  6. #    globals, que es troben a l'inicialitzador, MIDA_IMATGE_AMPLADA i MIDA_IMATGE_ALCADA
  7. #
  8. #    Autor: Marc + Cristian en  controlzeta.net
  9. #    Fecha creacion: 24/04/08
  10.  
  11. #  ultima modificacion 28/08/2008
  12. #
  13. #************************************************************************************
  14.  
  15. function redimensionarImatge($imatge,$extensio,$amplada=FALSE,$alcada=FALSE) {
  16. $original = imagecreatefromstring($imatge);
  17. $mides[] = imagesx($original); // $mides[0] ANCHURA
  18. $mides[] = imagesy($original); //  $mides[1] ALTURA
  19.  
  20. //echo '<br>AMPLADA R:'.$amplada;
  21. //echo '<br>AMPLADA R:'.$alcada;
  22. //echo '<br>AMPLADA:'.$mides[0];
  23. //echo '<br>AMPLADA:'.$mides[1];
  24.  
  25. if ( !( ($mides[0]==$amplada or $amplada==FALSE) AND ($mides[1]== $alcada or $alcada==FALSE) ) ){ //comprueba Que no se redimendsione al mismo tamaño Critian 19-08-2008
  26.  
  27. if($amplada || $alcada) {
  28. $midaHoritzontal = $amplada;
  29. $midaVertical = $alcada;
  30.  
  31. if( $alcada && ($mides[0]>(2*$mides[1])) ) {
  32. unset($alcada);
  33. $midaHoritzontal = 100;
  34. } elseif(!$alcada) {
  35. $midaVertical = $mides[1];
  36. }
  37. } elseif($mides[0] <= MIDA_IMATGE_AMPLADA && $mides[1] <= MIDA_IMATGE_ALCADA) {
  38. $midaHoritzontal = $mides[0];
  39. $midaVertical = $mides[1];
  40. $noRedimensionar = true;
  41. } else {
  42. $midaHoritzontal = MIDA_IMATGE_AMPLADA;
  43. $midaVertical = MIDA_IMATGE_ALCADA;
  44. }
  45. }else{
  46. $midaHoritzontal = $mides[0];
  47. $midaVertical = $mides[1];
  48. $noRedimensionar = true;
  49. }
  50.  
  51. if(!isset($noRedimensionar)) {
  52. unset($imatge);
  53.  
  54. if($midaHoritzontal) {
  55. $ratio = ($mides[0]/$midaHoritzontal);
  56. $midaVertical = round($mides[1]/$ratio);
  57. } else {
  58. $ratio = ($mides[1]/$midaVertical);
  59. $midaHoritzontal = round($mides[0]/$ratio);
  60. }
  61.  
  62. $thumb = imagecreatetruecolor($midaHoritzontal,$midaVertical);
  63.  
  64. switch($extensio) {
  65. case 'image/pjpeg':
  66. case 'image/jpeg':
  67. imagecopyresampled($thumb,$original,0,0,0,0,$midaHoritzontal,$midaVertical,$mides[0],$mides[1]);
  68. imagejpeg($thumb,'../tempImage');
  69. break;
  70.  
  71. case 'image/gif':
  72. case 'image/png':
  73. $colorTransparancia=imagecolortransparent($original);// devuelve el color usado como transparencia o -1 si no tiene transparencias
  74. if($colorTransparancia!=-1){ //TIENE TRANSPARENCIA
  75. //unset($thumb);
  76. //$thumb = imagecreatetruecolor($midaHoritzontal,$midaVertical);
  77.  
  78. $colorTransparente = imagecolorsforindex($original, $colorTransparancia); //devuelve un array con las componentes de lso colores RGB + alpha
  79. $idColorTransparente = imagecolorallocatealpha($thumb, $colorTransparente['red'], $colorTransparente['green'], $colorTransparente['blue'], $colorTransparente['alpha']); // Asigna un color en una imagen retorna identificador de color o FALSO o -1 apartir de la version 5.1.3
  80.  
  81. imagefill($thumb, 0, 0, $idColorTransparente);// rellena de color desde una cordenada, en este caso todo rellenado del color que se definira como transparente
  82. imagecolortransparent($thumb, $idColorTransparente); //Ahora definimos que en el nueva imagen el color transparente será el que hemos pintado el fondo.
  83. imagecopyresampled($thumb,$original,0,0,0,0,$midaHoritzontal,$midaVertical,$mides[0],$mides[1]);// copia y redimensiona un trozo de imagen
  84. //imagecopyresized
  85. }
  86.  
  87. switch ($extensio){
  88. case 'image/gif':
  89. imagegif($thumb,'../tempImage');
  90. break;
  91. case 'image/png':
  92. imagepng($thumb,'../tempImage');
  93. break;
  94. }
  95.  
  96. default:
  97. imagecopyresampled($thumb,$original,0,0,0,0,$midaHoritzontal,$midaVertical,$mides[0],$mides[1]);
  98. imagejpeg($thumb,'../tempImage');
  99.  
  100. break;
  101. }
  102.  
  103. //Lliurem la memòria
  104. unset($original);
  105. unset($thumb);
  106.  
  107. if (function_exists('file_get_contents')) {
  108. $imatge = file_get_contents('../tempImage');
  109. } elseif ($file_to_insert_size = filesize('../tempImage')) {
  110. $imatge = fread(fopen('../tempImage', 'rb'), $file_to_insert_size);
  111. }
  112.  
  113. //eliminació de la imatge del servidor
  114. @unlink('../tempImage');
  115.  
  116. }
  117.  
  118. return $imatge;
  119.  
  120. }

En este escript no se tienen en cuenta la redimension de imagenes gif animadas.