PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Aug 12, 2020 1:08 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sat Oct 08, 2005 9:26 pm 
Offline
Forum Commoner

Joined: Sat Oct 08, 2005 9:16 pm
Posts: 67
Location: USA


Last edited by Dm7 on Sun Oct 09, 2005 6:01 pm, edited 3 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 08, 2005 9:32 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
missing a semicolon
Syntax: [ Download ] [ Hide ]
$trans = imagecolortransparent($thumb, $lime)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 08, 2005 9:42 pm 
Offline
Forum Commoner

Joined: Sat Oct 08, 2005 9:16 pm
Posts: 67
Location: USA


Top
 Profile  
 
PostPosted: Sat Oct 08, 2005 10:48 pm 
Offline
Forum Commoner

Joined: Sat Oct 08, 2005 9:16 pm
Posts: 67
Location: USA
Other thing is... it works... but, whenever i change $black bg to other color, then it won't upload the image at all.

Example of working image with black bg:
Image
Visit http://dm7.net/?page=gallery to see what I mean...

The code is:
Syntax: [ Download ] [ Hide ]
<?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', 30);



// 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, 62, 0, 91);

                       

                                ################################################

                                #  create rounded corner image (beta version)  #

                                ################################################

                               

                                // create arc on top left corner

                        imagearc($thumb, (CORNER_THICKNESS/2), (CORNER_THICKNESS/2), CORNER_THICKNESS, CORNER_THICKNESS, 180, 270, $lime);

                       

                                // create arc on top right corner                      

                        imagearc($thumb, ($thumb_x-(CORNER_THICKNESS)/2), (CORNER_THICKNESS/2), CORNER_THICKNESS, CORNER_THICKNESS, 270, 360, $lime);

                       

                                // create arc on bottom left corner

                        imagearc($thumb, CORNER_THICKNESS/2, ($thumb_y-(CORNER_THICKNESS/2)), CORNER_THICKNESS, CORNER_THICKNESS, 90, 180, $lime);

                       

                                // create arc on bottom right corner

                        imagearc($thumb, ($thumb_x-(CORNER_THICKNESS/2)), ($thumb_y-(CORNER_THICKNESS/2)), CORNER_THICKNESS, CORNER_THICKNESS, 0, 90, $lime);

                       

                                // fill out the top edge

                        imageline($thumb, (CORNER_THICKNESS/2), 0, ($thumb_x-(CORNER_THICKNESS/2)), 0, $lime);

                       

                                // fill out the bottom edge

                        imageline($thumb, CORNER_THICKNESS/2, ($thumb_y-1), ($thumb_x-(CORNER_THICKNESS/2)), ($thumb_y-1), $lime);

                       

                                // fill out the left edge

                        imageline($thumb, 0, CORNER_THICKNESS/2, 0, ($thumb_y-(CORNER_THICKNESS/2)), $lime);

                       

                                // fill out the right edge

                        imageline($thumb, ($thumb_x-1), CORNER_THICKNESS/2, ($thumb_x-1), ($thumb_y-(CORNER_THICKNESS/2)), $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, 75);

                       

                       

                        }

                        }

                                       

        }

                       

 

 ?> </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>


Whenever I change this code:
Syntax: [ Download ] [ Hide ]
// set colors for background and rounded corners

                        $black = imagecolorallocate($thumb, 0, 0, 0);

                        $lime = imagecolorallocate($thumb, 62, 0, 91);

to
Syntax: [ Download ] [ Hide ]
// set colors for background and rounded corners

                        $black = imagecolorallocate($thumb, 23, 0, 34);

                        $lime = imagecolorallocate($thumb, 62, 0, 91);

Then the script will NOT work at all! :( I didn't get any errors, just that it won't work at all. I don't even get my image to upload.. nor that the data being entered in my database at all. I absolutely have no idea what's wrong with it. I'm hoping that you would help me out. Thanks. :D


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 08, 2005 11:01 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 09, 2005 10:21 am 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 09, 2005 4:05 pm 
Offline
Forum Commoner

Joined: Sat Oct 08, 2005 9:16 pm
Posts: 67
Location: USA


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 09, 2005 4:58 pm 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 09, 2005 5:12 pm 
Offline
Forum Commoner

Joined: Sat Oct 08, 2005 9:16 pm
Posts: 67
Location: USA


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 3:15 pm 
Offline
Forum Commoner

Joined: Sat Oct 08, 2005 9:16 pm
Posts: 67
Location: USA
I have researched everywhere and tried to figure out why it's not working... so far.. I'm having no luck. I only can make those thumbnail images with those rounded corners when it has black background (0, 0, 0), but not when I use anything else than 0, 0, 0. When I use other color, the picture wouldn't be even calucated at all and doesn't return the result at all.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 22, 2005 6:57 pm 
Offline
Forum Commoner

Joined: Sat Oct 08, 2005 9:16 pm
Posts: 67
Location: USA
Syntax: [ Download ] [ Hide ]
// generates thumbnail image - $orig is for imagecreate function

function makeThumb($orig) {

                        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);

               

                                                                       

                        // 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);

                                }

                                elseif ($imageradio_x < $imageratio_y) {

                                        $thumb_x = round($width / $imageratio_y);

                                        $thumb_y = MAX_HEIGHT;

                                }

                                elseif ($imageradio_x == $imageratio_y) {

                                        $thumb_x = MAX_WIDTH;

                                        $thumb_y = MAX_HEIGHT;

                                }

                                else {

                                        $show = 'error';

                                        $error = 'error in calucating the thumbnail size!';

                                }

                       

                                // 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);    

                        return $thumb;

                        } else {

                        echo "Couldn't generate thumbnail image! Not valid!";

                        }

}

?>
Syntax: [ Download ] [ Hide ]
<?php

include('functions_main.inc.php');

include('configuration.inc.php');



$im = imagecreatefromjpeg("webdesignconcept_31.jpg");

makeThumb($im);

header("Content-type:image/jpeg");

imagejpeg($im);

imagedestroy($im);



?>


It didn't shrink to 150 x 150 size. I didn' get any error and the image is shown, but it hasn't been resized. ??? *scratches her head*


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 22, 2005 7:53 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
you're returning $thumb, but not using/capturing it in your makeThumb() call..


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 22, 2005 8:23 pm 
Offline
Forum Commoner

Joined: Sat Oct 08, 2005 9:16 pm
Posts: 67
Location: USA


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 22, 2005 8:26 pm 
Offline
Site Admin
User avatar

Joined: Tue Dec 23, 2003 3:10 am
Posts: 11470
Location: Toronto
Syntax: [ Download ] [ Hide ]
makeThumb($im);


Your only calling the function, but not using/storing the return...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 22, 2005 8:27 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
your function, makeThumb() returns $thumb when the image was created. You never use the returned information from the function in your later code snippet.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group