On Oct 29, 2010, at 2:44 PM, Gary wrote:
"Adam Richardson" <simples...@gmail.com> wrote in message
On Fri, Oct 29, 2010 at 3:05 PM, Gary <gp...@paulgdesigns.com> 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

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



Thanks for your reply, that is my question, what is to replace ['src'] if I
am calling the image from a database.


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,
        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.

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to