Jump to content

GD BMP Resize


CanMan2004

Recommended Posts

Hi all

I have a php scrpt which resizes JPEG, GIF and PNG images, is there a function to add for BMP images too, adding the code which is used and changing it for BMP use, seems to throw up errors, the code is

[code]<?php

function createthumb($img,$target="",$width=0,$height=0,$percent=0, $max_height=0)
{
if (strpos($img,".jpg") !== false or strpos($img,".jpeg") !== false)
{
$image = ImageCreateFromJpeg($img);
$extension = ".jpg";
}
elseif (strpos($img,".png") !== false)
{
$image = ImageCreateFromPng($img);
$extension = ".png";
}
elseif (strpos($img,".gif") !== false)
{
$image = ImageCreateFromGif($img);
$extension = ".gif";
}
elseif (strpos($img,".JPG") !== false)
{
$image = ImageCreateFromJpeg($img);
$extension = ".JPG";
}
$size = getimagesize ($img);
if ($width and !$height)
{
$height = ($size[1] / $size[0]) * $width;
}
elseif (!$width and $height)
{
$width = ($size[0] / $size[1]) * $height;
}
elseif ($percent)
{
$width = $size[0] / 100 * $percent;
$height = $size[1] / 100 * $percent;
}
elseif (!$width and !$height and !$percent)
{
$width = 100;
$height = ($size[1] / $size[0]) * $width;
}
if ($max_height != 0 || $max_height != "")
{
if ($height > $max_height)
{
$difference_ratio = $height / $width;
$new_width = $max_height / $difference_ratio;
$width = $new_width;
$height = $max_height;
}
}
$thumb = imagecreatetruecolor ($width, $height);
if (function_exists("imageCopyResampled"))
{
if (!@ImageCopyResampled($thumb, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]))
{
ImageCopyResized($thumb, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
}
  }
  else
  {
ImageCopyResized($thumb, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
  }
  if (!$target)
  {
$target = "temp".$extension;
  }
  $return = true;   
  switch ($extension)
  {
case ".jpg":
{
imagejpeg($thumb, $target, 70);
break;
}
case ".gif":
{
imagegif($thumb, $target);
break;
}
case ".JPG":
{
imagejpeg($thumb, $target);
break;
}
case ".png":
{
imagepng($thumb, $target);
break;
}
default:
{
$return = false;
}
  }
  return $return;
}
?>[/code]

Can anyone give any advice

Thanks in advance
Ed
Link to comment
https://forums.phpfreaks.com/topic/27098-gd-bmp-resize/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.