function create_thumbnail($source, $new_file, $mimetype)
{
    global $attach_config, $imagick;
    $source = amod_realpath($source);
    $min_filesize = intval($attach_config['img_min_thumb_filesize']);
    $img_filesize = @file_exists(@amod_realpath($source)) ? filesize($source) : false;
    if (!$img_filesize || $img_filesize <= $min_filesize) {
        return FALSE;
    }
    $size = image_getdimension($source);
    if ($size[0] == 0 && $size[1] == 0) {
        return FALSE;
    }
    $new_size = get_img_size_format($size[0], $size[1]);
    $tmp_path = '';
    $old_file = '';
    if (intval($attach_config['allow_ftp_upload'])) {
        $old_file = $new_file;
        $tmp_path = explode('/', $source);
        $tmp_path[count($tmp_path) - 1] = '';
        $tmp_path = implode('/', $tmp_path);
        if ($tmp_path == '') {
            $tmp_path = '/tmp';
        }
        $value = trim($tmp_path);
        if ($value[strlen($value) - 1] == '/') {
            $value[strlen($value) - 1] = ' ';
        }
        $new_file = trim($value) . '/t00000';
    }
    $used_imagick = FALSE;
    if (is_imagick()) {
        if (is_array($size) && count($size) > 0) {
            passthru($imagick . ' -quality 85 -antialias -sample ' . $new_size[0] . 'x' . $new_size[1] . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $new_file) . '"');
            if (@file_exists(@amod_realpath($new_file))) {
                $used_imagick = TRUE;
            }
        }
    }
    if (!$used_imagick) {
        $type = $size[2];
        $supported_types = get_supported_image_types();
        if (in_array($type, $supported_types)) {
            switch ($type) {
                case '1':
                    $im = imagecreatefromgif($source);
                    $new_im = imagecreate($new_size[0], $new_size[1]);
                    imagecopyresized($new_im, $im, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);
                    imagegif($new_im, $new_file);
                    break;
                case '2':
                    $im = imagecreatefromjpeg($source);
                    $new_im = intval($attach_config['use_gd2']) ? @imagecreatetruecolor($new_size[0], $new_size[1]) : imagecreate($new_size[0], $new_size[1]);
                    imagecopyresized($new_im, $im, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);
                    imagejpeg($new_im, $new_file, 90);
                    break;
                case '3':
                    $im = imagecreatefrompng($source);
                    $new_im = intval($attach_config['use_gd2']) ? @imagecreatetruecolor($new_size[0], $new_size[1]) : imagecreate($new_size[0], $new_size[1]);
                    imagecopyresized($new_im, $im, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);
                    imagepng($new_im, $new_file);
                    break;
            }
        }
    }
    if (!@file_exists(@amod_realpath($new_file))) {
        return FALSE;
    }
    if (intval($attach_config['allow_ftp_upload'])) {
        $result = ftp_file($new_file, $old_file, $this->type, TRUE);
        // True for disable error-mode
        if (!$result) {
            return FALSE;
        }
    } else {
        @chmod($new_file, 0664);
    }
    return TRUE;
}
示例#2
0
/**
* Create Thumbnail
*/
function create_thumbnail($source, $destination, $mimetype)
{
    global $config, $phpbb_filesystem;
    $min_filesize = (int) $config['img_min_thumb_filesize'];
    $img_filesize = file_exists($source) ? @filesize($source) : false;
    if (!$img_filesize || $img_filesize <= $min_filesize) {
        return false;
    }
    $dimension = @getimagesize($source);
    if ($dimension === false) {
        return false;
    }
    list($width, $height, $type, ) = $dimension;
    if (empty($width) || empty($height)) {
        return false;
    }
    list($new_width, $new_height) = get_img_size_format($width, $height);
    // Do not create a thumbnail if the resulting width/height is bigger than the original one
    if ($new_width >= $width && $new_height >= $height) {
        return false;
    }
    $used_imagick = false;
    // Only use imagemagick if defined and the passthru function not disabled
    if ($config['img_imagick'] && function_exists('passthru')) {
        if (substr($config['img_imagick'], -1) !== '/') {
            $config['img_imagick'] .= '/';
        }
        @passthru(escapeshellcmd($config['img_imagick']) . 'convert' . (defined('PHP_OS') && preg_match('#^win#i', PHP_OS) ? '.exe' : '') . ' -quality 85 -geometry ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" "' . str_replace('\\', '/', $destination) . '"');
        if (file_exists($destination)) {
            $used_imagick = true;
        }
    }
    if (!$used_imagick) {
        $type = get_supported_image_types($type);
        if ($type['gd']) {
            // If the type is not supported, we are not able to create a thumbnail
            if ($type['format'] === false) {
                return false;
            }
            switch ($type['format']) {
                case IMG_GIF:
                    $image = @imagecreatefromgif($source);
                    break;
                case IMG_JPG:
                    @ini_set('gd.jpeg_ignore_warning', 1);
                    $image = @imagecreatefromjpeg($source);
                    break;
                case IMG_PNG:
                    $image = @imagecreatefrompng($source);
                    break;
                case IMG_WBMP:
                    $image = @imagecreatefromwbmp($source);
                    break;
            }
            if (empty($image)) {
                return false;
            }
            if ($type['version'] == 1) {
                $new_image = imagecreate($new_width, $new_height);
                if ($new_image === false) {
                    return false;
                }
                imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            } else {
                $new_image = imagecreatetruecolor($new_width, $new_height);
                if ($new_image === false) {
                    return false;
                }
                // Preserve alpha transparency (png for example)
                @imagealphablending($new_image, false);
                @imagesavealpha($new_image, true);
                imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            }
            // If we are in safe mode create the destination file prior to using the gd functions to circumvent a PHP bug
            if (@ini_get('safe_mode') || @strtolower(ini_get('safe_mode')) == 'on') {
                @touch($destination);
            }
            switch ($type['format']) {
                case IMG_GIF:
                    imagegif($new_image, $destination);
                    break;
                case IMG_JPG:
                    imagejpeg($new_image, $destination, 90);
                    break;
                case IMG_PNG:
                    imagepng($new_image, $destination);
                    break;
                case IMG_WBMP:
                    imagewbmp($new_image, $destination);
                    break;
            }
            imagedestroy($new_image);
        } else {
            return false;
        }
    }
    if (!file_exists($destination)) {
        return false;
    }
    try {
        $phpbb_filesystem->phpbb_chmod($destination, CHMOD_READ | CHMOD_WRITE);
    } catch (\phpbb\filesystem\exception\filesystem_exception $e) {
        // Do nothing
    }
    return true;
}
function create_thumbnail($source, $destination, $mimetype)
{
    global $config;
    $min_filesize = (int) $config['img_min_thumb_filesize'];
    $img_filesize = file_exists($source) ? @filesize($source) : false;
    if (!$img_filesize || $img_filesize <= $min_filesize) {
        return false;
    }
    list($width, $height, $type, ) = getimagesize($source);
    if (!$width || !$height) {
        return false;
    }
    list($new_width, $new_height) = get_img_size_format($width, $height);
    if ($width < $new_width && $height < $new_height) {
        return false;
    }
    $used_imagick = false;
    if (file_exists($destination)) {
        passthru($config['img_imagick'] . 'convert' . (defined('PHP_OS') && preg_match('#win#i', PHP_OS) ? '.exe' : '') . ' -quality 85 -antialias -sample ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $destination) . '"');
        if (file_exists($new_file)) {
            $used_imagick = true;
        }
    }
    if (!$used_imagick) {
        $type = get_supported_image_types($type);
        if ($type['gd']) {
            switch ($type['format']) {
                case IMG_GIF:
                    $image = imagecreatefromgif($source);
                    break;
                case IMG_JPG:
                    $image = imagecreatefromjpeg($source);
                    break;
                case IMG_PNG:
                    $image = imagecreatefrompng($source);
                    break;
                case IMG_WBMP:
                    $image = imagecreatefromwbmp($source);
                    break;
            }
            if ($type['version'] == 1) {
                $new_image = imagecreate($new_width, $new_height);
                imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            } else {
                $new_image = imagecreatetruecolor($new_width, $new_height);
                imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            }
            switch ($type['format']) {
                case IMG_GIF:
                    imagegif($new_image, $destination);
                    break;
                case IMG_JPG:
                    imagejpeg($new_image, $destination, 90);
                    break;
                case IMG_PNG:
                    imagepng($new_image, $destination);
                    break;
                case IMG_WBMP:
                    imagewbmp($new_image, $destination);
                    break;
            }
            imagedestroy($new_image);
        }
    }
    if (!file_exists($destination)) {
        return false;
    }
    @chmod($destination, 0666);
    return true;
}
示例#4
0
/**
* Create thumbnail
*/
function create_thumbnail($source, $new_file, $mimetype)
{
    global $attach_config, $imagick;
    $source = amod_realpath($source);
    $min_filesize = (int) $attach_config['img_min_thumb_filesize'];
    $img_filesize = @file_exists($source) ? @filesize($source) : false;
    if (!$img_filesize || $img_filesize <= $min_filesize) {
        return false;
    }
    list($width, $height, $type, ) = getimagesize($source);
    if (!$width || !$height) {
        return false;
    }
    list($new_width, $new_height) = get_img_size_format($width, $height);
    $tmp_path = $old_file = '';
    if (intval($attach_config['allow_ftp_upload'])) {
        $old_file = $new_file;
        $tmp_path = explode('/', $source);
        $tmp_path[count($tmp_path) - 1] = '';
        $tmp_path = implode('/', $tmp_path);
        if ($tmp_path == '') {
            $tmp_path = '/tmp';
        }
        $value = trim($tmp_path);
        if ($value[strlen($value) - 1] == '/') {
            $value[strlen($value) - 1] = ' ';
        }
        //
        $new_file = tempnam(trim($value), 't00000');
        // We remove it now because it gets created again later
        @unlink($new_file);
    }
    $used_imagick = false;
    if (is_imagick()) {
        passthru($imagick . ' -quality 85 -antialias -sample ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $new_file) . '"');
        if (@file_exists($new_file)) {
            $used_imagick = true;
        }
    }
    if (!$used_imagick) {
        $type = get_supported_image_types($type);
        if ($type['gd']) {
            switch ($type['format']) {
                case IMG_GIF:
                    $image = imagecreatefromgif($source);
                    break;
                case IMG_JPG:
                    $image = imagecreatefromjpeg($source);
                    break;
                case IMG_PNG:
                    $image = imagecreatefrompng($source);
                    break;
                case IMG_WBMP:
                    $image = imagecreatefromwbmp($source);
                    break;
            }
            if ($type['version'] == 1 || !$attach_config['use_gd2']) {
                $new_image = imagecreate($new_width, $new_height);
                imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            } else {
                $new_image = imagecreatetruecolor($new_width, $new_height);
                imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            }
            switch ($type['format']) {
                case IMG_GIF:
                    imagegif($new_image, $new_file);
                    break;
                case IMG_JPG:
                    imagejpeg($new_image, $new_file, 90);
                    break;
                case IMG_PNG:
                    imagepng($new_image, $new_file);
                    break;
                case IMG_WBMP:
                    imagewbmp($new_image, $new_file);
                    break;
            }
            imagedestroy($new_image);
        }
    }
    if (!@file_exists($new_file)) {
        return false;
    }
    if (intval($attach_config['allow_ftp_upload'])) {
        $result = ftp_file($new_file, $old_file, $mimetype, true);
        // True for disable error-mode
        @unlink($new_file);
        if (!$result) {
            return false;
        }
    } else {
        @chmod($new_file, 0664);
    }
    return true;
}
示例#5
0
/**
* Create thumbnail
*/
function create_thumbnail($source, $new_file, $mimetype)
{
    global $attach_config, $imagick;
    $source = amod_realpath($source);
    $min_filesize = (int) $attach_config['img_min_thumb_filesize'];
    $img_filesize = @file_exists($source) ? @filesize($source) : false;
    if (!$img_filesize || $img_filesize <= $min_filesize) {
        return false;
    }
    list($width, $height, $type, ) = getimagesize($source);
    if (!$width || !$height) {
        return false;
    }
    list($new_width, $new_height) = get_img_size_format($width, $height);
    $tmp_path = $old_file = '';
    $used_imagick = false;
    if (is_imagick()) {
        passthru($imagick . ' -quality 85 -antialias -sample ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $new_file) . '"');
        if (@file_exists($new_file)) {
            $used_imagick = true;
        }
    }
    if (!$used_imagick) {
        $type = get_supported_image_types($type);
        if ($type['gd']) {
            switch ($type['format']) {
                case IMG_GIF:
                    $image = imagecreatefromgif($source);
                    break;
                case IMG_JPG:
                    $image = imagecreatefromjpeg($source);
                    break;
                case IMG_PNG:
                    $image = imagecreatefrompng($source);
                    break;
                case IMG_WBMP:
                    $image = imagecreatefromwbmp($source);
                    break;
            }
            if ($type['version'] == 1 || !$attach_config['use_gd2']) {
                $new_image = imagecreate($new_width, $new_height);
                imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            } else {
                $new_image = imagecreatetruecolor($new_width, $new_height);
                imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            }
            switch ($type['format']) {
                case IMG_GIF:
                    imagegif($new_image, $new_file);
                    break;
                case IMG_JPG:
                    imagejpeg($new_image, $new_file, 90);
                    break;
                case IMG_PNG:
                    imagepng($new_image, $new_file);
                    break;
                case IMG_WBMP:
                    imagewbmp($new_image, $new_file);
                    break;
            }
            imagedestroy($new_image);
        }
    }
    if (!@file_exists($new_file)) {
        return false;
    }
    @chmod($new_file, 0664);
    return true;
}
示例#6
0
function create_thumbnail($source, $new_file)
{
    global $attach_config;
    $source = amod_realpath($source);
    $min_filesize = intval($attach_config['img_min_thumb_filesize']);
    $img_filesize = file_exists(amod_realpath($source)) ? filesize($source) : false;
    if (!$img_filesize || $img_filesize <= $min_filesize) {
        return FALSE;
    }
    $size = image_getdimension($source);
    if ($size[0] <= 0 && $size[1] <= 0) {
        return FALSE;
    }
    $new_size = get_img_size_format($size[0], $size[1]);
    $tmp_path = '';
    $old_file = '';
    if (intval($attach_config['allow_ftp_upload'])) {
        $old_file = $new_file;
        $tmp_path = explode('/', $source);
        $tmp_path[count($tmp_path) - 1] = '';
        $tmp_path = implode('/', $tmp_path);
        if ($tmp_path == '') {
            $tmp_path = '/tmp';
        }
        $value = trim($tmp_path);
        if ($value[strlen($value) - 1] == '/') {
            $value[strlen($value) - 1] = ' ';
        }
        $new_file = trim($value) . '/t00000';
    }
    global $MAIN_CFG;
    if (!isset($MAIN_CFG['imaging']['type'])) {
        //$attach_config['use_gd2']
        $MAIN_CFG['imaging']['type'] = empty($attach_config['img_imagick']) ? 'gd2' : 'im';
        $MAIN_CFG['imaging']['impath'] = $attach_config['img_imagick'];
        $MAIN_CFG['imaging']['pbmpath'] = $attach_config['img_imagick'];
    }
    require_once 'includes/imaging/imaging.inc';
    Graphic::resize($source, $new_size, $new_file, $size);
    if (!file_exists(amod_realpath($new_file))) {
        return FALSE;
    }
    if (intval($attach_config['allow_ftp_upload'])) {
        $result = ftp_file($new_file, $old_file, $this->type, TRUE);
        // True for disable error-mode
        if (!$result) {
            return FALSE;
        }
    } else {
        chmod($new_file, PHP_AS_NOBODY ? 0666 : 0644);
    }
    return TRUE;
}
function create_thumbnail($source, $destination, $mimetype) 
{
	global $config;

	$min_filesize = (int) $config['img_min_thumb_filesize'];
	$img_filesize = (file_exists($source)) ? @filesize($source) : false;

	$dimension = @getimagesize($source);

	if ($dimension === false)
	{
		return false;
	}

	list($width, $height, $type, ) = $dimension;

	if (empty($width) || empty($height))
	{
		return false;
	}

	if ($width <= $config['photo_thumb_width'] && $height <= $config['photo_thumb_height'])
	{
		return false;
	}

	list($new_width, $new_height) = get_img_size_format($width, $height);

	// Do not create a thumbnail if the resulting width/height is bigger than the original one
	if ($new_width > $width && $new_height > $height)
	{
		return false;
	}

	$used_imagick = false;

	// Only use imagemagick if defined and the passthru function not disabled
	if ($config['img_imagick'] && function_exists('passthru'))
	{
		@passthru(escapeshellcmd($config['img_imagick']) . 'convert' . ((defined('PHP_OS') && preg_match('#^win#i', PHP_OS)) ? '.exe' : '') . ' -quality 85 -antialias -sample ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $destination) . '"');

		if (file_exists($destination))
		{
			$used_imagick = true;
		}
	}

	if (!$used_imagick) 
	{
		$type = get_supported_image_types($type);

		if ($type['gd'])
		{
			// If the type is not supported, we are not able to create a thumbnail
			if ($type['format'] === false)
			{
				return false;
			}

			switch ($type['format']) 
			{
				case IMG_GIF:
					$image = @imagecreatefromgif($source);
				break;

				case IMG_JPG:
					$image = @imagecreatefromjpeg($source);
				break;

				case IMG_PNG:
					$image = @imagecreatefrompng($source);
				break;

				case IMG_WBMP:
					$image = @imagecreatefromwbmp($source);
				break;
			}

			if ($type['version'] == 1)
			{
				$new_image = imagecreate($new_width, $new_height);
				imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
			}
			else
			{
				$new_image = imagecreatetruecolor($new_width, $new_height);
				imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
			}

			// If we are in safe mode create the destination file prior to using the gd functions to circumvent a PHP bug
			if (@ini_get('safe_mode') || @strtolower(ini_get('safe_mode')) == 'on')
			{
				@touch($destination);
			}

			switch ($type['format'])
			{
				case IMG_GIF:
					imagegif($new_image, $destination);
				break;

				case IMG_JPG:
					imagejpeg($new_image, $destination, 90);
				break;

				case IMG_PNG:
					imagepng($new_image, $destination);
				break;

				case IMG_WBMP:
					imagewbmp($new_image, $destination);
				break;
			}

			imagedestroy($new_image);
		}
		else
		{
			return false;
		}
	}

	if (!file_exists($destination))
	{
		return false;
	}

	@chmod($destination, 0666);

	return true;
}