note 35814 added to function.imagecreatefromjpeg
| From: | massis at 7esign dot com | Date: | Mon, 15 Sep 2003 15:57:55 +0000 |
| Subject: | note 35814 added to function.imagecreatefromjpeg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-56536@lists.php.net to get a copy of this message | ||
Hi all!
I am having problems creating jpeg images from my database.
My host recently upgraded PHP to version 4.3.1.
All my files were on the gd library formate and now I have to convert to GD2. How would I do that???
I am getting all the images now with 256 colors or less...
PLEASE HELP ME OUT !!!
Thanks
Here is my php file:
<?
// Configuration:
//// CODE
if (!isset($w))
{
$w = 200;
}
if (!isset($h))
{
$h = 120;
}
SetType($mode, 'integer');
SetType($w, 'integer');
SetType($h, 'integer');
SetType($img, 'string' );
function percent($p, $w)
{
return (real)(100 * ($p / $w));
}
function unpercent($percent, $whole)
{
return (real)(($percent * $whole) / 100);
}
// Initialization
//$img = "5_0.jpg";
//$mode = 0;
$img = "photos/".$img;
// Make sure the file exists...
if (!file_exists($img))
{
echo "Error: could not find file: $img.";
exit();
}
// If the user defined a type to use.
if (!isset($type))
{
$ext = explode('.', $img);
$ext = $ext[count($ext)-1];
switch(strtolower($ext))
{
case 'jpeg' :
$type = 'jpg';
break;
default :
$type = $ext;
break;
}
}
// Create the image...
switch (strtolower($type))
{
case 'jpg':
$tmp = @imagecreatefromjpeg($img);
break;
case 'gif':
$tmp = @imagecreatefromgif($img);
break;
case 'png':
$tmp = @imagecreatefrompng($img);
break;
default:
echo 'Error: Unrecognized image format.';
exit();
break;
}
if ($tmp)
{
// Resize it
$ow = imagesx ($tmp); // Original image width
$oh = imagesy ($tmp); // Original image height
if ($mode)
{
// Just smash it up to fit the dimensions
$nw = $w;
$nh = $h;
}
else
{
// Make it proportional.
if ($ow > $oh)
{
$nw = $w;
$nh = unpercent(percent($nw, $ow), $oh);
}
else if ($oh > $ow)
{
$nh = $h;
$nw = unpercent(percent($nh, $oh), $ow);
} else {
$nh = $h;
$oh = $w;
}
}
$out = imagecreate($nw, $nh);
imagecopyresized($out, $tmp, 0, 0, 0, 0, $nw, $nh, $ow, $oh);
imagedestroy($tmp);
} else {
echo 'Could not create image resource.';
exit;
}
if ($out) {
switch (strtolower($type)) {
case 'jpg':
header('Content-type: image/jpeg');
imagejpeg($out);
break;
case 'gif':
header('Content-type: image/gif');
imagegif($out);
break;
case 'png':
header('Content-type: image/png');
imagepng($out);
break;
}
imagedestroy($out);
} else {
echo 'ERROR: Could not create resized image.';
}
// $img = "5_0.jpg";
$imgsize = getimagesize ($img);
print 'Width: '. $imgsize[0];
print '<br>Height: '. $imgsize[1];
if ($imgsize[0] > $imgsize[1]) {
print "<br>es mas ancho que alto";
} else {
print "<br>es mas alto que ancho";
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecreatefromjpeg.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35814
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35814&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35814&report=yes