php-general Digest 30 Oct 2010 13:58:40 -0000 Issue 7012
Topics (messages 309145 through 309148):
Re: Watermark with GD
309145 by: Adam Richardson
309146 by: Gary
309147 by: Tamara Temple
309148 by: tedd
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
On Fri, Oct 29, 2010 at 3:05 PM, Gary <[email protected]> wrote:
> I am trying to get the watermark to work, however I am having a problem in
> that the image is being called from a database (image sits in images file).
>
> The script in question is this
>
> $image = imagecreatefromjpeg($_GET['src']);
>
> However it produces an error message of
>
> Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: Filename
> cannot be empty in /home/content/a/l/i/alinde52/html/imagesDetail.php on
> line 233
>
First things first. It looks like there's nothing in $_GET['src'].
>From where are you getting the value 'src'?
Adam
--
Nephtali: PHP web framework that functions beautifully
http://nephtaliproject.com
--- End Message ---
--- Begin Message ---
"Adam Richardson" <[email protected]> wrote in message
news:[email protected]...
On Fri, Oct 29, 2010 at 3:05 PM, Gary <[email protected]> wrote:
> I am trying to get the watermark to work, however I am having a problem in
> that the image is being called from a database (image sits in images
> file).
>
> The script in question is this
>
> $image = imagecreatefromjpeg($_GET['src']);
>
> However it produces an error message of
>
> Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: Filename
> cannot be empty in /home/content/a/l/i/alinde52/html/imagesDetail.php on
> line 233
>
First things first. It looks like there's nothing in $_GET['src'].
>From where are you getting the value 'src'?
Adam
**
Adam
Thanks for your reply, that is my question, what is to replace ['src'] if I
am calling the image from a database.
Gary
__________ Information from ESET Smart Security, version of virus signature
database 5575 (20101029) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--- End Message ---
--- Begin Message ---
On Oct 29, 2010, at 2:44 PM, Gary wrote:
"Adam Richardson" <[email protected]> wrote in message
news:[email protected]...
On Fri, Oct 29, 2010 at 3:05 PM, Gary <[email protected]> wrote:
I am trying to get the watermark to work, however I am having a
problem in
that the image is being called from a database (image sits in images
file).
The script in question is this
$image = imagecreatefromjpeg($_GET['src']);
However it produces an error message of
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]:
Filename
cannot be empty in /home/content/a/l/i/alinde52/html/
imagesDetail.php on
line 233
First things first. It looks like there's nothing in $_GET['src'].
From where are you getting the value 'src'?
Adam
**
Adam
Thanks for your reply, that is my question, what is to replace
['src'] if I
am calling the image from a database.
Gary
I'd really need to know more about this application to help. If you
are calling the image from a database (does this mean you have the
image's file spec saved in the database, or you actually storing the
image data in the database?), you need to use a query to do that. Is
the imagesDetail.php script being called by something else that
already queried the database and put the file spec in the src query
string argument? Before you dump the query string argument directly
into the imagecreatefromjpeg() funciton, you should verify that it
exists:
if (isset($_GET['src'[) && (!empty($_GET['src'[) {
$src = $_GET['src'];
if (fileexists($src)) {
$image = imageceatefromjpeg($src);
if ($image === FALSE) {
# process error from imagecreatefromjpeg
}
} else {
# process missing image
}
} else {
# process missing query string parameter
}
This is all prediated on the idea that something is calling your
imageDetail.php script with the source path for the image in question.
If that is not the case, and you need to in fact query the database
for the source path of the image, then you need to do a database query.
Not knowing anything about how your database is set up, I'll take a
stab at a generic method of doing it.
Somehow, imageDetail.php needs to know what image to get. Let's assume
you are calling it from a gallery that has several images displayed.
Part of the information needed is some what to identify the image's
record in the database. Let's assume you have images stored with an
id, that is not null and autoincrements when you store a new image.
Here's a sample schema:
CREATE TABLE `photos` (
`id` INT AUTO_INCREMENT NOT NULL,
`src` VARCHAR(255) NOT NULL,
`created` TIMESTAMP NOT NULL DEFAULT 0,
`updated` TIMESTAMP NOT NULL DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP
PRIMARY KEY (`id`)
);
Of course, you would probably want to store a lot more info about an
image, but this will do for explanation.
Let's say you have a gallery shown at your application's index.php
program. In the html it generates, you may have something like this
for any particular thumbnail:
<a href="imageDetail.php?id=25"><img src="thumbs/imageABC.jpg"></a>
This is making some assumptions:
* you have image thumbnails for each image stored in the
subdirectory thumbs/
* you've figured out somehow that the id for thumbs/imageABC.jpg is
25
When the user clicks on the image, they get taken to your
imageDetail.php script, with the query string paramter id set to 25.
In PHP you would then do:
if (isset($_GET['id'] && (!empty($_GET['id'] &&
is_numeric($_GET['id']) {
$id = $_GET['id'];
$sql = "SELECT * FROM `photos` WHERE id=".$id." LIMIT 1";
$result = mysql_query($sql,$db);
if ($result) {
$imagedata = mysql_fetch_array($result,MYSQL_ASSOC);
$src = $imagedata['src'];
if (isset($src) && !empty($src) && fileexists($src)) {
$image = imagecreatefromjpeg($src);
# do stuff with image
} else {
# handle invalid src data
}
} else {
# handle error from query
}
} else {
# handle invalid id paramter on script
}
Note: some people like to handle error conditions before moving on to
working with the successful state. It's a matter of style. Either works.
Hope this helps.
Tamara
--- End Message ---
--- Begin Message ---
At 3:05 PM -0400 10/29/10, Gary wrote:
I am trying to get the watermark to work, however I am having a problem in
that the image is being called from a database (image sits in images file).
The script in question is this
$image = imagecreatefromjpeg($_GET['src']);
However it produces an error message of
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: Filename
cannot be empty in /home/content/a/l/i/alinde52/html/imagesDetail.php on
line 233
I have tried various methods, for example: ($_GET ['images/'] or ($_GET
['images/$row_WADAimages["image_id"]].
Can anyone shed some light on this for me.
Thank you
Gary
Gary:
Several things.
1. Getting an image from a database? You mean that you are getting
the path of the image in the file system, right?
Side note: You could place the image inside the database using a BLOB
and do away with the path all together. That has the benefit of being
portable -- you simply move the database to where ever you want it.
The downside is that the database becomes very large, but no more so
that the file system. There are pro's and con's in storing actual
images in a database.
2. Using a GET is not the way to get the path. Instead, you have to
retrieve the path from the database table where the path is stored --
and that requires a MySQL query similar to "SELECT * FROM <database>
WHERE id=<whatever>". There are lot's of examples of how to pull data
from a database.
3. After getting the path, then you can create the watermark like so:
http://webbytedd.com/b/watermark/
Hope this helps,
tedd
--
-------
http://sperling.com/
--- End Message ---