Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

ThumbNails and WaterMarks OnTheFly


Recommended Posts

  • Replies 87
  • Created
  • Last Reply

Top Posters In This Topic

I am using this contribute, but I need to make it so it uses a different watermark image for images that height are larger and width are smaller.

in image.php, try something like:

 

just before the line

//Loading
$watermark_img = imagecreatefrompng($wmark);

 

add:

$mi_size = getimagesize($mimage);

if ($mi_size[1] > 400 ) {                   // if taller than 400 pixels
   $wmark='watermark1.png';                 // use one image
} else {                                   // else
   $wmark='watermark2.png';                // use another
}

 

Obviously you can adjust or add as many tests as you want...

 

I'm still trying to find time to make the other mods people have requested... :=( why are there insufficient hours in the day?

Link to comment
Share on other sites

  • 2 weeks later...
Do you see a problem with my settings and your contribution?  I am not sure why I am having troubles with your contribution, or the other contribution I installed, which is "OnTheFly_GDThumbs_1_5" by Nate Welch.  Have you seen this contribution?  What are the differences (besides the fact that yours uses .htacces and includes watermarks?)

 

Thanks for the great support.  I was really excited to see that you had responded in less than one day to my earlier queston!

 

Yes.

Rob is a really nice man :)

 

This contribution, by using the .htaccess, is much more smart than the other contrib. And it is a very clean solution to a powerfull result.

As Rob states, you or your affiliates can refer to the pictures from outside the store and they will show thumbnailed!

 

Myself, I installed it in the last time, and after a little struggling, got it working beautifully.

:blush: Meanwhile, I just re-builded the store, migrated hosting, "gave birth" to twins, and performed my reserva service on the army. So I'll install it all again from the beginning. :P

 

SGershon

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

 

Tip Posted: Languageless Reviews

Link to comment
Share on other sites

GAH

 

I installed thsi contribution 2 weeks ago, got it working (great contribution by the way), but I accidently nuked all my .htaccess files, and I also changed domain names. So when I go to reinstall this contribution, I start running into a weird error:

 

Imagine that you have installed the thumb.php directly into your images folder and are making calls to it there. Also imagine you have two images, somename.jpg, and some name.jpg (the difference being that one has a space in it and one doesn't)

 

apparently when I open a jpg like this:

 

http://[path/to/]thumb.php?[/path/to/site]/images/somename.thumb

 

it opens and resizes correctly, however when I open a jpg that has a space in it:

 

http://[path/to/]thumb.php?[/path/to/site]/images/some&20name.thumb

 

I get this error:

<br />

<b>Warning</b>: imagecreatefromjpeg(autum%202004%203%20019.jpg): failed to open stream: No such file or directory in <b>/home/neen/public_html/catalog/images/thumb.php</b> on line <b>27</b><br />

 

:blink:

 

apprently imagecreatefromjpeg() can't handle spaces now, and I have NO idea why this could be. I mean, I had it working fine with spaces and all less then a week ago, and the changes that were made were the following:

 

1) all my htaccess's were destroyed (shouldn't have any effect on the test I was doing)

2) my host installed SSL for my space (again, no effect)

3) I changed my addon domain to be my main domain so that I could use SSL with it.

 

What could the problem be? I have no idea what I should do at this point....

Link to comment
Share on other sites

when I open a jpg that has a space in it:

<b>Warning</b>:? imagecreatefromjpeg(autum%202004%203%20019.jpg): failed to open stream: No such file or directory in <b>/home/neen/public_html/catalog/images/thumb.php</b> on line <b>27</b><br />

 

off the top of my head, try changing

$mimage=$QUERY_STRING;

to

$mimage=rawurldecode($QUERY_STRING);

 

in each script ...

 

this should turn the %20 back into a space.

 

.... in my experience, spaces in filenames, machine names, windows share names, etc. are a major pain in the neck and should be avoided wherever possible.

 

Rob

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

off the top of my head, try changing

$mimage=$QUERY_STRING;

to

$mimage=rawurldecode($QUERY_STRING);

 

in each script ...

 

this should turn the %20 back into a space.

 

.... in my experience, spaces in filenames, machine names, windows share names, etc. are a major pain in the neck and should be avoided wherever possible.

 

Rob

 

Can I just say that your a genius?? Off the top of your head, none the less.

 

What I don't understand is why it started acting up the 2nd time around installing it..... that just doesn't make sense to me, I'm still with the same host, although I was moved to a different shared ip... odd.

 

heres another question: What If I want to increased the quality of the thumbnails? The edges are a bit jagged on my site (http://www.martinadesigns.com/catalog/index.php?cPath=21) I bet you could create slightly bigger thumbnails then you plan to display, so that the file size would increase some but so would the quality. I think you can use imagecopyresampled() maybe?

 

I also saw that imagejpeg() can have 3 arguments, so that you could use

imagejpeg($main_img, "", 100) What do you think??

Link to comment
Share on other sites

<{POST_SNAPBACK}>Can I just say that your a genius??  Off the top of your head, none the less.
Well, let's just say that we could build a fan-club. :lol:
<{POST_SNAPBACK}>What I don't understand is why it started acting up the 2nd time around installing it... that just doesn't make sense to me, I'm still with the same host, although I was moved to a different shared ip... odd.
From my experience, host settings are just like the butterfly effect: "A butterfly flapping its wings starts a chain reaction of events that can result in a hurricane on the other side of the planet."

Unless, of course, if you are the sole admin of the server, it stays at your home, and you built it yourself installing each one of the programs yourself. Commercial hosts, specially shared hosting, can have weird things hapenning even if you did not change anything on it. People changing setting, and more than all, admins updating programs and resetting servers can turn your work upside down.

<{POST_SNAPBACK}>Heres another question:  What If I want to increased the quality of the thumbnails?
This is going to be good...

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

 

Tip Posted: Languageless Reviews

Link to comment
Share on other sites

I also saw that imagejpeg()? can have 3 arguments, so that you could use

imagejpeg($main_img, "", 100)? What do you think??

 

well, according to http://uk2.php.net/imagejpeg , that puts quality up from the default of 75 to the max of 100, so I would say yes, try it first.

 

As for making the image slightly larger than required... just edit the settings for MAX_WIDTH and MAX_HEIGHT - these would normally match the thumbnail sizes as set in your osc admin - if you make them bigger, then obviously you'll be sending more to the browser, and it'll squash it down a bit (though not as much as it would for the full size image of course!)

 

I havn't played with imagecopyresampled(), but reading the man pages again, yes, it should improve thngs. Just substitute it for imagecopyresized() - the parameter list looks the same. Let me know if you try using it, and how it turns out!

 

Rob.

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

well, according to http://uk2.php.net/imagejpeg , that puts quality up from the default of 75 to the max of 100, so I would say yes, try it first. 

 

I tried this: I didn't notice a differnece and my image sizes were jacked up to 44k from 8k. I do not suggest doing it.

 

 

As for making the image slightly larger than required... just edit the settings for MAX_WIDTH and MAX_HEIGHT - these would normally match the thumbnail sizes as set in your osc admin - if you make them bigger, then obviously you'll be sending more to the browser, and it'll squash it down a bit (though not as much as it would for the full size image of course!)

 

Didn't need to try this. See the next quote.

 

I havn't played with imagecopyresampled(), but reading the man pages again, yes, it should improve thngs.  Just substitute it for imagecopyresized() - the parameter list looks the same.  Let me know if you try using it, and how it turns out!

 

OH MAN. This made all the difference. My images look 100% better at no additional cost for size. I think you should seriosly consider writing this into your next update, cuz after I did it my inventory looked so good I didn't need to increase the image size and reshrink it. And all I had to do was change imagecopyresized to imagecopyresampled. Booya.

 

Thanks a ton again!

Link to comment
Share on other sites

  • 1 month later...

I installed this contribution's thumbnail part, it works in general, but on some pages images are not thumbnailed.

 

What can it be?

 

Also, I have Additional images 1.1 and Keep_Image_Proportions mods installed. I noticed, that additional images are not processed.

 

How can I make the additional images thumbnailed?

Link to comment
Share on other sites

I installed this contribution's thumbnail part,  it works in general, but on some pages images are not thumbnailed.

 

What can it be?

 

Also, I have Additional images 1.1 and Keep_Image_Proportions mods installed. I noticed, that additional images are not processed.

 

How can I make the additional images thumbnailed?

 

If you view-source on the page as displayed in your browser, are the images referred to as *.jpg or *.thumb ?

 

There are two parts to the mod; the routine to process and display the thumbs, which will kick in for any jpg which is called up with .thumb instead, and the mod to osc which spots that a jpg is bigger than it needs to be, and replaces the file extension with .thumb when it is accessed.

 

The osc mod is in a subroutine in general.php (I think; it's been a while...) so should be called by anything displaying a jpg. It's possible that the additional images mod does not use this subroutine though, and instead displays the <IMG tags directly, I don't know, having not delved into it. If you are still seeing .jpg and not .thumb in the source, then you just need to do a str_replace in that routine along the lines of the mod to general.php as described in the readme.

Link to comment
Share on other sites

Yes, there is no .thumb extension on the images which are not resampled.

 

The additional images uses tep_image also for calling the images

 

<!-- additional_images //-->
<table width="100%">
  <tr>
    <td>

<?php
 $info_box_contents = array();
 $row = 0;
 $col = 0;
 while ($new_products = tep_db_fetch_array($images_product)) {
   $info_box_contents[$row][$col] = array('align' => 'center',
                                          'params' => 'class="smallText" width="33%" valign="top"',
                                          'text' => '<a href="javascript:popupWindow(\'' . tep_href_link(FILENAME_POPUP_ADD_IMAGE, 'imagesID=' . $new_products['additional_images_id']) . '\')">' . tep_image(DIR_WS_IMAGES . $new_products['medium_images'], $new_products['images_description'], DISPLAY_IMAGE_WIDTH, DISPLAY_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '<br>' . TEXT_CLICK_TO_ENLARGE . '</a>'
                                         );
   $col ++;
   if ($col > 2) {
     $col = 0;
     $row ++;
   }
 }
 new imagesBox($info_box_contents);
?>
    </td>
  </tr>
</table>
<!-- additional_images_eof //-->

The name of image file called is taken from datatable and is stored as 'medium images'

Link to comment
Share on other sites

I need help with the apache or htaccess configuration.

I installed the contribution, and it works on my server and home computer, but I can't make it working on my office computer.

 

Links like

http://172.18.4.1:82/thumb.php?img/75kwksiweb.thumb

are displayed as thumbs but links like

http://172.18.4.1:82/img/75kwksiweb.thumb are not.

 

The only difference I noticed in my apache configurations is that I use port number in the office. I suppose that thу problem can be fixed by right virtual servers configurations (or may be I am wrong), but I don'tknow how to do that.

 

Can anybody advise?

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

Guys! If anyones still watching this topic, i need help :(

 

Going over the readme.txt file and what has been said on this thread....

 

You will need GD graphics compiled into PHP.? My FreeBSD4.8 stock distribution

did not have this, but the 5.2 did, so you will best check your system.

 

This uses apache redirect rules in .htaccess.? I have no idea if you can

achieve similar on other platforms.

 

This from what i've read means my host needs to have the GD Library enabled which it is.. So i carried on.

 

For thumbnails only:

 

copy thumb.php somewhere conveniant.

copy thumb.htaccess as .htaccess into your html root folder.

(or add contents to an existing .htaccess)

- amend path to thumb.php if you do not put it in html root.

 

Ok, so what ive done here is copy the thumb.php to the /catalog root folder (this is ok?)

 

I've already got a .htaccess file on /catalog so i've edited this and added the following code as described in the readme file.. then uploaded it into the same place (/catalog)

 

RewriteEngine ?on
RewriteRule	^(.*)\.thumb ?/thumb.php?%{REQUEST_FILENAME}

 

So again i carried on (not 100% certain that what ive already done is correct)

 

Now, to make oscommerce use it -

 

in /catalog/includes/functions/html_output.php

in function tep_image()

just before: if (tep_not_null($width) && tep_not_null($height))

add:

 

// Rob04 - kick in on-the-fly thumbnail generator if required image is thumbnail

// and supplied image is larger.

? ? if ($image_size = @getimagesize($src)) {

? ? ? ? if (($width < 101 || $height < 81) && ($image_size[0] > 101 && $image_size[1] > 81 )) {

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

? ? ? ? }

? ? }? ? 

// 101 & 81 refer to settings in thumb.php

// EndRob04

 

This is the bit i got stuck on mainly, but now ive got it to a point where the thumbnails are actually displaying the correct path but its trying to read them as .thumb and not .jpg ?

 

My html_output reads this:

 

////
// The HTML image wrapper function
function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '') {
? if ( (($src == '') || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) {
? ? return false;
? }

// alt is added to the img tag even if it is null to prevent browsers from outputting
// the image filename as default
? $image = '<img src="' . $src . '" border="0" alt="' . htmlspecialchars($alt) . '"';

? if (tep_not_null($alt)) {
? ? $image .= ' title=" ' . htmlspecialchars($alt) . ' "';
? }

? if ( (CONFIG_CALCULATE_IMAGE_SIZE == 'true') && ((!$width) || (!$height)) ) {
? ? if ($image_size = @getimagesize($src)) { 
? ? ? if ( (!$width) && ($height) ) {
? ? ? ? $ratio = $height / $image_size[1];
? ? ? ? $width = $image_size[0] * $ratio;
? ? ? } elseif ( ($width) && (!$height) ) {
? ? ? ? $ratio = $width / $image_size[0];
? ? ? ? $height = $image_size[1] * $ratio;
? ? ? } elseif ( (!$width) && (!$height) ) {
? ? ? ? $width = $image_size[0];
? ? ? ? $height = $image_size[1];
? ? ? }
? ? } elseif (IMAGE_REQUIRED == 'false') {
? ? ? return false;
? ? }
? }

? if ( ($width) && ($height) ) {
? ? $image .= ' width="' . $width . '" height="' . $height . '"';
? }

// Rob04 - kick in on-the-fly thumbnail generator if required image is thumbnail
// and supplied image is larger.
? if ($image_size = @getimagesize($src)) {
? ? ? if (($width < 101 || $height < 81) && ($image_size[0] > 101 && $image_size[1] > 81 )) {
? ? ? ? ? $image = str_replace(".jpg",".thumb",$image);
? ? ? }
? } ?
// 101 & 81 refer to settings in thumb.php 
// EndRob04

? if (tep_not_null($parameters)) $image .= ' ' . $parameters;

? $image .= '>';

? return $image;
}

////

 

So this is where i'm upto. I've put the original backup files back on because i couldnt get it to work as they only displayed as an image place holder because as i said its trying to display them as .thumb and not .jpg

 

Any ideas? I just dont know what ive done wrong (if anything) and how to fix it. I just want the thumbnail part of this working on www.componentsuk.co.uk:( :( :( :( :( :( :(

Edited by sp_
Link to comment
Share on other sites

  • 1 month later...

Hi

Probably a dumb question, but is it possible to use ONLY the watermark instead of the thumbnailer? If so, are there any changes that need to be done in the code?

Teresa :blush:

Link to comment
Share on other sites

  • 4 weeks later...

I use this contribution on my current server and it works great - I am in the process of moving server and web host and cant get it to work on the new box! I have copied over all the files as a straight copy so I dont think its a configuration issue.

 

At the moment I have thumbnails not displaying but they are being directed to a .thumb file so I end up with lots of boxes with broken links. The large image (jpg) does work but now doesnt watermark - at the moment I dont have the .htaccess file set up because as soon as I do none of the images work properly even the jpg version if I type the full url into my browser.

 

Without .htaccess I can refer to a file using image.php?images/2into1f.jpg and it watermarks properly but on my main site it doesnt. I cant access a file using thumb.php?images/2into1f.jpg and if I try I get:

 

<br />

<b>Warning</b>: imagecreatefromjpeg(images/2into1f.thumb): failed to open stream: No such file or directory in <b>/home/MYSITE/public_html/catalog/thumb.php</b> on line <b>28</b><br />

<br />

<b>Warning</b>: imagecopymerge(): supplied argument is not a valid Image resource in <b>/home/MYSITE/public_html/catalog/thumb.php</b> on line <b>34</b><br />

<br />

<b>Warning</b>: imagesx(): supplied argument is not a valid Image resource in <b>/home/MYSITE/public_html/catalog/thumb.php</b> on line <b>41</b><br />

<br />

<b>Warning</b>: imagesy(): supplied argument is not a valid Image resource in <b>/home/MYSITE/public_html/catalog/thumb.php</b> on line <b>42</b><br />

<br />

<b>Warning</b>: Division by zero in <b>/home/MYSITE/public_html/catalog/thumb.php</b> on line <b>43</b><br />

<br />

<b>Warning</b>: Division by zero in <b>/home/MYSITE/public_html/catalog/thumb.php</b> on line <b>43</b><br />

<br />

<b>Warning</b>: imagecreatetruecolor(): Invalid image dimensions in <b>/home/MYSITE/public_html/catalog/thumb.php</b> on line <b>51</b><br />

<br />

<b>Warning</b>: imagecopyresized(): supplied argument is not a valid Image resource in <b>/home/MYSITE/public_html/catalog/thumb.php</b> on line <b>55</b><br />

<br />

<b>Warning</b>: imagedestroy(): supplied argument is not a valid Image resource in <b>/home/MYSITE/public_html/catalog/thumb.php</b> on line <b>56</b><br />

<br />

<b>Warning</b>: imagejpeg(): supplied argument is not a valid Image resource in <b>/home/MYSITE/public_html/catalog/thumb.php</b> on line <b>63</b><br />

<br />

<b>Warning</b>: imagedestroy(): supplied argument is not a valid Image resource in <b>/home/MYSITE/public_html/catalog/thumb.php</b> on line <b>67</b><br />

 

This is so frustrating as I have it working on my current host so Im thinking its something to do with the new server but I have had the web host reinstall GD in case that was the problem - can anyone give me some guidance as without this my site will be so slow I may as well pack up and go home!

 

TIA

 

Jase

Link to comment
Share on other sites

  • 2 weeks later...

does anyone still follow this formn ??? have been trying to install the watermarks mod, but it is not happening for me..i am running MOPICS and can't seem to get anything to work...any help would be great

Link to comment
Share on other sites

I am running MOPICS and can't seem to get anything to work...any help would be great

I don't use MoPics, not know its structure.

But probably you should change the image calling function of MoPics as well.

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

 

Tip Posted: Languageless Reviews

Link to comment
Share on other sites

I just installed this and I just wanted to say that after almost pulling all my hair trying to get the other auto thumbnailers to work for days to no avail, it was awesome to find this and it be so easy and work so well. Thanks a lot.

Samuel Mateo, Jr.

osC 2.2 MS2

Installed Mods:

WYSIWYG HTMLArea 1.7 | Basic Template System 1.0 | osC-Affiliate | OSC-SupportTicket

Featured Products 1.3 | LoginBox 5.2 | LatestNews 1.1.3 | Extras for IE

Link to comment
Share on other sites

  • 2 months later...

I'm trying to install this for the watermark portion only and have been unable to get it to work. I've placed the .htaccess file into the image directory I want to protect

 

/public_html/catalog/images/clothing

 

The image.php file is in /public_html/catalog/images directory (one directory above where the .htaccess file is). Along with the watermark.png file.

 

My .htaccess file looks like this:

 

RewriteEngine on

RewriteRule ^(.*)\.jpg image.php?%{REQUEST_FILENAME}

 

I get a broken image link. If I right click on the image and select "view image" I don't get the broken image, but all I get is a blank screen.

 

Any ideas? All suggestions are appreciated.

 

Thank you,

Barb

Link to comment
Share on other sites

  • 4 weeks later...

I don't see full path to your image.php file it should be like this(lime my server):

 

RewriteEngine         on
RewriteRule        ^(.*)\.jpg                /home/user12435/web/com/webdomain/www/watermark/image.php?%{REQUEST_FILENAME}

Link to comment
Share on other sites

Ok, guys.

Question!

 

I got some other pictures located in my images directory and they come up with watermaks - that's baaad!

 

How to exclude from the rule some image names? (it will be painful to redo all path to get rif of my extra pics in images directory

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