Re: Watermark with GD

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Tamara Temple" <tamouse.lists@xxxxxxxxx> wrote in message 
news:7F666311-4BC8-4064-8C70-4F2597E7BF7F@xxxxxxxxxxxx
> On Oct 29, 2010, at 2:44 PM, Gary wrote:
>> "Adam Richardson" <simpleshot@xxxxxxxxx> wrote in message
>> news:AANLkTi=keNXt7yEwrZtcm4+hyifRLQhOZxSe7Ufmqjp=@xxxxxxxxxxxxxxxxx
>> On Fri, Oct 29, 2010 at 3:05 PM, Gary <gpaul@xxxxxxxxxxxxxxxx> 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
>
Tamara

Thanks for your reply.  The image is already called, (and if you read the 
response I posted to tedd, you'll see I am now not sure how it is). I also 
posted the code that calls the image if that sheds any light.

I am digesting all the information to get it to work, if any of the code 
changes your answer, I would love to hear it!

Thank you again.

Gary 



__________ Information from ESET Smart Security, version of virus signature database 5576 (20101029) __________

The message was checked by ESET Smart Security.

http://www.eset.com





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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux