• Hi,

    I needed an option to control the size of the image included by the zenphotopress shortcode. I added a size option for both the shortcode and the widget. Below is the patch:

    diff -Naur zenphotopress_orig//classes.php zenphotopress/classes.php
    --- zenphotopress_orig//classes.php	2012-01-19 14:43:20.000000000 -0800
    +++ zenphotopress/classes.php	2012-02-17 13:25:15.865419877 -0800
    @@ -75,7 +75,7 @@
     	 * @param $classes Additional classes for CSS
     	 * @param $postid ID of the post containing the badge (if any)
     	 */
    -	function getBadge($sort, $number, $albumid = 0, $classes = '', $post_id='') {
    +	function getBadge($sort, $number, $albumid = 0, $classes = '', $post_id='', $size = -1, $show_title = false) {
     	    global $zp_admin_dir;
    
     		$rel_value = get_option('zenphotopress_rel_value', '');
    @@ -97,19 +97,20 @@
     		$images = ZenphotoProxy::getImages($sort, $number, $albumid);
    
     		$out .= '<dl class="' . $class_string . '">';
    +		$thumb_size = ($size>0?$size:"thumb");
     		foreach ($images as $image) {
     			if ($mod_rewrite) {
     				$imgpath = get_option('zenphotopress_web_path') ."/" . ZenphotoPressHelpers::pathurlencode($image[album_url]) . "/" . urlencode($image[url]);
    -				$thumbpath = get_option('zenphotopress_web_path') . "/" . ZenphotoPressHelpers::pathurlencode($image[album_url]) . "/image/thumb/" . urlencode($image[url]);
    +				$thumbpath = get_option('zenphotopress_web_path') . "/" . ZenphotoPressHelpers::pathurlencode($image[album_url]) . "/image/$thumb_size/" . urlencode($image[url]);
     			} else {
     				$imgpath = get_option('zenphotopress_web_path') ."/index.php?album=" . ZenphotoPressHelpers::pathurlencode($image[album_url]) . "&image=" . urlencode($image[url]);
    -				$thumbpath = get_option('zenphotopress_web_path') . "/" . $zp_admin_dir . "/i.php?a=" . ZenphotoPressHelpers::pathurlencode($image[album_url]) . "&i=" . urlencode($image[url]) . "&s=thumb";
    +				$thumbpath = get_option('zenphotopress_web_path') . "/" . $zp_admin_dir . "/i.php?a=" . ZenphotoPressHelpers::pathurlencode($image[album_url]) . "&i=" . urlencode($image[url]) . "&s=$thumb_size";
     			}
     			// TEMPORARILY IGNORE mod_rewrite FOR IMAGE PATH TO BE COMPATIBLE WITH ZENPHOTO 1.4
    -			$thumbpath = get_option('zenphotopress_web_path') . "/" . $zp_admin_dir . "/i.php?a=" . ZenphotoPressHelpers::pathurlencode($image[album_url]) . "&i=" . urlencode($image[url]) . "&s=thumb";
    -			if ($image[thumbX] && $image[thumbY] && $image[thumbW] && $image[thumbH]) {
    -                // Custom thumb cropping
    -                $thumbpath = get_option('zenphotopress_web_path') . "/" . $zp_admin_dir . "/i.php?a=" . ZenphotoPressHelpers::pathurlencode($image[album_url]) . "&i=" . urlencode($image[url]);
    +                        $thumbpath = get_option('zenphotopress_web_path') . "/" . $zp_admin_dir . "/i.php?a=" . ZenphotoPressHelpers::pathurlencode($image[album_url]) . "&i=" . urlencode($image[url]) . "&s=$thumb_size";
    +			if ($image[thumbX] && $image[thumbY] && $image[thumbW] && $image[thumbH] && $size==-1) {
    +                            // Custom thumb cropping
    +                            $thumbpath = get_option('zenphotopress_web_path') . "/" . $zp_admin_dir . "/i.php?a=" . ZenphotoPressHelpers::pathurlencode($image[album_url]) . "&i=" . urlencode($image[url]);
    
     			    $thumbpath .= "&w=".$thumb_size;
     			    $thumbpath .= "&cx=".$image[thumbX];
    @@ -126,7 +127,9 @@
     				$thumbpath = get_option('zenphotopress_web_path') . "/" . $zp_admin_dir . "/i.php?a=.&i=" . urlencode($image[default_thumb]) . "&s=thumb";
     			}
    
    -			$out .= '<dt><a href="'.$imgpath.'" '.$rel_attribute.'><img title="'.$image[name].'" alt="'.$image[name].'" src="'.$thumbpath.'" /></a></dt>';
    +			$out .= '<dt><a href="'.$imgpath.'" '.$rel_attribute.'><img title="'.$image[name].'" alt="'.$image[name].'" src="'.$thumbpath.'" /></a>'.
    +                                ($show_title?'<h4 class="badge_title">'.$image[name].'</h4>':'').
    +                            '</dt>';
     		}
     		$out .= '<hr /></dl>';
    
    @@ -142,8 +145,8 @@
     	 * @param $albumid ID of the album to show (0 for all albums)
     	 * @param $classes Additional classes for CSS
     	 */
    -	function printBadge($sort, $number, $albumid = 0, $classes = '', $post_id='') {
    -		echo ZenphotoPressUI::getBadge($sort, $number, $albumid, $classes, $post_id);
    +	function printBadge($sort, $number, $albumid = 0, $classes = '', $post_id='', $size = -1) {
    +		echo ZenphotoPressUI::getBadge($sort, $number, $albumid, $classes, $post_id, $size);
     	}
     }
    
    diff -Naur zenphotopress_orig//zenphotopress.php zenphotopress/zenphotopress.php
    --- zenphotopress_orig//zenphotopress.php	2012-01-19 14:43:20.000000000 -0800
    +++ zenphotopress/zenphotopress.php	2012-02-17 13:30:37.427014422 -0800
    @@ -140,9 +140,11 @@
     			'sort' => 'random',
     			'number' => 3,
     			'album' => 0,
    +                        'size' => -1,
    +                        'show_title' => 1,
     		), $atts));
    
    -		return ZenphotoPressUI::getBadge($sort, $number, $album, 'ZenphotoPress_shortcode', $id);
    +		return ZenphotoPressUI::getBadge($sort, $number, $album, 'ZenphotoPress_shortcode', $id, $size, $show_title);
     	}
    
     	function add_shortcodes() {
    @@ -165,10 +167,11 @@
     		$sort = empty($instance['sort']) ? 'random' : $instance['sort'];
     		$number = empty($instance['number']) ? 5 : $instance['number'];
     		$albumid = empty($instance['albumid']) ? 0 : $instance['albumid'];
    +                $size = empty($instance['size']) ? -1 : $instance['size'];
    
     		echo $before_widget;
     		echo $before_title . $title . $after_title;
    -		ZenphotoPressUI::printBadge($sort, $number, $albumid, 'ZenphotoPress_widget', $id);
    +		ZenphotoPressUI::printBadge($sort, $number, $albumid, 'ZenphotoPress_widget', $id, $size);
     		echo $after_widget;
     	}
    
    @@ -183,6 +186,7 @@
     		$sort = esc_attr( $instance['sort'] );
     		$number = esc_attr( $instance['number'] );
     		$albumid = esc_attr( $instance['albumid'] );
    +                $size = esc_attr( $instance['size'] );
    
     		$albums = ZenphotoProxy::getAlbums();
    
    @@ -217,6 +221,12 @@
     					</select>
     				</label>
     			</p>
    +                        <p>
    +                                <label for="<?php echo $this->get_field_id('size'); ?>">
    +                                        <?php _e('Image size:'); ?>
    +                                        <input id="<?php echo $this->get_field_id('size'); ?>" name="<?php echo $this->get_field_name('size'); ?>" type="text" value="<?php echo $size; ?>" />
    +                                </label>
    +                        </p>
     		<?php
     	}
     }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The size of the images comes from Zenphoto’s configuration options, so it is possible to change it from there. I guess you wanted to keep them independent, though, which makes sense.

    Good to know someone is making the most out of the opensource nature of the plugin. Nice work!

    Thread Starter mariusmuja

    (@mariusmuja)

    Yes, I needed different size images in different places (a 600px image using the shortcode and thumbnail images using the widget).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: ZenphotoPress] Option for image size (patch included)’ is closed to new replies.