includes/functions.php
changeset 1364 68c17d935750
parent 1360 570abc94bd7f
child 1373 851b91febb85
equal deleted inserted replaced
1363:f1ed3e9298ae 1364:68c17d935750
  4266 	{
  4266 	{
  4267 		if ( !preg_match('/^([\/A-z0-9:\. _-]+)$/', $magick_path) )
  4267 		if ( !preg_match('/^([\/A-z0-9:\. _-]+)$/', $magick_path) )
  4268 		{
  4268 		{
  4269 			die('SECURITY: ImageMagick path is screwy');
  4269 			die('SECURITY: ImageMagick path is screwy');
  4270 		}
  4270 		}
       
  4271 		$magick_path = escapeshellcmd($magick_path);
  4271 		$cmdline = "$magick_path $in_file_sh -resize \"{$width}x{$height}>\" $out_file_sh";
  4272 		$cmdline = "$magick_path $in_file_sh -resize \"{$width}x{$height}>\" $out_file_sh";
  4272 		system($cmdline, $return);
  4273 		system($cmdline, $return);
  4273 		if ( !file_exists($out_file) )
  4274 		if ( !file_exists($out_file) )
  4274 			throw new Exception('ImageMagick: did not produce output image file.');
  4275 			throw new Exception('ImageMagick: did not produce output image file.');
  4275 		return true;
  4276 		return true;
  4289 			$new_height = round( $width / $ratio );
  4290 			$new_height = round( $width / $ratio );
  4290 		}
  4291 		}
  4291 		else if ( $ratio < 1 )
  4292 		else if ( $ratio < 1 )
  4292 		{
  4293 		{
  4293 			// orig. height is greater than width
  4294 			// orig. height is greater than width
  4294 			$new_width = round( $height / $ratio );
  4295 			$new_width = round( $height * $ratio );
  4295 			$new_height = $height;
  4296 			$new_height = $height;
  4296 		}
  4297 		}
  4297 		else if ( $ratio == 1 )
  4298 		else if ( $ratio == 1 )
  4298 		{
  4299 		{
  4299 			$new_width = $width;
  4300 			$new_width = $width;
  4310 		if ( !$newimage )
  4311 		if ( !$newimage )
  4311 			throw new Exception('GD: Request to create new truecolor image refused.');
  4312 			throw new Exception('GD: Request to create new truecolor image refused.');
  4312 		$oldimage = @$func($in_file);
  4313 		$oldimage = @$func($in_file);
  4313 		if ( !$oldimage )
  4314 		if ( !$oldimage )
  4314 			throw new Exception('GD: Request to load input image file failed.');
  4315 			throw new Exception('GD: Request to load input image file failed.');
       
  4316 		
       
  4317 		if ( $file_ext == 'png' || $file_ext == 'gif' )
       
  4318 		{
       
  4319 			imagecolortransparent($newimage, imagecolorallocatealpha($newimage, 0, 0, 0, 127));
       
  4320 			imagealphablending($newimage, false);
       
  4321 			imagesavealpha($newimage, true);
       
  4322 		}
  4315 		
  4323 		
  4316 		// Perform scaling
  4324 		// Perform scaling
  4317 		imagecopyresampled($newimage, $oldimage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
  4325 		imagecopyresampled($newimage, $oldimage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
  4318 		
  4326 		
  4319 		// Get output format
  4327 		// Get output format