/** * This function will do the actual work of creating a thumbnail image. * * @param $width The maximum width of the thumbnail. * @param $height The maximum height of the thumbnail. * @param $cache (optional) Indicate if the thumbnails should be cached. By default, caching is turned off. * * @internal */ function &_createThumbnail($width, $height, $cache = true) { // Check if the GD library is loaded. if (!extension_loaded('gd')) { $this->_error('YD_gd_not_installed'); } // Include phpThumb require_once 'phpThumb/phpthumb.class.php'; // Create a new thumbnail object $thumb = new phpThumb(); $thumb->src = $this->getAbsolutePath(); // Set the options for the creation of thumbnails $thumb->config_nohotlink_enabled = false; $thumb->config_cache_directory = YD_DIR_TEMP; // Set the width and the height $thumb->w = $width; $thumb->h = $height; // Create the cached thumbnail $cacheFName = $thumb->GenerateCachedFilename(); $cacheFName .= $this->getLastModified(); $cacheFName .= $this->getAbsolutePath(); $cacheFName = YD_TMP_PRE . 'N_' . md5($cacheFName) . '.tmn'; $cacheFName = YD_DIR_TEMP . '/' . $cacheFName; // Check if caching is enabled if ($cache == true) { // Output the cached version if any if (is_file($cacheFName)) { $img = new YDFSImage($cacheFName); header('Content-type: ' . $img->getMimeType()); echo $img->getContents(); die; } } // Width should be positive integer if ($width < 1) { $this->_error(); } // Height should be positive integer if ($width < 1) { $this->_error(); } // Generate the thumbnail $thumb->GenerateThumbnail(); // Check if caching is enabled if ($cache == true) { $thumb->RenderToFile($cacheFName); } // Return the thumbnail object return $thumb; }
/** * If sending an HTML message with embedded images, use this function * to add the image. * * @param $file The image file path. * @param $c_type (optional) The content type of the image or file. * @param $name (optional) The filename of the image. */ function addHTMLImage($file, $c_type = '', $name = '') { if (!YDObjectUtil::isSubClass($file, 'YDFSImage')) { $file = new YDFSImage($file); } $data = $file->getContents(); if (empty($name)) { $name = $file->getBaseName(); } if (empty($c_type)) { $c_type = $file->getMimeType(); } $this->_msg->addHTMLImage($data, $name, $c_type); }
/** * This function is used to output an error image. * * @param $name (optional) Name of the error image. Default image that is shown is the generic * "YD_ydfsimage_fatal_error". * * @internal */ function _error($name = 'YD_ydfsimage_fatal_error') { $img = new YDFSImage(YD_DIR_HOME . '/images/' . $name . '.gif'); header('Content-type: ' . $img->getMimeType()); echo $img->getContents(); die; }