bol by som Vam velmi povdacny, keby ste mi niekto pomohol upravit ten druhy kod tak, aby som si mohol urcit height a weight - z toho width si urcim v px a height v percentach. aktualne sa tam da urcit width a height v PX. 1. kod ma v sebe tu funkciu..
Kód: Vybrať všetko
<?php
$gCF_abspath = dirname(__FILE__);
require_once($gCF_abspath_1 .'wp-config.php');
$rigwfz_dir = get_option('rigwfz_dir');
$max_height = 1000;
$image = $gCF_abspath_1 . $rigwfz_dir . $_GET["IMGNAME"];
$max_width = $_GET["MAXWIDTH"];
if($max_width > 500)
{
$max_width = 500;
}
if (strrchr($image, '/')) {
$filename = substr(strrchr($image, '/'), 1); // remove folder references
} else {
$filename = $image;
}
$size = getimagesize($image);
$width = $size[0];
$height = $size[1];
// get the ratio needed
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
// if image already meets criteria, load current values in
// if not, use ratios to load new size info
if (($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
} else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
} else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
/* Caching additions by Trent Davies */
// first check cache
// cache must be world-readable
$resized = 'cache/'.$tn_width.'x'.$tn_height.'-'.$filename;
$imageModified = @filemtime($image);
$thumbModified = @filemtime($resized);
header("Content-type: image/jpeg");
// if thumbnail is newer than image then output cached thumbnail and exit
if($imageModified<$thumbModified) {
header("Last-Modified: ".gmdate("D, d M Y H:i:s",$thumbModified)." GMT");
readfile($resized);
exit;
}
// read image
$ext = substr(strrchr($image, '.'), 1); // get the file extension
switch ($ext) {
case 'jpg': // jpg
$src = imagecreatefromjpeg($image) or notfound();
break;
case 'png': // png
$src = imagecreatefrompng($image) or notfound();
break;
case 'gif': // gif
$src = imagecreatefromgif($image) or notfound();
break;
case 'JPG': // jpg
$src = imagecreatefromjpeg($image) or notfound();
break;
case 'PNG': // png
$src = imagecreatefrompng($image) or notfound();
break;
case 'GIF': // gif
$src = imagecreatefromgif($image) or notfound();
break;
default:
notfound();
}
// set up canvas
$dst = imagecreatetruecolor($tn_width,$tn_height);
imageantialias ($dst, true);
// copy resized image to new canvas
imagecopyresampled ($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
/* Sharpening adddition by Mike Harding */
// sharpen the image (only available in PHP5.1)
if (function_exists("imageconvolution")) {
$matrix = array( array( -1, -1, -1 ),
array( -1, 32, -1 ),
array( -1, -1, -1 ) );
$divisor = 24;
$offset = 0;
imageconvolution($dst, $matrix, $divisor, $offset);
}
// send the header and new image
imagejpeg($dst, null, -1);
imagejpeg($dst, $resized, -1); // write the thumbnail to cache as well...
// clear out the resources
imagedestroy($src);
imagedestroy($dst);
?>
Kód: Vybrať všetko
<?php
add_action('widgets_init', create_function('', 'return register_widget("NextGEN_Gallery_Sidebar_Widget");'));
class NextGEN_Gallery_Sidebar_Widget extends WP_Widget
{
protected $_templates = array();
function NextGEN_Gallery_Sidebar_Widget()
{
$widget_ops = array('classname' => 'ngg-sidebar-widget', 'description' => 'A widget to show random galleries with preview image.');
$this->WP_Widget('ngg-sidebar-widget', 'NextGEN Gallery Sidebar Widget', $widget_ops);
}
function widget($args, $instance)
{
global $wpdb;
extract($args);
$title = apply_filters('widget_title', $instance['title']);
switch($instance['gallery_order']) {
case 'added_desc':
$order = 'gid DESC';
break;
case 'added_asc':
$order = 'gid ASC';
break;
default:
$order = 'RAND()';
break;
}
$included_galleries = $this->explode_ids($instance['included_galleries']);
$excluded_galleries = $this->explode_ids($instance['excluded_galleries']);
$where = ' ';
if(count($included_galleries) > 0) {
$include = array();
foreach($included_galleries as $included_gallery) {
if(!in_array($included_gallery, $excluded_galleries)) {
$include[] = $included_gallery;
}
}
$where = " WHERE gid IN (" . implode(',', $include) . ")";
} else if(count($excluded_galleries) > 0) {
$where = " WHERE gid NOT IN (" . implode(',', $excluded_galleries) . ")";
}
$results = $wpdb->get_results("SELECT * FROM $wpdb->nggallery" . $where . " ORDER BY " . $order . " LIMIT 0, " . $instance['max_galleries']);
if(is_array($results) && count($results) > 0) {
$galleries = array();
foreach($results as $result) {
if($wpdb->get_var("SELECT COUNT(pid) FROM $wpdb->nggpictures WHERE galleryid = '" . $result->gid . "'") > 0) {
if($instance['gallery_thumbnail'] == 'preview' && (int)$result->previewpic > 0) {
// ok
} elseif($instance['gallery_thumbnail'] == 'random') {
$result->previewpic = $wpdb->get_var("SELECT pid FROM $wpdb->nggpictures WHERE galleryid = '" . $result->gid . "' ORDER BY RAND() LIMIT 1");
} else {
// else take the first image
$result->previewpic = $wpdb->get_var("SELECT pid FROM $wpdb->nggpictures WHERE galleryid = '" . $result->gid . "' ORDER BY sortorder ASC, pid ASC LIMIT 1");
}
$galleries[] = $result;
}
}
if(count($galleries) > 0) {
$outerTplFile = get_template_directory() . '/ngg-sidebar-widget/tpl.outer.html';
$innerTplFile = get_template_directory() . '/ngg-sidebar-widget/tpl.inner.html';
$outerTplFile = (file_exists($outerTplFile)) ? $outerTplFile : dirname(__FILE__) . '/tpl/tpl.outer.html';
$innerTplFile = (file_exists($innerTplFile)) ? $innerTplFile : dirname(__FILE__) . '/tpl/tpl.inner.html';
$outerTpl = file_get_contents($outerTplFile);
$innerTpl = file_get_contents($innerTplFile);
if(empty($outerTpl)) {
$outerTpl = '{=inner}';
}
$this->parseTemplate('innerTpl', $innerTpl);
$output = "\n";
$output .= $args['before_widget'] . "\n";
$output .= $args['before_title'] . $title . $args['after_title'] . "\n";
$innerOutput = '';
foreach($galleries as $gallery) {
$imagerow = $wpdb->get_row("SELECT * FROM $wpdb->nggpictures WHERE pid = '" . $gallery->previewpic . "'");
foreach($gallery as $key => $value) {
$imagerow->$key = $value;
}
$image = new nggImage($imagerow);
$tpl = array(
'gallery' => (array) $gallery,
'image' => (array) $image
);
if($gallery->pageid > 0) {
$gallery_link = get_permalink($gallery->pageid);
} elseif(!empty($instance['default_link'])) {
$gallery_link = get_permalink($instance['default_link']);
} else {
$gallery_link = get_permalink(1);
}
$tpl['gallery']['link'] = $gallery_link;
if(function_exists('getphpthumburl') && trim($instance['autothumb_params']) != '') {
$tpl['image']['url'] = getphpthumburl($image->imageURL, $instance['autothumb_params']);
} else {
$tpl['image']['url'] = $image->thumbURL;
}
$tpl['image']['output_width'] = $instance['output_width'];
$tpl['image']['output_height'] = $instance['output_height'];
if(trim($instance['autothumb_params']) != '') {
$tpl['image']['output_width_tag'] = '';
$tpl['image']['output_height_tag'] = '';
} else {
$tpl['image']['output_width_tag'] = ' width="' . $instance['output_width'] . '"';
$tpl['image']['output_height_tag'] = ' height="' . $instance['output_height'] . '"';
}
$innerOutput .= $this->renderTemplate('innerTpl', $tpl);
}
$output .= str_replace('{=inner}', $innerOutput, $outerTpl);
$output .= "\n" . $args['after_widget'] . "\n";
echo $output;
}
}
}
function explode_ids($string, $separator = ',')
{
$ret = array();
$exploded = explode($separator, $string);
foreach($exploded as $ex) {
$ex = trim($ex);
if(is_numeric($ex)) {
$ret[] = $ex;
}
}
return $ret;
}
function renderTemplate($id, $values)
{
$output = '';
if(isset($this->_templates[$id])) {
$output = $this->_templates[$id]['template'];
foreach($this->_templates[$id]['tags'] as $identifier => $val) {
if(isset($values[$val[0]][$val[1]])) {
$output = str_replace('{=' . $identifier . '}', $values[$val[0]][$val[1]], $output);
}
}
}
return $output;
}
function parseTemplate($id, $template)
{
$tags = array();
$pattern = '#\{\=([a-zA-Z0-9\-\_\.]*)\.([a-zA-Z0-9\-\_\.]*)\}#';
preg_match_all($pattern, $template, $matches);
if(is_array($matches) && count($matches) > 0) {
foreach($matches[0] as $key => $value) {
$identifier = $matches[1][$key] . '.' . $matches[2][$key];
$tags[$identifier][0] = $matches[1][$key];
$tags[$identifier][1] = $matches[2][$key];
}
}
$this->_templates[$id]['template'] = $template;
$this->_templates[$id]['tags'] = $tags;
}
function form($instance)
{
$instance = wp_parse_args((array) $instance, array(
'title' => 'Galleries',
'max_galleries' => 6,
'gallery_order' => 'random',
'gallery_thumbnail' => 'first',
'autothumb_params' => '',
'output_width' => 100,
'output_height' => 75,
'default_link' => 1,
'included_galleries' => '',
'excluded_galleries' => ''
));
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">Widget Title</label><br />
<input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title'] ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('max_galleries'); ?>">Maximum Galleries</label><br />
<input type="text" id="<?php echo $this->get_field_id('max_galleries'); ?>" name="<?php echo $this->get_field_name('max_galleries'); ?>" value="<?php echo $instance['max_galleries'] ?>" />
<p>
<label for="<?php echo $this->get_field_id('gallery_order'); ?>">Gallery Order</label><br />
<select id="<?php echo $this->get_field_name('gallery_order'); ?>" name="<?php echo $this->get_field_name('gallery_order'); ?>">';
<option value="random" <?php echo ($instance['gallery_order'] == 'random') ? ' selected="selected"' : ''; ?>>Random</option>
<option value="added_asc" <?php echo ($instance['gallery_order'] == 'added_asc') ? ' selected="selected"' : ''; ?>>Date added ASC</option>
<option value="added_desc" <?php echo ($instance['gallery_order'] == 'added_desc') ? ' selected="selected"' : ''; ?>>Date added DESC</option>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('gallery_thumbnail'); ?>">Gallery thumbnail image</label><br />
<select id="<?php echo $this->get_field_name('gallery_thumbnail'); ?>" name="<?php echo $this->get_field_name('gallery_thumbnail'); ?>">';
<option value="preview" <?php echo ($instance['gallery_thumbnail'] == 'preview') ? ' selected="selected"' : ''; ?>>Gallery Preview (set in NGG)</option>
<option value="first" <?php echo ($instance['gallery_thumbnail'] == 'first') ? ' selected="selected"' : ''; ?>>First</option>
<option value="random" <?php echo ($instance['gallery_thumbnail'] == 'random') ? ' selected="selected"' : ''; ?>>Random</option>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('autothumb_params'); ?>">Autothumb Parameters (if installed)</label><br />
<input type="text" id="<?php echo $this->get_field_id('autothumb_params'); ?>" name="<?php echo $this->get_field_name('autothumb_params'); ?>" value="<?php echo $instance['autothumb_params'] ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('output_width'); ?>">Output width</label><br />
<input type="text" id="<?php echo $this->get_field_id('output_width'); ?>" name="<?php echo $this->get_field_name('output_width'); ?>" value="<?php echo $instance['output_width'] ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('output_height'); ?>">Output height</label><br />
<input type="text" id="<?php echo $this->get_field_id('output_height'); ?>" name="<?php echo $this->get_field_name('output_height'); ?>" value="<?php echo $instance['output_height'] ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('default_link'); ?>">Default Link Id (galleries without image page)</label><br />
<input type="text" id="<?php echo $this->get_field_id('default_link'); ?>" name="<?php echo $this->get_field_name('default_link'); ?>" value="<?php echo $instance['default_link'] ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('included_galleries'); ?>">Included gallery IDs (comma separated)</label><br />
<input type="text" id="<?php echo $this->get_field_id('included_galleries'); ?>" name="<?php echo $this->get_field_name('included_galleries'); ?>" value="<?php echo $instance['included_galleries'] ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('excluded_galleries'); ?>">Excluded gallery IDs (comma separated)</label><br />
<input type="text" id="<?php echo $this->get_field_id('excluded_galleries'); ?>" name="<?php echo $this->get_field_name('excluded_galleries'); ?>" value="<?php echo $instance['excluded_galleries'] ?>" />
</p>
<?php
}
function update($new_instance, $old_instance)
{
$new_instance['title'] = htmlspecialchars($new_instance['title']);
return $new_instance;
}
}