$h = !empty($_GET['height']) ? intval($_GET['height']) : 0; // limit the maxium size, prevent server memory overload if ($w > 1280) { $w = 1280; } if ($h > 1280) { $h = 1280; } $thumb->resize($w, $h); } // Apply effects according to the mode parameter if ($mode == 'watermark') { if ($ngg_options['wmType'] == 'image') { $thumb->watermarkImgPath = $ngg_options['wmPath']; $thumb->watermarkImage($ngg_options['wmPos'], $ngg_options['wmXpos'], $ngg_options['wmYpos']); } else { if ($ngg_options['wmType'] == 'text') { $thumb->watermarkText = $ngg_options['wmText']; $thumb->watermarkCreateText($ngg_options['wmColor'], $ngg_options['wmFont'], $ngg_options['wmSize'], $ngg_options['wmOpaque']); $thumb->watermarkImage($ngg_options['wmPos'], $ngg_options['wmXpos'], $ngg_options['wmYpos']); } } } else { if ($mode == 'web20') { $thumb->createReflection(40, 40, 50, false, '#a4a4a4'); } } // Show thumbnail $thumb->show(); $thumb->destruct(); exit;
/** * This function creates a cache for all singlepics to reduce the CPU load * * @param int $width * @param int $height * @param string $mode could be watermark | web20 | crop * @return the url for the image or false if failed */ function cached_singlepic_file($width = '', $height = '', $mode = '') { $ngg_options = get_option('ngg_options'); include_once nggGallery::graphic_library(); // cache filename should be unique $cachename = $this->pid . '_' . $mode . '_' . $width . 'x' . $height . '_' . $this->filename; $cachefolder = WINABSPATH . $ngg_options['gallerypath'] . 'cache/'; $cached_url = site_url() . '/' . $ngg_options['gallerypath'] . 'cache/' . $cachename; $cached_file = $cachefolder . $cachename; // check first for the file if (file_exists($cached_file)) { return $cached_url; } // create folder if needed if (!file_exists($cachefolder)) { if (!wp_mkdir_p($cachefolder)) { return false; } } $thumb = new ngg_Thumbnail($this->imagePath, TRUE); // echo $thumb->errmsg; if (!$thumb->error) { if ($mode == 'crop') { // calculates the new dimentions for a downsampled image list($ratio_w, $ratio_h) = wp_constrain_dimensions($thumb->currentDimensions['width'], $thumb->currentDimensions['height'], $width, $height); // check ratio to decide which side should be resized $ratio_h < $height || $ratio_w == $width ? $thumb->resize(0, $height) : $thumb->resize($width, 0); // get the best start postion to crop from the middle $ypos = ($thumb->currentDimensions['height'] - $height) / 2; $thumb->crop(0, $ypos, $width, $height); } else { $thumb->resize($width, $height); } if ($mode == 'watermark') { if ($ngg_options['wmType'] == 'image') { $thumb->watermarkImgPath = $ngg_options['wmPath']; $thumb->watermarkImage($ngg_options['wmPos'], $ngg_options['wmXpos'], $ngg_options['wmYpos']); } if ($ngg_options['wmType'] == 'text') { $thumb->watermarkText = $ngg_options['wmText']; $thumb->watermarkCreateText($ngg_options['wmColor'], $ngg_options['wmFont'], $ngg_options['wmSize'], $ngg_options['wmOpaque']); $thumb->watermarkImage($ngg_options['wmPos'], $ngg_options['wmXpos'], $ngg_options['wmYpos']); } } if ($mode == 'web20') { $thumb->createReflection(40, 40, 50, false, '#a4a4a4'); } // save the new cache picture $thumb->save($cached_file, $ngg_options['imgQuality']); } $thumb->destruct(); // check again for the file if (file_exists($cached_file)) { return $cached_url; } return false; }
function cached_singlepic_file($width = '', $height = '', $mode = '') { // This function creates a cache for all singlepics to reduce the CPU load $ngg_options = get_option('ngg_options'); include_once nggGallery::graphic_library(); // cache filename should be unique $cachename = $this->pid . '_' . $mode . '_' . $width . 'x' . $height . '_' . $this->filename; $cachefolder = WINABSPATH . $ngg_options['gallerypath'] . 'cache/'; $cached_url = get_option('siteurl') . '/' . $ngg_options['gallerypath'] . 'cache/' . $cachename; $cached_file = $cachefolder . $cachename; // check first for the file if (file_exists($cached_file)) { return $cached_url; } // create folder if needed if (!file_exists($cachefolder)) { if (!wp_mkdir_p($cachefolder)) { return false; } } $thumb = new ngg_Thumbnail($this->imagePath, TRUE); // echo $thumb->errmsg; if (!$thumb->error) { $thumb->resize($width, $height); if ($mode == 'watermark') { if ($ngg_options['wmType'] == 'image') { $thumb->watermarkImgPath = $ngg_options['wmPath']; $thumb->watermarkImage($ngg_options['wmPos'], $ngg_options['wmXpos'], $ngg_options['wmYpos']); } if ($ngg_options['wmType'] == 'text') { $thumb->watermarkText = $ngg_options['wmText']; $thumb->watermarkCreateText($ngg_options['wmColor'], $ngg_options['wmFont'], $ngg_options['wmSize'], $ngg_options['wmOpaque']); $thumb->watermarkImage($ngg_options['wmPos'], $ngg_options['wmXpos'], $ngg_options['wmYpos']); } } if ($mode == 'web20') { $thumb->createReflection(40, 40, 50, false, '#a4a4a4'); } // save the new cache picture $thumb->save($cached_file, $ngg_options['imgQuality']); } $thumb->destruct(); // check again for the file if (file_exists($cached_file)) { return $cached_url; } return false; }