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 4 1694
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>
On Apr 17, 8:28 am, ZeldorBlat <zeldorb...@gmail.comwrote:
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
e_matthes wrote:
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."
Is there anything outside your <?php ... ?block? Any whitespace?
Could you provide a URL?
--
Toby A Inkster BSc (Hons) ARCS http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
On Apr 18, 1:10 am, Toby A Inkster <usenet200...@tobyinkster.co.uk>
wrote:
e_matthes wrote:
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."
Is there anything outside your <?php ... ?block? Any whitespace?
Could you provide a URL?
--
Toby A Inkster BSc (Hons) ARCShttp://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
Thank you for the whitespace suggestion. I thought whitespace only
made a problem at the beginning of a file, so I hadn't noticed the two
blank lines at the end of each file. Works now! Thanks again to both
of you. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Rithish |
last post by:
I have a set of images on a server. I want to pick these from the
database without creating a
temporary file on the server; and also have some text alongwith it.
Something like,
...
|
by: Richard Barnet |
last post by:
I'm trying to style a line break, something like this:
<br class="spacer" />
via CSS, but none of the following seems to have any effect. Any ideas?
br.spacer {
clear: both;
height: 50px;...
|
by: Øyvind Isaksen |
last post by:
Hello!
I need to dynamic generate a SQL statement based on how many images a user
select to upload.
Here you see an example with 2 images. It can be up to 50 images and I dont
want to write...
|
by: jaapkramer |
last post by:
I have a page with 641 images in it. Each image can be clicked with as
result that the image source will be changed. For this the images need
to have a unique ID. But to do this manually for 641 is...
|
by: Jim Michaels |
last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or
mysql.
I have not been able to do either. I get the same number back several times
from PHP's mt_rand() and from mysql's...
|
by: Jef Driesen |
last post by:
Suppose I have a datastructure (actually it's a graph) with one template
parameter (the property P for each edge and vertex):
struct graph<P>;
struct vertex<P>;
struct edge<P>;
I also have...
|
by: Corey Ellsworth |
last post by:
I have coded a class that uses the bitmap class to generate graphics from
True Type fonts. I'm using it primarily to render 3 of 9 barcodes from a
True Type font. When the exact same code is used...
|
by: wilkinson.philip |
last post by:
I have a javascript object which dynamically generates a table adding,
deleting and moving rows as the user clicks on buttons or links.
Problem is when I generate a table row and add the javascript...
|
by: Grant Edwards |
last post by:
I need to be able to generate a PDF report which consists
mostly of vector images (which I can generate as encapsulated
Postscript, PDF, or SVG). What I need is a way to combine
these figures...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |