trying to use the GD library
Posted: Fri Apr 30, 2010 9:50 am
1. I am trying to use the GD library in a script (located at the bottom of this page) that resizes an iimage but come up with the following errors:
----------
[30-Apr-2010 14:03:18] PHP Notice: Undefined index: upfile in /PhpSql/quickStart_Practice/wcphp/thumb.php on line 44
[30-Apr-2010 14:03:18] PHP Notice: Undefined index: upfile in /PhpSql/quickStart_Practice/wcphp/thumb.php on line 45
[30-Apr-2010 14:03:34] PHP Warning: imagejpeg() [<a href='function.imagejpeg'>function.imagejpeg</a>]: Unable to open 'thumbs/daveonPier.jpg' for writing: No such file or directory in /PhpSql/quickStart_Practice/wcphp/thumb.php on line 40
-----------
2. Within my pphpInfo() I get the following that indicates the library is installed:
-------------
Command './configure' '--with-mysql=/Applications/MAMP/Library' '--with-apxs2=/Applications/MAMP/Library/bin/apxs' '--with-gd' '--enable-bcmath' '--enable-ftp' '--enable-gd-native-ttf'
GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.3.9
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled
--------------
3. The following script returns 'mkthumb not present' though the mkthumb() function is supposed to be part of the library
4. I am using the following:
------------
Apache/2.0.63 (Unix)
PHP/5.2.11 DAV/2
MySQL client version: 5.1.37
-------------
Can someone start me off on how to fix this?
Appreciated,
chopWood
----------
[30-Apr-2010 14:03:18] PHP Notice: Undefined index: upfile in /PhpSql/quickStart_Practice/wcphp/thumb.php on line 44
[30-Apr-2010 14:03:18] PHP Notice: Undefined index: upfile in /PhpSql/quickStart_Practice/wcphp/thumb.php on line 45
[30-Apr-2010 14:03:34] PHP Warning: imagejpeg() [<a href='function.imagejpeg'>function.imagejpeg</a>]: Unable to open 'thumbs/daveonPier.jpg' for writing: No such file or directory in /PhpSql/quickStart_Practice/wcphp/thumb.php on line 40
-----------
2. Within my pphpInfo() I get the following that indicates the library is installed:
-------------
Command './configure' '--with-mysql=/Applications/MAMP/Library' '--with-apxs2=/Applications/MAMP/Library/bin/apxs' '--with-gd' '--enable-bcmath' '--enable-ftp' '--enable-gd-native-ttf'
GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.3.9
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled
--------------
3. The following script returns 'mkthumb not present' though the mkthumb() function is supposed to be part of the library
Code: Select all
<?php
if (function_exists(mkthumb)){
print 'mkthumb present';
}else {
print 'mkthumb not present';
print' ';
}
?>
4. I am using the following:
------------
Apache/2.0.63 (Unix)
PHP/5.2.11 DAV/2
MySQL client version: 5.1.37
-------------
Can someone start me off on how to fix this?
Appreciated,
chopWood
Code: Select all
<?php
function mkthumb($filename, $thumbname) {
/* generate an image thumbnail */
$thumb_width = 125;
$thumb_height = 125;
if (preg_match('/\.gif$/i', $filename)) {
$src_image = imagecreatefromgif($filename);
} else if (preg_match('/\.png$/i', $filename)) {
$src_image = imagecreatefrompng($filename);
} else {
/* assume jpeg by default */
$src_image = imagecreatefromjpeg($filename);
}
$width = imagesx($src_image);
$height = imagesy($src_image);
if (($height > $thumb_height) || ($width > $thumb_width)) {
/* create a thumbnail */
if ($width > $height) {
$ratio = $thumb_width / $width;
} else {
$ratio = $thumb_height / $height;
}
$new_width = round($width * $ratio);
$new_height = round($height * $ratio);
$dest_image = ImageCreateTrueColor($new_width, $new_height);
imagecopyresampled($dest_image, $src_image, 0, 0, 0, 0,
$new_width, $new_height, $width, $height);
imagedestroy($src_image);
} else {
/* image is already small enough; just output */
$dest_image = $src_image;
}
imagejpeg($dest_image, $thumbname);
imagedestroy($dest_image);
}
$upfile = $_FILES["upfile"]["tmp_name"];
$fn = $_FILES["upfile"]["name"];
$thumb_filename = "thumbs/$fn";
if ($upfile) {
mkthumb($upfile, $thumb_filename);
print "<img src=\"$thumb_filename\" />";
} else { ?>
<form action="thumb.php" enctype="multipart/form-data" method="post">
Upload an image:<br />
<input name="upfile" type="file" /><br />
<input name="Submit" type="submit" value="Upload Image" />
<?
}
?>