Author Topic: PHP image reflection help...  (Read 2204 times)

0 Members and 1 Guest are viewing this topic.

Offline TeachyTopic starter

  • Irregular
    • View Profile
PHP image reflection help...
« on: January 14, 2008, 08:06:43 PM »
Hello guys, I hope you can help me with this

I am trying to add a PHP-serverside image reflection, using the tutorial at http://www.talkphp.com/advanced-php-programming/1714-image-reflections-php.html

At the moment, we only want to apply it to our staff signatures, and for the reflection to be about 50% the height of the real image (which then fades into the background)...

I tried using the tutorial and putting the relevant lines in, changing jpeg to png (as that's what the rest uses) and only using the header, imagepng and imagedestroy lines once, but I just got tonnes of errors. Can you help me integrating that script into mine to make it work?

Thanks!


<?php
 
include_once('/home/site/functions-connectonly.php');
 
putenv('GDFONTPATH=' realpath('.'));

if (isset(
$_GET['staffid'])) {
  
$staffid = ($_GET['staffid']);

  
$num_users=mysql_num_rows(mysql_query("Select * from user where account='".mysql_real_escape_string(htmlentities($staffid))."'"));
  if (
$num_users>0) {

    
$ourGroups='';
    
// fetch user from db
    
$user=mysql_fetch_array(mysql_query("Select * from user where account='".mysql_real_escape_string(htmlentities($staffid))."'"));
    
$flag=mysql_fetch_array(mysql_query("Select * from flag where id_flag=".$user['location'])); 

    
// Group code here (irrelevant)

    
$name "".$user['account']."";
    if (
strlen($ourGroups)>0) {
       
$text "\n".$ourGroups."\nhttp://oursite.com";
    } else {
       
$text "\nNo groups\nhttp://oursite.com";
    }

    
// tell the browser what it's about to recieve
    
header("Content-type: image/png");

    
// import background image
    
$img = @imagecreatefrompng("/home/site/img/sigbg.png");
    
$im imagecreatetruecolor(18558);

    
// font details
    
$font 'segoe.ttf';

    
// insert the flag
    
$insert imagecreatefrompng("/home/site/img/flags/".$flag['img']."");

    
// Select the first pixel of the overlay image (at 0,0) and use
    // it's color to define the transparent color

    
imagecolortransparent($insert,imagecolorat($insert,0,0));

    
// Get overlay image width and hight for later use

    
$insert_x imagesx($insert);
    
$insert_y imagesy($insert);

    
// Combine the images into a single output image. Some people
    // prefer to use the imagecopy() function, but more often than
    // not, it sometimes does not work. (could be a bug)

    
imagecopymerge($img,$insert,162,5,0,0,$insert_x,$insert_y,100);

    
// text color
    
$white imagecolorallocate($img255255255);
    
$grey imagecolorallocate($img225225225);

    
// add the text to the image ,
    
$textarr explode("\n",$text);
    
$i 16;
    foreach(
$textarr as $a){
      
imagettftext($img1005216$white$font$name);
      
imagettftext($img8052$i$grey$font$a);
      
$i=$i+17;
    }

    
// date in the past, so that the image is not cached by the browser
    
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

    
// create the png image
    
imagepng($img);

    
// clean up
    
imagedestroy($img);

  }
}
 
?>

Offline kickassamd

  • Enthusiast
  • Gender: Male
    • View Profile
    • KickassAMD
Re: PHP image reflection help...
« Reply #1 on: January 14, 2008, 08:19:58 PM »
Post the errors.

Offline TeachyTopic starter

  • Irregular
    • View Profile
Re: PHP image reflection help...
« Reply #2 on: January 14, 2008, 08:47:02 PM »
Hi, thanks for your reply.

Got the errors sorted, but now, I don't see my normal signature, instead just a grey gradient which is halfway down the image, where I guess it should be... *baffled*


<?php
 
include_once('/home/site/functions-connectonly.php');
 
putenv('GDFONTPATH=' realpath('.'));

if (isset(
$_GET['staffid'])) {
  
$staffid = ($_GET['staffid']);

  
$num_users=mysql_num_rows(mysql_query("Select * from user where account='".mysql_real_escape_string(htmlentities($staffid))."'"));
  if (
$num_users>0) {

    
$ourGroups='';
    
// fetch user from db
    
$user=mysql_fetch_array(mysql_query("Select * from user where account='".mysql_real_escape_string(htmlentities($staffid))."'"));
    
$flag=mysql_fetch_array(mysql_query("Select * from flag where id_flag=".$user['location'])); 

    
// Group code here (irrelevant)

    
$name "".$user['account']."";
    if (
strlen($ourGroups)>0) {
       
$text "\n".$ourGroups."\nhttp://oursite.com";
    } else {
       
$text "\nNo groups\nhttp://oursite.com";
    }

    
// tell the browser what it's about to recieve
    
header("Content-type: image/png");

    
// import background image
    
$img = @imagecreatefrompng("/home/site/img/sigbg.png");
    
// Create new blank image with sizes.  Normal size is 58, add 30
    
$newImage imagecreatetruecolor(18588);
    for (
$x 0$x 185$x++) {
      for (
$y 0$y 88$y++)
      {
        
imagecopy($newImage$img$x185 $y 1$x$y11);
      }
    }

    
$background imagecreatetruecolor(18588);

    
$gradientColor "255 255 255"// White
    
$gradparts explode(" ",$gradientColor); // get the parts of the  colour (RRR,GGG,BBB)
    
$dividerHeight 1;

    
// font details
    
$font 'segoe.ttf';

    
// insert the flag
    
$insert imagecreatefrompng("/home/site/img/flags/".$flag['img']."");

    
// Select the first pixel of the overlay image (at 0,0) and use
    // it's color to define the transparent color

    
imagecolortransparent($insert,imagecolorat($insert,0,0));

    
// Get overlay image width and hight for later use

    
$insert_x imagesx($insert);
    
$insert_y imagesy($insert);

    
// Combine the images into a single output image. Some people
    // prefer to use the imagecopy() function, but more often than
    // not, it sometimes does not work. (could be a bug)

    
imagecopymerge($background,$newImage,0,0,0,0,185,88,100);
    
imagecopymerge($img,$insert,162,5,0,0,$insert_x,$insert_y,100);

    
// text color
    
$gradient_y_startpoint $dividerHeight;
    
$gdGradientColor=ImageColorAllocate($background,$gradparts[0],$gradparts[1],$gradparts[2]);

    
$white imagecolorallocate($img255255255);
    
$grey imagecolorallocate($img225225225);

    
// create from a the image so we can use fade out.
    
$gradient_line imagecreatetruecolor(1851);

    
// Next we draw a GD line into our gradient_line
    
imageline ($gradient_line001850$gdGradientColor);

    
// add the text to the image ,
    
$textarr explode("\n",$text);
    
$i 16;
    foreach(
$textarr as $a){
      
imagettftext($img1005216$white$font$name);
      
imagettftext($img8052$i$grey$font$a);
      
$i=$i+17;
    }

    
$ii 0;
    
$transparency 30//from 0 - 100

    
while ($ii 88//create line by line changing as we go
    
{
      
imagecopymerge ($background$gradient_line0,$gradient_y_startpoint001851$transparency);
        
      ++
$ii;
      ++
$gradient_y_startpoint;
                
      if (
$transparency == 100) {
        
$transparency 100;
      } else {
        
// this will determing the height of the
        // reflection. The higher the number, the smaller the reflection.
        // 1 being the lowest(highest reflection)
        
$transparency $transparency 1;
      }
    }

    
// Set the thickness of the line we're about to draw
    
imagesetthickness ($background88);

    
// Draw the line
    
imageline ($background001850$gdGradientColor);

    
// date in the past, so that the image is not cached by the browser
    
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

    
// create the png image
    
imagepng($background);

    
// clean up
    
imagedestroy($background);
    
imagedestroy(gradient_line);
    
imagedestroy(newImage);

  }
}
 
?>

Offline TeachyTopic starter

  • Irregular
    • View Profile
Re: PHP image reflection help...
« Reply #3 on: January 15, 2008, 06:17:21 AM »
Any luck? :)

Offline TeachyTopic starter

  • Irregular
    • View Profile
Re: PHP image reflection help...
« Reply #4 on: January 17, 2008, 06:39:29 PM »
Any luck guys? sorry to bump this

Offline Aureole

  • Devotee
  • Hmm...
    • View Profile
Re: PHP image reflection help...
« Reply #5 on: January 17, 2008, 06:45:20 PM »
I know a great way to do this with Javascript if you're interested, with your PHP problems though I can't help...
Quote
PHP: 4.4.7 & MYSQL: 4.1.21 Standard


Offline Barand

  • Sen . (ile || sei)
  • Staff Alumni
  • 'Mind Boggling!'
  • *
  • Gender: Male
  • php 4.3/5.1 MySql 5.0.1
    • View Profile
Re: PHP image reflection help...
« Reply #6 on: January 17, 2008, 07:08:00 PM »
Use code tags when you post your code in these forums
|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

Offline TeachyTopic starter

  • Irregular
    • View Profile
Re: PHP image reflection help...
« Reply #7 on: January 17, 2008, 08:13:43 PM »
Hi there
Thanks for your replies :)
I've seen the Javascript one, it doesn't really do it the same as the PHP one and we ideally want it serverside

Barand, I used the [-php][-/php] ones as that was the formatting, that's how it showed up. I still see that when I edit too

Offline rperea

  • Irregular
    • View Profile
Re: PHP image reflection help...
« Reply #8 on: February 12, 2008, 11:29:23 AM »
I am not too sure about the functions that you are using to create the images, but, I have created an open source project called vsrefleciton on SourceForge.net.
It uses PHP and ImageMagick to create great Image Reflections on the fly.

Possibly you could use some of the code to make your project work.
The sourceforge download is located at:   http://sourceforge.net/project/showfiles.php?group_id=217530

You can visit the project homepage at:    http://www.vsourcesoftware.com/vsreflection.php

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.