Rounded corner thumbnail [status: still not solved]
Posted: Sat Oct 08, 2005 9:26 pm
Hi,
It was working with resize and upload the image (everything worked)... til recently, I decided to add rounded corners for thumbnail images and I got this error...
What did I do wrong? Notice: the line 120 in my code is...
Here's my code (very long... please bear with me)...
Sorry, I know it's a long code, but I felt that all were necessary to help you understand what my code was doing. It did work with the tutorial that I found for rounded corner button with center text.. I tested it on the image and it worked... it's just that it all of a sudden doesn't work in my code and I can't figure out why. Any ideas? Thanks in advance. 
It was working with resize and upload the image (everything worked)... til recently, I decided to add rounded corners for thumbnail images and I got this error...
Code: Select all
Parse error: parse error, unexpected T_STRING in /var/www/vhosts/dm7.net/httpdocs/gallery/upload.php on line 118Code: Select all
// create arc on top left corner
imagearc($thumb, CORNER_THICKNESS, CORNER_THICKNESS, CORNER_THICKNESS, CORNER_THICKNESS, 180, 270, $lime);Code: Select all
<?php
#########################################
# Admin Gallery System #
# upload.php #
#########################################
include("auth.inc.php");
include("functions_main.inc.php");
include("fields_login.inc.php");
include("gallery.css");
$table = "art";
if ($_GET['log'] == "yes") {
$result = "You have been already logged in!"; }
?>
<p class="style3"><?php echo $page['top']; echo " - Today is: " . date("Y-m-d G:i:s"); ?></p>
<div align="center">You have reached "<?php echo $page['title'] ?>" uploading section!</div>
<center><?php if (isset($result)) { ?><font color="red"><?php echo $result; ?></font><?php } ?></center>
<?php
$overlay = "/var/www/vhosts/dm7.net/httpdocs/gallery/Copyright.png";
$cache_fs = "/var/www/vhosts/dm7.net/httpdocs/gallery/images/";
$cache_uri = "http://dm7.net/gallery/images/";
define('MAX_HEIGHT', 150);
define('MAX_WIDTH', 150);
define('CORNER_THICKNESS', 20);
// Checks if overlay image exists
if (!$overlay = imagecreatefrompng($overlay)) {
$error = "error opening overlay image";
$show = "error";
}
// sets up the path
if (isset($_FILES['file'])) {
$name = $_FILES['file']['name'];
$base_fs = $cache_fs . $name;
$base_fstb = $cache_fs . 'tb' . $name;
$base_uri = $cache_uri . $name;
$base_uritb = $cache_uri . 'tb' . $name;
//open original (uploaded) image, based on type.
switch($_FILES['file']['type']) {
case 'image/jpeg':
case 'image/pjpeg':
$orig = imagecreatefromjpeg($_FILES['file']['tmp_name']);
break;
case 'image/png':
$orig = imagecreatefrompng($_FILES['file']['tmp_name']);
break;
case 'image/gif':
$orig = imagecreatefromgif($_FILES['file']['tmp_name']);
break;
default:
$error = "Unknown File Format or MIME Type";
$show = "error"; }
if ($orig) {
// fetch the size of the original and overlay images,
// and calculate the size of the new image and thumb.
$width = imagesx($orig);
$height = imagesy($orig);
$overlay_x = imagesx($overlay);
$overlay_y = imagesy($overlay);
// Calculate thumbnail size to avoid distortions
$imageratio_x = $width / MAX_WIDTH;
$imageratio_y = $height / MAX_HEIGHT;
if ($imageratio_x > $imageratio_y) {
$thumb_x = MAX_WIDTH;
$thumb_y = round($height / $imageratio_x);
}
if ($imageradio_x < $imageratio_y) {
$thumb_x = round($width / $imageratio_y);
$thumb_y = MAX_HEIGHT;
}
if ($imageradio_x == $imageratio_y) {
$thumb_x = MAX_WIDTH;
$thumb_y = MAX_HEIGHT;
}
// Calculate offsets for overlay (bottom right)
$offset_x = $width - $overlay_x;
$offset_y = 1;
// Set the transparent color in the overlay, and copy
// it into the new image.
imagecolortransparent($overlay);
imagecopymerge($orig, $overlay, $offset_x, $offset_y, 0, 0, $overlay_x, $overlay_y, 75);
// create the thumb image, and scale the original in it.
$thumb = imagecreatetruecolor($thumb_x, $thumb_y);
imagecopyresampled($thumb, $orig, 0, 0, 0, 0, $thumb_x, $thumb_y, $width, $height);
// set colors for background and rounded corners
$black = imagecolorallocate($thumb, 0, 0, 0);
$lime = imagecolorallocate($thumb, 0, 255, 0);
// transparent
$trans = imagecolortransparent($thumb, $lime)
################################################
# create rounded corner image (beta version) #
################################################
// create arc on top left corner
imagearc($thumb, CORNER_THICKNESS, CORNER_THICKNESS, CORNER_THICKNESS, CORNER_THICKNESS, 180, 270, $lime);
// create arc on top right corner
imagearc($thumb, ($thumb_x-CORNER_THICKNESS), CORNER_THICKNESS, CORNER_THICKNESS, 270, 0, $lime);
// create arc on bottom left corner
imagearc($thumb, CORNER_THICKNESS, ($thumb_y-CORNER_THICKNESS), CORNER_THICKNESS, CORNER_THICKNESS, 90, 180, $lime);
// create arc on bottom right corner
imagearc($thumb, ($thumb_x-CORNER_THICKNESS), ($thumb_y-CORNER_THICKNESS), CORNER_THICKNESS, CORNER_THICKNESS, 0, 90, $lime);
// fill out the top edge
imageline($thumb, CORNER_THICKNESS, 0, ($thumb_x-CORNER_THICKNESS), 0, $lime);
// fill out the bottom edge
imageline($thumb, CORNER_THICKNESS, $thumb_y, ($thumb_x-CORNER_THICKNESS), $thumb_y, $lime);
// fill out the left edge
imageline($thumb, 0, CORNER_THICKNESS, 0, CORNER_THICKNESS, $lime);
// fill out the right edge
imageline($thumb, $thumb_x, CORNER_THICKNESS, $thumb_x, ($thumb_y-CORNER_THICKNESS), $lime);
// fill black bg
imagefilltoborder($thumb, 0, 0, $lime, $black);
imagefilltoborder($thumb, 0, $thumb_y, $lime, $black);
imagefilltoborder($thumb, $thumb_x, 0, $lime, $black);
imagefilltoborder($thumb, $thumb_x, $thumb_y, $lime, $black);
// calculate the uri of the 2 images
$orig_uri = $base_uri;
$thumb_uri = $base_uritb;
// Write 2 images to disk
if(is_file($orig_uri)) {
$show = "error";
$error = "File already exists!";
}
else {
// write the records to database
$datetime = date("Y-m-d G:i:s");
$title = $_REQUEST['title'];
$comment = $_REQUEST['comment'];
Connect_to_db("Vars.inc.php");
$sql = "INSERT INTO $table SET " .
"name='$name', ".
"image='$orig_uri', ".
"tbimage='$thumb_uri', " .
"title='$title', " .
"date='$datetime', " .
"comment='$comment'";
if (mysql_query($sql)) {
$show = "result"; }
else { echo "Couldn't execute query! " . mysql_error();
die(); }
imagejpeg($orig, $base_fs, 90);
imagejpeg($thumb, $base_fstb);
}
}
}
?> </p>
<?php
if(isset($show)) {
if($show == "error") { ?>
<h2 align="center"><font color="red"><?=$error?></font></h2> <?php }
elseif($show == "result") { ?>
<h2 align="center">Thumb Image</h2>
<p align="center"><img src="<?=$thumb_uri?>"/></p>
<?php }} ?>
<form enctype="multipart/form-data" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<div align="center">
<table width="320" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td width="91">Image:</td>
<td width="221">
<input name="name" type="hidden" value="<?php echo $name ?>">
<input name="file" type="file" size="30"> </td>
</tr>
<tr>
<td>Title:</td>
<td><input name="title" type="text" id="title" size="32"></td>
</tr>
<tr>
<td valign="top">Comment:</td>
<td><textarea name="comment" cols="32" rows="4" id="comment"></textarea></td>
</tr>
<tr>
<td colspan="2"><div align="right">
<input type="submit" name="submit" value="Upload">
</div></td>
</tr>
</table>
</form>
<center>
<?php
foreach($menulogin as $key => $value)
{ if ($key == 'logout') {
echo $value;
}
else { echo $value . " | " ;}
} ?>
</center>
<p align="center"><?php echo $page['bottom']; ?></p>