Click here to get back home

Class to generate images

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Class to generate images e_matthes 04-17-2007
Get Chitika Premium
Posted by e_matthes on April 17, 2007, 11:55 am
Please log in for more thread options
Kimmo Laine wrote:
> <?php
>
> include('http://www.your.domain/next_page.php?foo=bar');

Unless next_page.php generates PHP, the script with this include will
only get HTML.

> exit();
>
> ?>

next_page.php

<?php
if (isset($_GET['foo'])) {
echo '<?php echo $_GET[\'foo\']; ?>';
} else {
echo '<?php echo \'Not available\'; ?>';
}

--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

Posted by ZeldorBlat on April 17, 2007, 12:28 pm
Please log in for more thread options
Kimmo Laine wrote:
> <?php
>
> include('http://www.your.domain/next_page.php?foo=bar');

Unless next_page.php generates PHP, the script with this include will
only get HTML.

> exit();
>
> ?>

next_page.php

<?php
if (isset($_GET['foo'])) {
echo '<?php echo $_GET[\'foo\']; ?>';
} else {
echo '<?php echo \'Not available\'; ?>';
}

--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

Posted by e_matthes on April 18, 2007, 12:15 am
Please log in for more thread options
> On Apr 17, 11:55 am, e_matt...@hotmail.com wrote:
>
>
>
> > Hello everyone,
>
> > I'm trying to make a class that will generate images. I can get it to
> > work if the class and the instance of the class is in the same file.
> > However, I can't get it to work if I save the class as its own file,
> > and try to make an instance of it in another file. Any thoughts?
>
> > Here is the working version:
>
> > <?php
>
> > header("Content-type: image/png");
> > $imageRes = new Image(200, 300);
> > $imageRes->colorImage(255,0,0);
> > $image = $imageRes->getImage();
> > imagepng($image);
>
> > class Image {
>
> > private $imageRes;
>
> > function __construct($widthIn, $heightIn) {
> > $this->imageRes = imageCreate($widthIn, $heightIn);
> > }
>
> > function colorImage($rIn,$gIn,$bIn) {
> > $red = imagecolorallocate( $this->imageRes,
$rIn,$gIn,$bIn );
> > }
>
> > function getImage() {
> > return $this->imageRes;
> > }
>
> > } // END class
>
> > ?>
>
> > Thanks for any help.
> > -Eric
>
> Make sure you require/include the file that contains the class
> definition. If the class is in a file called Image.php then you might
> have a page that looks like this:
>
> require('Image.php');
>
> header("Content-type: image/png");
> $imageRes = new Image(200, 300);
> $imageRes->colorImage(255,0,0);
> $image = $imageRes->getImage();
> imagepng($image);
>
> Also look into __autoload() -- it will make things much easier when
> you have a lot of classes.
>
> <http://www.php.net/autoload>


I think this is what I tried. When I put the class in a separate
file, this is what I have:

<?php

        // simple_phptests.php
        include_once("Image.php");
        header("Content-type: image/png");
        $imageRes = new Image(200, 300);
        $imageRes->colorImage(255,0,0);
        $image = $imageRes->getImage();
        imagepng($image);

?>

<?php

        // Image.php
        class Image {

                private $imageRes;

                function __construct($widthIn, $heightIn) {
                        $this->imageRes = imageCreate($widthIn, $heightIn);
                }
                function colorImage($rIn,$gIn,$bIn) {
                        $red = imagecolorallocate( $this->imageRes, $rIn,$gIn,$bIn );
                }
                function getImage() {
                        return $this->imageRes;
                }

        }        // END class

?>

This works for all the other classes I have created, but not for this
image class. The message I get when I load simple_phptests.php is:

"The image simple_phptests.php cannot be displayed, because it
contains errors."

Any other ideas? Thanks


Posted by Toby A Inkster on April 18, 2007, 5:10 am
Please log in for more thread options
Kimmo Laine wrote:
> <?php
>
> include('http://www.your.domain/next_page.php?foo=bar');

Unless next_page.php generates PHP, the script with this include will
only get HTML.

> exit();
>
> ?>

next_page.php

<?php
if (isset($_GET['foo'])) {
echo '<?php echo $_GET[\'foo\']; ?>';
} else {
echo '<?php echo \'Not available\'; ?>';
}

--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

Posted by e_matthes on April 18, 2007, 10:46 am
Please log in for more thread options
Kimmo Laine wrote:
> <?php
>
> include('http://www.your.domain/next_page.php?foo=bar');

Unless next_page.php generates PHP, the script with this include will
only get HTML.

> exit();
>
> ?>

next_page.php

<?php
if (isset($_GET['foo'])) {
echo '<?php echo $_GET[\'foo\']; ?>';
} else {
echo '<?php echo \'Not available\'; ?>';
}

--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

Similar ThreadsPosted
Script to generate auth images for comment posting? February 11, 2007, 7:50 am
Random images from Google Images September 8, 2005, 4:36 pm
Mzk - Mezzenger Klient (php Class), Class for making PHP bots and webmessengers (MSN Messenger) February 6, 2007, 12:29 am
Reading properties in non-instantiated child class from the parent class June 16, 2008, 1:23 am
PHP5: Can a class inherit initialized classvariable from another class? March 17, 2005, 12:31 pm
include file into class, retain class scope June 11, 2007, 5:56 pm
PHP to generate XML November 28, 2006, 4:51 pm
Can't generate XLM with the DOM March 7, 2008, 7:50 am
Generate HTML from PHP September 21, 2004, 2:34 pm
XSL generate-id problems April 6, 2005, 12:53 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap