<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Ridurre dimensioni immagini mostrate da plugin]]></title><description><![CDATA[<p dir="auto">Ho la necessità di modificare il plugin "randomimage".<br />
Il suddetto plugin visualizza nella sidebar 12 immagini prelevate a random tra tutte le immagini pubblicate sul blog.<br />
Il problema è che questo plug in non ridimensiona le immagini, ma semplicemente al momento della visualizzazione modifica le dimensioni cambiando l'attributo width dell'img src.<br />
Con la conseguenza che ogni volta vengono visualizzate immagini di dimensioni inferiori ai 100px che però pesano anche più di 100Kb-150Kb l'una.</p>
<p dir="auto">Sapreste aiutarmi a far si che il plugin diminuisca la dimensione dell'immagine?</p>
<p dir="auto">Questo è il codice:</p>
<pre><code class="language-php">&lt;?php

/*
Plugin Name: Random Image
Description: Display a random image that links back to the post it came from.
Version: 5.0
Author: Justin Watt
*/

// widgetization
function widget_randomimage_init() {
  if (!function_exists('register_sidebar_widget')) {
		return;
	}

	function widget_randomimage() {
		print '&lt;li&gt;' . "\n";
		randomimage();
		print '&lt;/li&gt;' . "\n";
	}

	register_sidebar_widget('Random Image', 'widget_randomimage');
}

add_action('plugins_loaded', 'widget_randomimage_init');


// add configuration page to WordPress
function randomimage_add_page()
{
  add_options_page('Random Image', 'Random Image', 6, __FILE__, 'randomimage_configuration_page');
}
add_action('admin_menu', 'randomimage_add_page');


// helper function to set randomimage defaults (if necessary)
// and return array of options
function get_randomimage_options()
{
  $randomimage_options = get_option('randomimage_options');

  if (!isset($randomimage_options["image_template_html"]) || $randomimage_options["image_template_html"] == '') {

    if (isset($randomimage_options["show_post_title"]) || isset($randomimage_options["show_alt_caption"])) {
      // lets upgrade from v3
      $upgraded_template = '';
      if ($randomimage_options["show_post_title"] === true) {
        $upgraded_template .= "\n&lt;strong&gt;%1&lt;/strong&gt;&lt;br /&gt;\n";
      }

      $upgraded_template .= "%2";

      if ($randomimage_options["show_alt_caption"] === true) {
        $upgraded_template .= "&lt;br /&gt;\n&lt;em&gt;%3&lt;/em&gt;\n";
      }

      $randomimage_options["image_template_html"] = $upgraded_template;
      
      unset($randomimage_options["show_post_title"]);
      unset($randomimage_options["show_alt_caption"]);

    } else {
      $randomimage_options["image_template_html"] = "\n&lt;strong&gt;%1&lt;/strong&gt;&lt;br /&gt;\n%2&lt;br /&gt;\n&lt;em&gt;%3&lt;/em&gt;\n";
    }
  }

  // init default options if options aren't set    
  if (!isset($randomimage_options["show_images_in_posts"])) {
    $randomimage_options["show_images_in_posts"] = true;
  }
  
  if (!isset($randomimage_options["show_images_in_pages"])) {
    $randomimage_options["show_images_in_pages"] = false;
  }

  if (!isset($randomimage_options["show_images_in_galleries"])) {
    $randomimage_options["show_images_in_galleries"] = true;
  }
  
  if (!isset($randomimage_options["number_of_images"])) {
    $randomimage_options["number_of_images"] = 1;
  }
  
  if (!isset($randomimage_options["image_attributes"])) {
    $randomimage_options["image_attributes"] = "";
  }
  
  if (!isset($randomimage_options["inter_image_html"])) {
    $randomimage_options["inter_image_html"] = "&lt;br /&gt;&lt;br /&gt;";
  }
  
  if (!isset($randomimage_options["image_src_regex"])) {
    $randomimage_options["image_src_regex"] = "";
  }

  if (!isset($randomimage_options["category_filter"])) {
    $randomimage_options["category_filter"] = array();
  }

  if (!isset($randomimage_options["sort_images_randomly"])) {
    $randomimage_options["sort_images_randomly"] = true;
  }

  if (!isset($randomimage_options["image_class_match"])) {
    $randomimage_options["image_class_match"] = "";
  } 

  add_option('randomimage_options', $randomimage_options);
  return $randomimage_options;
}


// generate configuration page
function randomimage_configuration_page()
{
  $randomimage_options = get_randomimage_options();
  
  // if form has been submitted, save values
  if (isset($_POST['submit'])) {
    // booleanize all the checkboxes
    isset($_POST['show_images_in_posts'])     ? $_POST['show_images_in_posts']     = true : $_POST['show_images_in_posts']     = false;
    isset($_POST['show_images_in_pages'])     ? $_POST['show_images_in_pages']     = true : $_POST['show_images_in_pages']     = false;
    isset($_POST['show_images_in_galleries']) ? $_POST['show_images_in_galleries'] = true : $_POST['show_images_in_galleries'] = false;
    isset($_POST['sort_images_randomly'])     ? $_POST['sort_images_randomly']     = true : $_POST['sort_images_randomly']     = false;
    
    // correct for empty image number
    if ($_POST['number_of_images'] &lt; 1) {
      $_POST['number_of_images'] = 1;
    }

    // correct for posts and pages and galleries being deselected
    if (!$_POST['show_images_in_posts'] &amp;&amp; !$_POST['show_images_in_pages']) {
      $_POST['show_images_in_posts'] = true;
    }

    if (!is_array($_POST['category_filter'])) {
      $_POST['category_filter'] = array();
    }

    if (trim($_POST['image_template_html']) == '') {
      $_POST['image_template_html'] = "\n&lt;strong&gt;%1&lt;/strong&gt;&lt;br /&gt;\n%2&lt;br /&gt;\n&lt;em&gt;%3&lt;/em&gt;\n";
    }

    // create array of new options
    $randomimage_options = array(
        "show_images_in_posts"     =&gt; $_POST['show_images_in_posts'],
        "show_images_in_pages"     =&gt; $_POST['show_images_in_pages'],
        "show_images_in_galleries" =&gt; $_POST['show_images_in_galleries'],
        "number_of_images"         =&gt; $_POST['number_of_images'],
        "image_attributes"         =&gt; stripslashes($_POST['image_attributes']),
        "inter_image_html"         =&gt; stripslashes($_POST['inter_image_html']),
        "image_src_regex"          =&gt; stripslashes($_POST['image_src_regex']),
        "category_filter"          =&gt; $_POST['category_filter'],
        "sort_images_randomly"     =&gt; $_POST['sort_images_randomly'],
        "image_class_match"        =&gt; stripslashes(trim($_POST['image_class_match'])),
        "image_template_html"      =&gt; stripslashes($_POST['image_template_html'])
    );
    update_option('randomimage_options', $randomimage_options);
  }

?&gt;

&lt;div class="wrap"&gt;
&lt;h2&gt;Random Image Settings&lt;/h2&gt;

&lt;form method="post" action=""&gt;

&lt;p&gt;&lt;strong&gt;Instructions:&lt;/strong&gt; Use the following options to configure how you want the plugin to behave. The Sample Output at the bottom of the page will reflect the changes you've made. When you're satisfied, goto &lt;a href="widgets.php"&gt;Design &gt; Widgets&lt;/a&gt; and add "Random Image" to your sidebar (if your theme is widget-enabled). Otherwise you can manually edit your index.php or sidebar.php template files and add &lt;code style="font-weight:bold;"&gt;&amp;lt?php randomimage(); ?&amp;gt&lt;/code&gt; where you want the random image to appear.

&lt;div style="clear: both;padding-top:10px;"&gt;
&lt;label style="float:left;width:250px;text-align:right;padding-right:6px;" for="show_images_in_posts"&gt;Include images from posts?&lt;/label&gt;
&lt;div style="float:left;"&gt;&lt;input type="checkbox" id="show_images_in_posts" name="show_images_in_posts" &lt;?php if ($randomimage_options["show_images_in_posts"]) print "checked='on'"; ?&gt;/&gt;&amp;nbsp;&amp;nbsp;&lt;label for="show_images_in_pages"&gt;Pages?&lt;/label&gt; &lt;input type="checkbox" id="show_images_in_pages" name="show_images_in_pages" &lt;?php if ($randomimage_options["show_images_in_pages"]) print "checked='on'"; ?&gt;/&gt;&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div style="clear: both;padding-top:10px;"&gt;
&lt;label style="float:left;width:250px;text-align:right;padding-right:6px;" for="show_images_in_galleries"&gt;Include images from galleries?&lt;/label&gt; 
&lt;div style="float:left;"&gt;&lt;input type="checkbox" id="show_images_in_galleries" name="show_images_in_galleries" &lt;?php if ($randomimage_options["show_images_in_galleries"]) print "checked='on'"; ?&gt;/&gt;&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div style="clear: both;padding-top:10px;"&gt;
&lt;label style="float:left;width:250px;text-align:right;padding-right:6px;" for="sort_images_randomly"&gt;Sort Images Randomly?&lt;/label&gt;
&lt;div style="float:left;"&gt;&lt;input type="checkbox" id="sort_images_randomly" name="sort_images_randomly" &lt;?php if ($randomimage_options["sort_images_randomly"]) print "checked='on'"; ?&gt;/&gt; Uncheck if you want to show recent images rather than random images&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div style="clear: both;padding-top:10px;"&gt;
&lt;label style="float:left;width:250px;text-align:right;padding-right:6px;padding-top:7px;" for="number_of_images"&gt;How many images to display?&lt;/label&gt;
&lt;div style="float:left;"&gt;&lt;input type="text" id="number_of_images" name="number_of_images" size="1" maxlength="2" &lt;?php if ($randomimage_options["number_of_images"]) print "value='" . $randomimage_options["number_of_images"] . "'"; ?&gt;/&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div style="clear: both;padding-top:10px;"&gt;
&lt;label style="float:left;width:250px;text-align:right;padding-right:6px;padding-top:7px;" for="image_template_html"&gt;HTML Template:&lt;br/&gt;&lt;code&gt;%1&lt;/code&gt; = title&lt;br /&gt;&lt;code&gt;%2&lt;/code&gt; = image&lt;br /&gt;&lt;code&gt;%3&lt;/code&gt; = caption&lt;br /&gt;&lt;code&gt;%4&lt;/code&gt; = excerpt&lt;/label&gt;
&lt;div style="float:left;"&gt;&lt;textarea id="image_template_html" name="image_template_html" rows="4" cols="24" style="float:left;"&gt;&lt;?php if ($randomimage_options["image_template_html"]) print stripslashes(htmlspecialchars($randomimage_options["image_template_html"])); ?&gt;&lt;/textarea&gt;
e.g. &lt;code style="font-weight:bold;"&gt;&amp;lt;strong&amp;gt;%1&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;%2&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;em&amp;gt;%3&amp;lt;/em&amp;gt;&lt;code&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div style="clear: both;padding-top:10px;"&gt;
&lt;label style="float:left;width:250px;text-align:right;padding-right:6px;padding-top:7px;" for="inter_image_html"&gt;HTML between images:&lt;/label&gt;
&lt;div style="float:left;"&gt;&lt;input type="text" id="inter_image_html" name="inter_image_html" size="12" &lt;?php if (isset($randomimage_options["inter_image_html"])) print "value='" . stripslashes(htmlspecialchars($randomimage_options["inter_image_html"], ENT_QUOTES)) . "'"; ?&gt;/&gt;  e.g. &lt;code style="font-weight:bold;"&gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div style="clear: both;padding-top:10px;"&gt;
&lt;label style="float:left;width:250px;text-align:right;padding-right:6px;padding-top:7px;" for="image_attributes"&gt;Optional attributes for &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tags:&lt;/label&gt;
&lt;div style="float:left;"&gt;&lt;input type="text" id="image_attributes" name="image_attributes"  style="width:200px;" &lt;?php if ($randomimage_options["image_attributes"]) print "value='" . stripslashes(htmlspecialchars($randomimage_options["image_attributes"], ENT_QUOTES)) . "'"; ?&gt;/&gt; e.g. &lt;code style="font-weight:bold;"&gt;style="width:200px;"&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div style="clear: both;padding-top:10px;"&gt;
&lt;label style="float:left;width:250px;text-align:right;padding-right:6px;padding-top:7px;"&gt;Limit by categories/tags:&lt;br /&gt;(leave unchecked for all)&lt;/label&gt;
&lt;div style="float:left;"&gt;

&lt;div style='overflow:auto;height:6em;width:200px;background-color:#efefef;border:1px solid #b2b2b2;padding:2px 0 0 3px;'&gt;
&lt;?php
    
    
  // create WordPress-style category multi-select list
  global $wpdb, $wp_version;

  if ($wp_version &gt;= '2.3') {
    $categories = $wpdb-&gt;get_results("SELECT $wpdb-&gt;terms.term_id as cat_ID, $wpdb-&gt;terms.name as cat_name
                                      FROM $wpdb-&gt;terms LEFT JOIN $wpdb-&gt;term_taxonomy on $wpdb-&gt;terms.term_id = $wpdb-&gt;term_taxonomy.term_id
                                      WHERE $wpdb-&gt;term_taxonomy.taxonomy IN ('post_tag', 'category')
                                      ORDER BY $wpdb-&gt;terms.name");
  } else  { 
    $categories = $wpdb-&gt;get_results("SELECT cat_ID, cat_name
                                      FROM $wpdb-&gt;categories
                                      ORDER BY cat_name");
  }

  foreach ($categories as $category) {
    print "&lt;label style='display:block;' for='category-$category-&gt;cat_ID'&gt;&lt;input type='checkbox' value='$category-&gt;cat_ID' name='category_filter[]' id='category-$category-&gt;cat_ID'" . (in_array( $category-&gt;cat_ID, $randomimage_options["category_filter"] ) ? ' checked="checked"' : "") . " /&gt;" .  wp_specialchars($category-&gt;cat_name) . "&lt;/label&gt;\n";
  }
?&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;/div&gt;

&lt;div style="clear: both;padding-top:10px;"&gt;
&lt;label style="float:left;width:250px;text-align:right;padding-right:6px;padding-top:7px;" for="image_class_match"&gt;String to match in the &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; &lt;code&gt;class&lt;/code&gt;:&lt;/label&gt;
&lt;div style="float:left;"&gt;&lt;input type="text" id="image_class_match" name="image_class_match" style="width:200px;" &lt;?php if ($randomimage_options["image_class_match"]) print "value='" . stripslashes(htmlspecialchars($randomimage_options["image_class_match"], ENT_QUOTES)) . "'"; ?&gt;/&gt; e.g. &lt;code style="font-weight:bold;"&gt;randomimage&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;div style="clear: both;padding-top:10px;"&gt;
&lt;label style="float:left;width:250px;text-align:right;padding-right:6px;padding-top:7px;" for="image_src_regex"&gt;Regex to match against the &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; &lt;code&gt;src&lt;/code&gt;:&lt;/label&gt;
&lt;div style="float:left;"&gt;&lt;input type="text" id="image_src_regex" name="image_src_regex" style="width:200px;" &lt;?php if ($randomimage_options["image_src_regex"]) print "value='" . stripslashes(htmlspecialchars($randomimage_options["image_src_regex"], ENT_QUOTES)) . "'"; ?&gt;/&gt; e.g. &lt;code style="font-weight:bold;"&gt;images&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div style="clear: both;padding-top:10px;text-align:center;"&gt;
&lt;p class="submit"&gt;&lt;input type="submit" name="submit" value="Update Options &amp;raquo;" /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;


&lt;div class="wrap"&gt;
&lt;h2&gt;Sample Output&lt;/h2&gt;
&lt;?php randomimage(); ?&gt;
&lt;/div&gt;




&lt;?php
}



function randomimage($show_post_title          = true, 
                     $number_of_images         = 1, 
                     $image_attributes         = "", 
                     $show_alt_caption         = true, 
                     $image_src_regex          = "",
                     $post_type                = "posts",
                     $inter_image_html         = "&lt;br /&gt;&lt;br /&gt;",
                     $category_filter          = "",
                     $sort_images_randomly     = true,
                     $image_class_match        = "",
                     $image_template_html      = "",
                     $show_images_in_galleries = true)
{
  // get access to wordpress' database object
  global $wpdb, $wp_version;
  $debugging = false;

  if ($debugging) print "&lt;strong&gt;Random Image Debugging is On!&lt;/strong&gt;&lt;br/&gt;";

  // if no arguments are specified
  // assume we're going with the configuration options
  if (!func_get_args()) {
    if ($debugging) print "Configuration options (specified via admin interface):&lt;br /&gt;";

    $randomimage_options = get_randomimage_options();

    $number_of_images         = $randomimage_options['number_of_images'];        
    $image_attributes         = $randomimage_options['image_attributes'];        
    $image_src_regex          = $randomimage_options['image_src_regex'];        
    $inter_image_html         = $randomimage_options['inter_image_html'];
    $sort_images_randomly     = $randomimage_options['sort_images_randomly'];
    $image_class_match        = $randomimage_options['image_class_match'];
    $image_template_html      = $randomimage_options['image_template_html'];
    $show_images_in_galleries = $randomimage_options['show_images_in_galleries'];

    // convert category filter array into a comma-separated list
    if (!is_array($randomimage_options['category_filter'])) {
      $randomimage_options['category_filter'] = array();
    }
    $category_filter  = implode(",", $randomimage_options['category_filter']);
    
    // galleries really only exist in posts
    if ($show_images_in_posts == true &amp;&amp; $show_images_in_pages == false) {
      $post_type = "posts";
    
    } elseif ($show_images_in_posts == false &amp;&amp; $show_images_in_pages == true) {
      $post_type = "pages";

    } else {
      $post_type = "both";
    }

  } else {
    if ($debugging) print "Configuration options (specified via function parameters):&lt;br /&gt;";
    
    // if config options were specified via a function call, but no template was supplied,
    // build a template from the show_post_title and show_alt_caption options.
    if ($image_template_html == '') {
      if ($show_post_title) {
        $image_template_html .= "\n&lt;strong&gt;%1&lt;/strong&gt;&lt;br /&gt;\n";
      }

      $image_template_html .= "%2";

      if ($show_alt_caption) {
        $image_template_html .= "&lt;br /&gt;\n&lt;em&gt;%3&lt;/em&gt;\n";
      }
    }
  }
  
  if ($debugging) {
    print "show_post_title: "      . htmlspecialchars($show_post_title)      . "&lt;br/&gt;";     
    print "number_of_images: "     . htmlspecialchars($number_of_images)     . "&lt;br/&gt;";    
    print "image_attributes: "     . htmlspecialchars($image_attributes)     . "&lt;br/&gt;";    
    print "show_alt_caption: "     . htmlspecialchars($show_alt_caption)     . "&lt;br/&gt;";    
    print "image_src_regex:  "     . htmlspecialchars($image_src_regex)      . "&lt;br/&gt;";     
    print "post_type: "            . htmlspecialchars($post_type)            . "&lt;br/&gt;";           
    print "inter_image_html: "     . htmlspecialchars($inter_image_html)     . "&lt;br/&gt;";    
    print "category_filter: "      . htmlspecialchars($category_filter)      . "&lt;br/&gt;";     
    print "sort_images_randomly: " . htmlspecialchars($sort_images_randomly) . "&lt;br/&gt;&lt;br/&gt;";
  }

  // select the post_type sql for both post pages (post_status = 'static') 
  // and posts (AND post_status = 'publish')
  // or for just pages or for just posts (the default)
  // by adding this where criteria, we also solve the problem
  // of accidentally including images from draft posts.
  if ($wp_version &lt; '2.1') {
    if ($post_type == "both") {
      $post_type_sql = "AND (post_status = 'publish' OR post_status = 'static')";
    } else if ($post_type == "pages") {
      $post_type_sql = "AND post_status = 'static'";
    } else {
      $post_type_sql = "AND post_status = 'publish'";
    }

  } else {
    if ($post_type == 'both') {
      $post_type_sql = "AND post_status = 'publish' AND post_type in ('post', 'page')";
    } elseif ($post_type == 'pages') {
      $post_type_sql = "AND post_status = 'publish' AND post_type = 'page'";
    } else {
      $post_type_sql = "AND post_status = 'publish' AND post_type = 'post'";
    }
  }

  // assuming $category_filter is a comma separated list of category ids,
  // modify query to join with post2cat table to select from only the chosen categories
  $category_filter_join  = "";
  $category_filter_sql   = "";
  $category_filter_group = "";
  if ($category_filter != "") {
    if ($wp_version &gt;= '2.3') {
      $category_filter_join  = "LEFT JOIN $wpdb-&gt;term_relationships ON $wpdb-&gt;posts.ID = $wpdb-&gt;term_relationships.object_id LEFT JOIN $wpdb-&gt;term_taxonomy ON $wpdb-&gt;term_relationships.term_taxonomy_id = $wpdb-&gt;term_taxonomy.term_taxonomy_id";
      $category_filter_sql   = "AND $wpdb-&gt;term_taxonomy.term_id IN ($category_filter)";   
      $category_filter_group = "GROUP BY $wpdb-&gt;posts.ID";

    } else {
      $category_filter_join  = "LEFT JOIN $wpdb-&gt;post2cat ON $wpdb-&gt;posts.ID = $wpdb-&gt;post2cat.post_id";
      $category_filter_sql   = "AND $wpdb-&gt;post2cat.category_id IN ($category_filter)";   
      $category_filter_group = "GROUP BY $wpdb-&gt;posts.ID";
    }
  }
  
  // by default we sort images randomly,
  // but we can also sort them in descending date order
  if ($sort_images_randomly) {
    $order_by_sql = "rand()";
  } else {
    $order_by_sql = "$wpdb-&gt;posts.post_date DESC";
  }

  // query records that contain img tags, ordered randomly
  // do not select images from password protected posts
  $sql = "SELECT $wpdb-&gt;posts.ID, $wpdb-&gt;posts.post_title, $wpdb-&gt;posts.post_content, $wpdb-&gt;posts.post_excerpt
          FROM $wpdb-&gt;posts
          $category_filter_join
          WHERE (post_content LIKE '%&lt;img%' or post_content LIKE '%[gallery]%')
          AND post_password = ''
          $post_type_sql
          $category_filter_sql
          $category_filter_group
          ORDER BY $order_by_sql";
  $resultset = @mysql_query($sql, $wpdb-&gt;dbh);
  
  if ($debugging &amp;&amp; mysql_error($wpdb-&gt;dbh)) print "mysql errors: " . mysql_error($wpdb-&gt;dbh) . "&lt;br/&gt; SQL: " . htmlspecialchars($sql) . "&lt;br/&gt;";;
  if ($debugging) print "elligible post count: " . @mysql_num_rows($resultset) . "&lt;br/&gt;"; 
  
  // keep track of multiple images to prevent displaying dups
  $image_srcs = array();

  // loop through each applicable post from the database
  $image_count = 0;
  while ($row = mysql_fetch_array($resultset)) {
    $post_title     = $row['post_title'];
    $post_permalink = get_permalink($row['ID']);
    $post_content   = $row['post_content'];
    $post_excerpt   = $row['post_excerpt'];
    $matches = array();

    // find all img tags
    preg_match_all("/&lt;img[^&gt;]+&gt;/i", $post_content, $matches);
    
    if ($show_images_in_galleries) {
      // find any gallery attachments
      if (strpos($post_content, '[gallery]') !== false) {
        $sql = "SELECT $wpdb-&gt;posts.guid, $wpdb-&gt;posts.post_excerpt
                FROM $wpdb-&gt;posts
                WHERE post_parent = '" . $row['ID'] . "'
                AND post_type = 'attachment'
                AND post_password = ''
                AND post_mime_type in ('image/jpeg', 'image/gif', 'image/png')";
        $resultset2 = @mysql_query($sql, $wpdb-&gt;dbh);
        while ($row2 = mysql_fetch_array($resultset2)) {
          $matches[0][] = "&lt;img src='" . $row2['guid'] . "' alt='" . htmlspecialchars($row2['post_excerpt'], ENT_QUOTES) .  "' /&gt;";
        }
      }
    }

    // if there are none, try again,  
    if (count($matches[0]) == 0) {
      continue;
    }

    // randomize the array of images in this post
    shuffle($matches[0]);

    // loop through each image candidate for this post and try to find a winner        
    foreach ($matches[0] as $image_element) {
      // grab the src attribute and see if it exists, if not try again
      preg_match("/src\s*=\s*(\"|')(.*?)\\1/i", $image_element, $image_src);
      $image_src = $image_src[2];
      
      // Modifica rapporto larghezza/altezza immagini
	list($width, $height, $type, $attr)= getimagesize($image_src);
	if ($width / $height != "1.5") {
        continue;
      }

      // make sure we haven't displayed this image before
      if ($image_src == "" || in_array($image_src, $image_srcs)) {
        continue;
      }

      // if a regex is supplied and it doesn't match, try next post
      if ($image_src_regex != "" &amp;&amp; !preg_match("/" . $image_src_regex . "/i", $image_src)) {
        continue;
      }

      if ($image_class_match != "") {
        // grab the class attribute and see if it exists, if not try again
        preg_match("/class\s*=\s*(\"|')(.*?)\\1/i", $image_element, $image_classes);
        $image_classes = $image_classes[2];

        if ($image_classes == '') {
          continue;
        }

        $image_classes = explode(" ", $image_classes);
        if (!in_array($image_class_match, $image_classes)) {
          continue;
        }
      }

      // add img src to array to check for dups
      $image_srcs[] = $image_src;
         
      // grab the alt attribute and see if it exists, if not supply default
      preg_match("/alt\s*=\s*(\"|')(.*?)\\1/i", $image_element, $image_alt);
      $image_alt = $image_alt[2];

      if ($image_alt == "") {
        $image_alt = "random image";
      }

      $image_html = $image_template_html;
      $image_html = str_replace("%1", $post_title, $image_html);
      $image_html = str_replace("%2", "&lt;a href='$post_permalink'&gt;&lt;img class='imm-random' src='$image_src' alt='$image_alt' $image_attributes /&gt;&lt;/a&gt;", $image_html);
      
      if ($image_alt == 'random image') {
        $image_html = str_replace("%3", '', $image_html);
      } else {
        $image_html = str_replace("%3", $image_alt, $image_html);
      }

      $image_html = str_replace("%4", $post_excerpt, $image_html);

      print $image_html;

      $image_count++;
      
      if ($image_count == $number_of_images) {
        return;
      } else {
        // print a linebreak between each successive image
        print "$inter_image_html\n";
      }
      
      // leave the foreach loop and look for images
      // in other posts
      // TODO: if people wanted to display multiple images per post,
      // we would selectively skip this break
      break;
    }
  }
}
?&gt;
</code></pre>
]]></description><link>https://dev.connect.gt/topic/164258/ridurre-dimensioni-immagini-mostrate-da-plugin</link><generator>RSS for Node</generator><lastBuildDate>Mon, 30 Nov 2026 17:01:58 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/164258.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 12 Jan 2012 16:29:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ridurre dimensioni immagini mostrate da plugin on Mon, 16 Jan 2012 18:24:32 GMT]]></title><description><![CDATA[<p dir="auto">Funziona, non ti dico i posti dove ho guardato per cercare di sistemarlo... e pensare che avevo la soluzione davanti al naso. Grazie per l'aiuto! <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f609.png?v=2190ae3dadd" class="not-responsive emoji emoji-android emoji--wink" style="height:1.4em;width:auto;vertical-align:middle" title=";)" alt="😉" /></p>
]]></description><link>https://dev.connect.gt/post/1047858</link><guid isPermaLink="true">https://dev.connect.gt/post/1047858</guid><dc:creator><![CDATA[darkf3d3]]></dc:creator><pubDate>Mon, 16 Jan 2012 18:24:32 GMT</pubDate></item><item><title><![CDATA[Reply to Ridurre dimensioni immagini mostrate da plugin on Mon, 16 Jan 2012 15:15:14 GMT]]></title><description><![CDATA[<p dir="auto">prova così</p>
<pre><code class="language-php">&lt;a href='$post_permalink'&gt;&lt;img class='imm-random' src='http://www.dottorgadget.it/wp-content/themes/Avenue/timthumb.php?src=$image_src&amp;h=91&amp;w=91&amp;zc=1' alt='the_title()' /&gt;&lt;/a&gt;
</code></pre>
]]></description><link>https://dev.connect.gt/post/1047857</link><guid isPermaLink="true">https://dev.connect.gt/post/1047857</guid><dc:creator><![CDATA[elmanisero]]></dc:creator><pubDate>Mon, 16 Jan 2012 15:15:14 GMT</pubDate></item><item><title><![CDATA[Reply to Ridurre dimensioni immagini mostrate da plugin on Mon, 16 Jan 2012 14:27:26 GMT]]></title><description><![CDATA[<p dir="auto">Rispondo a questa discussione perché lo script sopraindicato ha risolto il problema del ridimensionamento, però ne ha creato un'altro.<br />
Le immagini del widget che devo ridimensionare vengono ridimensionate e visualizzate correttamente nella home, mentre in tutte le altre pagine danno errore.</p>
<p dir="auto">Questo è il codice che uso nel plugin:</p>
<pre><code class="language-php">&lt;a href='$post_permalink'&gt;&lt;img class='imm-random' src='wp-content/themes/Avenue/timthumb.php?src=$image_src&amp;h=91&amp;w=91&amp;zc=1' alt='the_title()' /&gt;&lt;/a&gt;
</code></pre>
<p dir="auto">Potete vedere l'errore andando nella home e spostandovi alla seconda pagina con i bottoni che ci sono in basso.</p>
]]></description><link>https://dev.connect.gt/post/1047856</link><guid isPermaLink="true">https://dev.connect.gt/post/1047856</guid><dc:creator><![CDATA[darkf3d3]]></dc:creator><pubDate>Mon, 16 Jan 2012 14:27:26 GMT</pubDate></item><item><title><![CDATA[Reply to Ridurre dimensioni immagini mostrate da plugin on Sun, 15 Jan 2012 16:48:34 GMT]]></title><description><![CDATA[<p dir="auto">Grazie DARKF3D3 <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f609.png?v=2190ae3dadd" class="not-responsive emoji emoji-android emoji--wink" style="height:1.4em;width:auto;vertical-align:middle" title=";)" alt="😉" /></p>
]]></description><link>https://dev.connect.gt/post/1047853</link><guid isPermaLink="true">https://dev.connect.gt/post/1047853</guid><dc:creator><![CDATA[katherine]]></dc:creator><pubDate>Sun, 15 Jan 2012 16:48:34 GMT</pubDate></item><item><title><![CDATA[Reply to Ridurre dimensioni immagini mostrate da plugin on Sun, 15 Jan 2012 14:06:48 GMT]]></title><description><![CDATA[<p dir="auto">Sono riuscito a risolvere utilizzando questo script:<br />
www . wprecipes . com / how-to-resize-images-on-the-fly</p>
]]></description><link>https://dev.connect.gt/post/1047854</link><guid isPermaLink="true">https://dev.connect.gt/post/1047854</guid><dc:creator><![CDATA[darkf3d3]]></dc:creator><pubDate>Sun, 15 Jan 2012 14:06:48 GMT</pubDate></item></channel></rss>