コード例 #1
0
ファイル: resize.php プロジェクト: lorea/Hydra-dev
/**
 * Create thumbnails using ImageMagick executables
 *
 * @param ElggFile holds the image that was uploaded
 * @param string   folder to store thumbnail in
 * @param string   name of the thumbnail
 * @return bool    TRUE on success
 */
function tp_create_im_cmdline_thumbnails($file, $prefix, $filestorename)
{
    $image_sizes = elgg_get_plugin_setting('image_sizes', 'tidypics');
    if (!$image_sizes) {
        register_error(elgg_echo('tidypics:nosettings'));
        return FALSE;
    }
    $image_sizes = unserialize($image_sizes);
    $thumb = new ElggFile();
    $thumb->owner_guid = $file->owner_guid;
    $thumb->container_guid = $file->container_guid;
    // tiny thumbnail
    $thumb->setFilename($prefix . "thumb" . $filestorename);
    $thumbname = $thumb->getFilenameOnFilestore();
    if (empty($image_sizes['tiny_image_width'])) {
        // sites upgraded from 1.6 may not have this set
        $image_sizes['tiny_image_width'] = $image_sizes['tiny_image_height'] = 60;
    }
    $rtn_code = tp_im_cmdline_resize($file->getFilenameOnFilestore(), $thumbname, $image_sizes['tiny_image_width'], $image_sizes['tiny_image_height'], TRUE);
    if (!$rtn_code) {
        return FALSE;
    }
    $file->thumbnail = $prefix . "thumb" . $filestorename;
    // album thumbnail
    $thumb->setFilename($prefix . "smallthumb" . $filestorename);
    $thumbname = $thumb->getFilenameOnFilestore();
    $rtn_code = tp_im_cmdline_resize($file->getFilenameOnFilestore(), $thumbname, $image_sizes['small_image_width'], $image_sizes['small_image_height'], TRUE);
    if (!$rtn_code) {
        return FALSE;
    }
    $file->smallthumb = $prefix . "smallthumb" . $filestorename;
    // main image
    $thumb->setFilename($prefix . "largethumb" . $filestorename);
    $thumbname = $thumb->getFilenameOnFilestore();
    $rtn_code = tp_im_cmdline_resize($file->getFilenameOnFilestore(), $thumbname, $image_sizes['large_image_width'], $image_sizes['large_image_height'], FALSE);
    if (!$rtn_code) {
        return FALSE;
    }
    $file->largethumb = $prefix . "largethumb" . $filestorename;
    tp_im_cmdline_watermark($thumbname);
    unset($thumb);
    return TRUE;
}
コード例 #2
0
ファイル: resize.php プロジェクト: iionly/tidypics
/**
 * Create thumbnails using ImageMagick executables
 *
 * @param ElggFile holds the image that was uploaded
 * @param string   folder to store thumbnail in
 * @param string   name of the thumbnail
 * @return bool    TRUE on success
 */
function tp_create_im_cmdline_thumbnails($file, $prefix, $filestorename)
{
    $image_sizes = elgg_get_plugin_setting('image_sizes', 'tidypics');
    if (!$image_sizes) {
        register_error(elgg_echo('tidypics:nosettings'));
        return false;
    }
    $image_sizes = unserialize($image_sizes);
    // check if all necessary config variables are set and fall back to default if not
    $image_sizes['tiny_image_width'] = isset($image_sizes['tiny_image_width']) ? $image_sizes['tiny_image_width'] : 60;
    $image_sizes['tiny_image_height'] = isset($image_sizes['tiny_image_height']) ? $image_sizes['tiny_image_height'] : 60;
    $image_sizes['tiny_image_square'] = isset($image_sizes['tiny_image_square']) ? $image_sizes['tiny_image_square'] : true;
    $image_sizes['small_image_width'] = isset($image_sizes['small_image_width']) ? $image_sizes['small_image_width'] : 153;
    $image_sizes['small_image_height'] = isset($image_sizes['small_image_height']) ? $image_sizes['small_image_height'] : 153;
    $image_sizes['small_image_square'] = isset($image_sizes['small_image_square']) ? $image_sizes['small_image_square'] : true;
    $image_sizes['large_image_width'] = isset($image_sizes['large_image_width']) ? $image_sizes['large_image_width'] : 600;
    $image_sizes['large_image_height'] = isset($image_sizes['large_image_height']) ? $image_sizes['large_image_height'] : 600;
    $image_sizes['large_image_square'] = isset($image_sizes['large_image_square']) ? $image_sizes['large_image_square'] : false;
    $thumb = new ElggFile();
    $thumb->owner_guid = $file->owner_guid;
    $thumb->container_guid = $file->container_guid;
    // tiny thumbnail
    $thumb->setFilename($prefix . "thumb" . $filestorename);
    $thumbname = $thumb->getFilenameOnFilestore();
    $rtn_code = tp_im_cmdline_resize($file->getFilenameOnFilestore(), $thumbname, $image_sizes['tiny_image_width'], $image_sizes['tiny_image_height'], $image_sizes['tiny_image_square']);
    if (!$rtn_code) {
        return false;
    }
    $file->thumbnail = $prefix . "thumb" . $filestorename;
    // album thumbnail
    $thumb->setFilename($prefix . "smallthumb" . $filestorename);
    $thumbname = $thumb->getFilenameOnFilestore();
    $rtn_code = tp_im_cmdline_resize($file->getFilenameOnFilestore(), $thumbname, $image_sizes['small_image_width'], $image_sizes['small_image_height'], $image_sizes['small_image_square']);
    if (!$rtn_code) {
        return false;
    }
    $file->smallthumb = $prefix . "smallthumb" . $filestorename;
    // main image
    $thumb->setFilename($prefix . "largethumb" . $filestorename);
    $thumbname = $thumb->getFilenameOnFilestore();
    $rtn_code = tp_im_cmdline_resize($file->getFilenameOnFilestore(), $thumbname, $image_sizes['large_image_width'], $image_sizes['large_image_height'], $image_sizes['large_image_square']);
    if (!$rtn_code) {
        return false;
    }
    $file->largethumb = $prefix . "largethumb" . $filestorename;
    tp_im_cmdline_watermark($thumbname);
    unset($thumb);
    return true;
}