Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

ThumbNails and WaterMarks OnTheFly


Recommended Posts

Hello.

 

Nice contrib. Very useful and very clever.

 

My hosting has GD enabled. Server info shows that:

 

gd

GD Support  enabled

GD Version  2.0 or higher

JPG Support  enabled

PNG Support  enabled

WBMP Support  enabled

 

But, when running the store, a problem:

- Images show as a broken source reference (just the placeholder appears, with the broken image icon)

- Clicking on the image give popups as usual, functioning well.

- ThumbNail image appears as ImageName.thumb.jpeg , shouldn't the ".jpg" replace the ".thumb"?

- Popup image is ImageName.jpg, functioning as expected.

 

= Again with the ThumbNail file name, why is the extension ".jpEg", and not ".jpg"?

 

Thanks for your help in this issue!

I am trying to find where did I missed a detail, or what I did wrong...

 

SGershon

If at first you don't succeed, you must be a programmer.

 

Tip Posted: Languageless Reviews

Link to comment
Share on other sites

  • Replies 87
  • Created
  • Last Reply

Top Posters In This Topic

Thank you :-)

 

Can you access a thumbnail directly?

 

i.e. call up http://your.web.site/images/ImageName.thumb ?

 

if this fails, or doesn't display a smaller picture, you've a problem with either the .htaccess or the thumbs.php file - check your error_log to find out which.

 

If it works directly, displaying a thumbnail, then your problem is likely to be the additional code in html_output.php misbehaving. The code I have here is:

 ? ?if ($image_size = @getimagesize($src)) {
? ? ? ?if (($width < 101 || $height < 81) && ($image_size[0] > 101 && $image_size[1] > 81 )) {
? ? ? ? ? ?$image = str_replace(".jpg",".thumb",$image);
? ? ? ?}
? ?}

which is just a quick replace of ".jpg" with ".thumb" if the image size required is as small as a thumbnail and the picture is bigger. if your image already ends jpEg, then obviously this replace won't work, and (presumably) nothing will happen...

Edited by irrelevant.com
Link to comment
Share on other sites

Thanks!

I should've tested the images by themselves before asking. Now I know.

 

When accessing the image directly by Mozilla, I receive a "The image "ImageName.thumb" cannot be displayed, because it contains errors.".

Mozilla writes in the browser title "ImageName.thumb (JPEG Image)".

 

IE, reveals the error:

<br />

<b>Warning</b>:  imagecreatefromjpeg(/path/to/site/images/100002_Suit_Black.jpg): failed to open stream: No such file or directory in <b>/path/to/site/thumb.php</b> on line <b>27</b><br />

<br />

<b>Warning</b>:  imagesx(): supplied argument is not a valid Image resource in <b>/path/to/site/thumb.php</b> on line <b>40</b><br />

<br />

<b>Warning</b>:  imagesy(): supplied argument is not a valid Image resource in <b>/path/to/site/thumb.php</b> on line <b>41</b><br />

<br />

<b>Warning</b>:  Division by zero in <b>/path/to/site/thumb.php</b> on line <b>42</b><br />

<br />

<b>Warning</b>:  Division by zero in <b>/path/to/site/thumb.php</b> on line <b>42</b><br />

<br />

<b>Warning</b>:  imagecreatetruecolor(): Invalid image dimensions in <b>/path/to/site/thumb.php</b> on line <b>50</b><br />

<br />

<b>Warning</b>:  imagecopyresized(): supplied argument is not a valid Image resource in <b>/path/to/site/thumb.php</b> on line <b>54</b><br />

<br />

<b>Warning</b>:  imagedestroy(): supplied argument is not a valid Image resource in <b>/path/to/site/thumb.php</b> on line <b>55</b><br />

<br />

<b>Warning</b>:  imagejpeg(): supplied argument is not a valid Image resource in <b>/path/to/site/thumb.php</b> on line <b>62</b><br />

<br />

<b>Warning</b>:  imagedestroy(): supplied argument is not a valid Image resource in <b>/path/to/site/thumb.php</b> on line <b>66</b><br />

 

So it seems .htaccess is working, as it redirects to thumb.php.

thumb.php is what I downloaded with the contrib, without modifications.

 

Error lines in thumb.php are:

27 -- $main_img = imagecreatefromjpeg($mimage);

40 -- $width = imagesx($main_img);

41 -- $height = imagesy($main_img);

42 -- $scale = min($MAX_WIDTH/$width, $MAX_HEIGHT/$height);

50 -- $tmp_img = imagecreatetruecolor($new_width, $new_height);

53,54 -- imagecopyresized($tmp_img, $main_img, 0, 0, 0, 0,

            $new_width, $new_height, $width, $height);

55 -- imagedestroy($main_img);

62 -- imagejpeg($main_img);//(6)

66 -- imagedestroy($main_img);

 

I'm having difficulty on understanding where all this is pointing to.

Thank you for your ideas!

 

SGershon

If at first you don't succeed, you must be a programmer.

 

Tip Posted: Languageless Reviews

Link to comment
Share on other sites

This is weird:

<b>Warning</b>:  imagecreatefromjpeg(/path/to/site/images/100002_Suit_Black.jpg): failed to open stream: No such file or directory in <b>/path/to/site/thumb.php</b> on line <b>27</b><br />

 

I have this file, on this directory.

Actually, the absolute path was automatic, so I guess it's right.

What can be wrong? Why isn't $mimage correct?

If at first you don't succeed, you must be a programmer.

 

Tip Posted: Languageless Reviews

Link to comment
Share on other sites

That certainly seems to be where the error lies; it can't find the file it's been passed as a parameter. However it's passed it by the .htaccess redirect as the local path to the file you actually requested.

 

Try calling it direct:

This will allow you to play with the path name to see what's going on

... it might be that the account your web server runs the php as does not have permissions to traverse the directory structure all the way from / .. you might be able to access it another way, in which case you can adjust the redirect accordingly.

 

Rob

Link to comment
Share on other sites

I've written a similar script to create thumbnails but the php functions imagecreatetruecolor and such seem to crap out with images that have a fourth alpha channel. I've been reading other forums and there doesn't seem to be a php work around. Has anyone noticed this problem? Anyone have any thoughts on this?

Link to comment
Share on other sites

I'm having a strange problem:

I installed the thumb part which worked great. I then instaled the watermark part and set thumb.php

$watermark = "1";

which gives me a missing thumb. When I access the image directly it shows up correct with the watermark. The thumb will not show with watermark enabled. Is there something I'm missing?

Link to comment
Share on other sites

jantunes, does the thumb appear at all? What do you mean by missing thumb?

gives me a missing thumb.

 

It's not clear to me if the problem is that:

- the thumb appears, but without the watermark on it. Or:

- when watermark is enabled, the thumbnail does not work at all.

If at first you don't succeed, you must be a programmer.

 

Tip Posted: Languageless Reviews

Link to comment
Share on other sites

Try calling it direct:
http://your.site.name/thumbs.php?/path/to/site/images/100002_Suit_Black.jpg

This will allow you to play with the path name to see what's going on.

:D Rob, great sugestion, again! It is realy useful.

 

I am on a shared host, so it seems to be a "Complete" path, like:

/home/Me_On_the_Host/home/www/Here_is_the_Site

And a "Short" path, that is:

/home/www/Here_is_the_Site

By playing with the path, I saw that .htaccess is passing the "Complete" path, and thumb.php is expecting the "Short" path.

 

So I modified thumb.php like this:

$mimage=str_replace('/home/Me_On_the_Host','',$QUERY_STRING);
$mimage=str_replace(".thumb",".jpg",$mimage);

Now it's working fine! BUT:

 

1) Generated images are still named: ImageName.thumb.jpeg

Is that intended?

 

2) Generated images are displayed weird, that is: An image that is generated as (for example) 45x80 pixels, page is displaying it as:

<img src="images/ImageName.thumb" border="0" alt="Image Name" title=" Image Name " width="100" height="177.04545454545">
I think the problem is in html_output.php, over here:
if (tep_not_null($width) && tep_not_null($height)) {

  $image .= ' width="' . tep_output_string($width) . '" height="' . tep_output_string($height) . '"';

}

:huh: Can you point me in the direction to solve it?

 

Thanks again for all the support!

SGershon

If at first you don't succeed, you must be a programmer.

 

Tip Posted: Languageless Reviews

Link to comment
Share on other sites

Well, it seems that you are required to set, in admin, the smaller setting from thumb.php. That is, if you set thumb.php to deal with width 100 and height 80, set height 80 and leave width blank in admin.

If at first you don't succeed, you must be a programmer.

 

Tip Posted: Languageless Reviews

Link to comment
Share on other sites

Congrats in finding out the path issue.

 

I've got height/width set in admin as 100/80 to match the thumbnail size, but all my images are sized to that ratio already (just bigger). If you typically use different sizes, or want to calculate them on the fly based on the original image size, you can edit thumb.php accordingly - the sizes are set within there.

 

As for the .thumb.jpeg - are your images all called .jpeg or just .jpg ? html_output.php swaps in .thumb for .jpg, and thumb.php swaps back .jpg for .thumb to find the file - if you are using alternate file extensions you might have problems, and need to create some alternates

 

e.g. (thinking aloud here) if you use both .jpg and .jpeg on your site:

 

add an extra replace in html output to replace .jpeg with (say) .thump

 

copy thumbs.php to thump.php.

edit it and change the replace to put back .jpeg for .thump

 

edit the .htaccess and add an extra line to redirect files ending .thump to thump.php

 

that should then use an alternate extension for the .jpeg, and work...

 

In the long run it MIGHT be easier to do something to just add .thumb to the end of the filename, and some more interesting work within thumbs.php to determine original filename, to allow for use of GIFs, PNG, etc. But I wrote this originally for my own use on a site where our product images are exclusively named *.jpg as a quick fix following the theft of some of our pictures and their use on eBay.

Link to comment
Share on other sites

The only other thing I can think about here is that somewhere something else is adding the .jpeg to the .thumb.

 

Where exactly are you seeing this? The <img src snippet you quote doesn't mention .jpeg..

Edited by irrelevant.com
Link to comment
Share on other sites

The thumb works good by itself. When I add the watermark part, the thumb gives back a broken link. When i click on that link, the larger jpg WITH the watermark appears. It's the watermarked thumb that's giving a broken link.

If I access the jpg directly from the browser, it shows up correctly with the watermark.

Link to comment
Share on other sites

HI all

 

I am not quite use how the watermark should work, but it doesn't work in my site..

 

I have puto the files how it said in readme.txt

 

anywhere the image.php + watermark.png

water.htaccess where are the images which I like to watermark....

 

Do I have do to anything else?

 

I have the big image in a different directory the the small.

 

images/images_big/

 

I have little modification in the popup, and I like to watermark the popup..

 

Should it work?

 

Salvo

Link to comment
Share on other sites

Hello Everyone,

 

I would like to know how to install this contribution:

 

Please walk me thru the installation processes, I installed a lot of the Oscommerce on my website which you can see here: My Shop

 

but I need help with installing this the ThumbNails and WaterMarks OnTheFly contribution:

 

I really appreciate your time and help on this matter:

Link to comment
Share on other sites

The only other thing I can think about here is that somewhere something else is adding the .jpeg to the .thumb.

Where exactly are you seeing this?  The <img src snippet you quote doesn't mention .jpeg...

Hi Rob!

Thanks for your answer, and excuse my delay.

 

All my images are .jpg.

I don't know who is inserting the .jpeg...

 

The weird thing is that it seems to override

$mimage=str_replace(".thumb",".jpg",$mimage);

because not only that the extension is .JPEG, the .thumb is not taken out from the filename.

 

Maybe... thumb.php is not receiving the filename well, and imagecreate is inserting the .jpEg? Can it be?

 

 

And

In the long run it MIGHT be easier to do something to just add .thumb to the end of the filename, and some more interesting work within thumbs.php to determine original filename, to allow for use of GIFs, PNG, etc.
may be a real nice idea. I cannot promice, but it seems something my poor PHP skills can handle, so I may contrib this in the future.

 

Thanks for your nice work.

 

SGershon

If at first you don't succeed, you must be a programmer.

 

Tip Posted: Languageless Reviews

Link to comment
Share on other sites

To the users asking for instructions:

Instructions can be found in readme.txt.

Use only the simple installation if your OSC is a brand new installation.

If you have any MOD, use the advanced instructions. They are quite straightforward.

If at first you don't succeed, you must be a programmer.

 

Tip Posted: Languageless Reviews

Link to comment
Share on other sites

To the users asking for instructions:

Instructions can be found in readme.txt.

Use only the simple installation if your OSC is a brand new installation.

If you have any MOD, use the advanced instructions. They are quite straightforward.

HI,

 

I can't see the Advanced instructions in the download area......

t

I am after the watermark only

sorry..

 

Salvo

Edited by Salvo
Link to comment
Share on other sites

Hi Salvo,

If all you want is the watermarks, you just need to put the .htaccess in your images_big folder. Make sure that the path to images.php within the .htaccess is correct for wherever you put that file. No mods to osc itself are needed for just this.

 

Shmuel,

I really have no idea where the jpeg is coming from... :-( maybe do a grep across the php files see if you can see where it's referred to?

 

Fadel,

I was rather hoping the installation notes were simple enough. There is only one code change to osc for to make it use the thumbnails, the rest is standalone php files and a redirect to them in the Apache .htaccess files. If you have any problems with installing this, please do let me know.

 

 

Rob,

Link to comment
Share on other sites

Rob,

I dont think the problem is in other files.

 

This Weekend, I'll try to debug thumb.php by having it print to a file what is happening to the file name through the execution.

I think that there is something wrong in the way my server is passing teh names.

I'll have you updated of any news.

 

I also think the installation is pretty easy. But, if people are not understanding the instructions, let's try to make them easier. In my spare time.

I think this solution is so cool in its simplicity, that it should be merged in the core OSC.

 

SGershon

If at first you don't succeed, you must be a programmer.

 

Tip Posted: Languageless Reviews

Link to comment
Share on other sites

I have the same broken image deal as first mentioned. when looking into my logs. they mention thumbs.php..The file is named thumb.php. IS there supposed to be an "s" THUMBS instead of THUMB.php

 

anyone else know what I mean

 

home/mypath/www/thumbs.php

 

/thumbs.php?/~mypath/home/www/images/image.jpg

 

Also, where it says mypath one has a '~' and one does not..

 

is that what is causing the broken images?

Link to comment
Share on other sites

Okay, i give up for now..it

seems the problem is the path.

 

home/mypath/www/thumbs.php

 

/thumbs.php?/~mypath/home/www/images/image.jpg

 

For some reason it is switching the path around

 

the absolute path is correct, but when reading the short path, it switches "home" and "mypath". ideally, the short path could just read home/public_html and have no need for ~mypath.

 

any ideas

Link to comment
Share on other sites

I went into includes/functions/html_output.php and changed

 

$image = str_replace(".jpg",".thumb",$image);

 

to

 

$mimage = str_replace(".jpg",".thumb",$mimage);

 

 

Basically added the m before image. Not sure why, but this lets all the thumbnails show up and with watermarks..I guess I will stick with this until I find another fix.

Link to comment
Share on other sites

Hi Daniel.

 

The .php files can be called anything you like, they are only referred to by the .htaccess file you add to your images folder, so it needs to be in step with that, but that's all. (indeed, probably best you do change the name and make it obscure..)

 

I don't know why the path would be being altered.... it should be passed the full path to the file.. it might be something in your apache config that's rewriting it....

 

Why did you pick mimage to replace image? Has there been a change of name in the subroutine elsewhere?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...