Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Support thread for the Image Magic contribution


tomjmul

Recommended Posts

  • Replies 1.3k
  • Created
  • Last Reply

Top Posters In This Topic

Nobody ?

 

Hi all !

 

Thanks again for that contrib. It works great for me but my apache error log file is full of warnings and notices:

 

PHP Warning: Call-time pass-by-reference has been deprecated - argument passed by values ...

PHP Notice: Undefined variable: page_prefix in /var/www/html/catalog/imagemagic.php on line 168

PHP Notice: Undefined variable: thumbail_size in /var/www/html/catalog/imagemagic.php on line 66

 

I have upgraded today to the latestest version of Image Magic (tried 1.14 and 1.15 version) but the warnings are still there.

 

My config:

 

Linux (CentOS v4.3)

gd 2.0.28

apache 2.0.52 with vhosts

php v5.0.4

mysql 4.1.20

 

Thanks a lot

 

Guillaume

Link to comment
Share on other sites

Hi,

i installed imagemagic using the readme, when i rigth click on product image i can see the "imagemagic.php" in the url, so it works. But on the client side, i can't see any product picture, do you know what the problem?

 

Thanks,

koudjo

 

ok, i check my install, all is done:

 

-gd is installed (i see it on list of tools/server_info in the admin side)

-replacement text in html_output.php is done like dj07 said to do it

-imagemagic is working because it appears in url of product images

-thumbnails images are created, i see them in "/catalog/thumbnails" directory

 

but product images (generate by "tep_image" function) still don't appear in the client side

 

i guess that "&" in images url aren't interpreted but i'm not shure.

there is an example of url for image "octane_2.jpg":

http://localhost/catalog/imagemagic.php?im...;page=prod_info

 

and the thumbnails associates with is : octane_2.jpg.thumb_prod_infoprod_info_100x25_322020c9c3bddd45a251fc65c2d0e980.jp

g

 

 

Somebody no what is the problem?

 

thanks for all,

Link to comment
Share on other sites

Ok, I just drop a message here to warn everyone about two facts, here the first one...

 

The base64 encoding used when enciphering the image path should be change with a "URL safe" base64 encoding !

Otherwise, it will make you crazy if you also use mod_rewrite to build path like

/fakeimgdirectory/img-ENCRYPTEDPATH-w-WIDTH-h-HEIGHT-p-PAGENAME

=> imagemagic.php?img=ENCRYPTEDPATH&w=WIDTH&h=HEIGHT&p=PAGENAME

 

I've lost something like 3 to 4 hours trying to understand why SOME of my images wouldn't show up.

The answer is simple : base64_encoded encrypted image path MIGHT contain some special characters like "+", "/" or "=".

mod_rewrite MIGHT or MIGHT NOT urldecode the encrypted image path, hence ENCRYPTEDPATH MIGHT contain end up with a "+" character.

=> The imagemagic.php script WILL shoke on this. Anytime.

 

Solution : quite simple, remplace the calls to base64_encode and base64_decode by calls to these specific functions (source : http://www.php.net/base64_encode )

 

function urlsafe_b64encode($string) {
$data = base64_encode($string);
	// first, perform a base64_encode, THEN, remplace + by -, / by _, = by .
$data = str_replace(array('+','/','='),array('-','_','.'),$data);
return $data;
}

function urlsafe_b64decode($string) {
$data = str_replace(array('-','_','.'),array('+','/','='),$string);
/*  WARNING WARNING - I, Celluloid, commented this.
		Because I absolutely don't know what it does. 
		But may'be you should reconsider, see the original in the comments 
		on this page ....
	   => http://www.php.net/base64_encode */
	/*
	$mod4 = strlen($data) % 4;
if ($mod4) {
	$data .= substr('====', $mod4);
} */
return base64_decode($data);
}

 

Modification in html_output.php

//Encrypt the image filename if switched on
if (CFG_ENCRYPT_FILENAMES == "True" && CFG_ENCRYPTION_KEY !="") {
$result = '';
$key=CFG_ENCRYPTION_KEY;
for($i=0; $i<strlen($src); $i++) {
	$char = substr($src, $i, 1);
	$keychar = substr($key, ($i % strlen($key))-1, 1);
	$char = chr(ord($char)+ord($keychar));
	$result.=$char;
}
// ORIGINAL : $src=urlencode(base64_encode($result));
$src=urlsafe_b64encode($result);
}

You will have noticed that I didn't urlencode the urlsafe_b64encoded $result ...

Why ?

(Source Wikipedia) about base64 encoding :

The only characters used are the upper- and lower-case Roman alphabet characters (A?Z, a?z), the numerals (0?9), and the "+" and "/" symbols, with the "=" symbol as a special suffix code.

So, basically, ANY character string will end up like a character string composed of [A-Z], [a-z], "+", "/" and "=".

"+", "/" and "=" WERE the need for the urlencode.

Since we replace them with "-", "_" and ".", which are "URL safe" there is no need any more of a urlencode...

 

Second modification (you might have figured it out by yourself) lies in imagemagic.php :

//Decrypt the image filename if switched on
if (CFG_ENCRYPT_FILENAMES == "True" && CFG_ENCRYPTION_KEY !="") {
	$result = '';
	$key=CFG_ENCRYPTION_KEY;
	// ORIGINAL : $string = base64_decode($_GET['img']);
			$string = urlsafe_b64decode($_GET['img]);
	for($i=0; $i<strlen($string); $i++) {
		$char = substr($string, $i, 1);
		$keychar = substr($key, ($i % strlen($key))-1, 1);
		$char = chr(ord($char)-ord($keychar));
		$result.=$char;
	}
	$_GET['img']= $result;
}

=> we just replace the call to "base64_decode" by a call to "urlsafe_b64decode".

!!!!!! Just DON'T bother about performing a urldecode. Whether or not you are using mod_rewrite, a urlencoded GET parameter is ALWAYS already urldecoded prior to "entering" the PHP script which "receives" it.

 

Of course, the two functions will have to be declared somewhere in your PHP files.

You can place them above "function tep_image" in html_output.php, and at the start of the file in imagemagic.php ...

Edited by Celluloid
Link to comment
Share on other sites

Nobody ?

 

Notice and warning are just that ... notices and warning.

The last two you pasted are a simple case of "variable not initiliazed" : PHP is not very strict about variables.

There is not required prior "declaration" (as in C, JAVA, ...) of a variable before its use...

Back in PHP3, there wasn't event the need to set a value to a variable to use it.

BUT if a variable is used in a test condition and has not been set a value before, PHP will issue a notice and create a "blank" variable (whose value will be "" / 0 / false ).

That, is, a "recent" PHP, like yours (PHP5) : the tolerance about the use of unitiliazed variables have greatly changed from PHP3 to PHP4, and from PHP4 to PHP5.

 

To answer your question precisely, the notice about "thumbnail_size" is caused by the (line 60 ... to 70, or something )

switch($thumbnail_size) {
....
}

which is placed after a series of tests to give thumbnail_size a value :

// Get the type of thumbnail we are dealing with
if ( $_GET['w']== SMALL_IMAGE_WIDTH || $_GET['h'] == SMALL_IMAGE_HEIGHT) $thumbnail_size=1;
elseif ($_GET['w'] == HEADING_IMAGE_WIDTH || $_GET['h'] == HEADING_IMAGE_HEIGHT) $thumbnail_size=2;
elseif ($_GET['w'] == SUBCATEGORY_IMAGE_WIDTH || $_GET['h'] == SUBCATEGORY_IMAGE_HEIGHT) $thumbnail_size=3;

if ($_GET['page'] == "prod_info") {
  $thumbnail_size=4;
  $page_prefix = $page ."prod_info_";
}
if ($_GET['page'] == "popup") {
  $thumbnail_size=5;
  $page_prefix = $page ."prod_info_";
}

==> there MIGHT be special cases when the none of the five conditions are met, hence, $thumbnail_size won't have a value yet.

As "$thumbnail_size" is only used for the "switch ... case", you can if you wish, add a

$thumnail_size = 0;

before the series of if(...).

Hence, even if no condition is met, it will have a value (without any consequence for the rest of the script).

 

Same idea about "page_prefix"...

 

But if you don't feel confident, don't try to eliminate the sources of the notice and warning.

The very fact you asked this question means you might not have yet the required level of understanding need to "correct" sources for warning and notices ...

Link to comment
Share on other sites

Ok, here's the second problem I noticed about this contribution, and this one is serious.

 

If you use the caching functionality of the contribution, DO NOT EVER DELETE THE WHOLE TREE STRUCTURE UNDER your thumbnail cache directory. I SAID : DO NOT EVER.

 

Explanation : I don't know the reason, if it's the << glob("*.*") >> call or something else (well, actually, I do have leads), BUT if you delete the whole tree structure under say YOUR_CATALOG_DIRECTORY/thumbnails/ (/thumnails/image/dvd/[...] etc for ) WHILE someone requests a thumbnail from the online website, AT LEAST ALL THE FILES in YOUR_CATALOG_DIRECTORY WILL BE DELETED.

 

And I'm not joking.

 

So basically :

1) WRITE PROTECT all your files at the base of your OsCommerce installation (those in the /catalog directory) if your thumbnails directory is right below it (ex: /catalog/thumbnails)

Perform same protection at the right place if the location of your thumbnails directory is somewhere else.

 

2) DO NOT EVER perform a MASSIVE DELETE of the tree structure under your thumbnails directory, be it by a shell command (rm -Rf) or a FTP connection

=> if there is THE SLIGHTEST CHANCE that someone's browsing your website and ALL your site files are not WRITE PROTECTED, YOU WILL LOSE SOME.

=> if you have SSH access, once located INSIDE the thumbnails directory, a "find . -type f -name "*" -exec rm {} \;" MIGHT be safer (*)

 

3) If you really like taking risks, perform a SAFE backup of all the files on your website (prefered method : rsync via SSH) BEFORE.

 

4) If anyone has already encounter such problem, drop a message here.

The creator of the mod is welcomed to contribute too ...

May'be there's a way to restrict the glob function call (to image-type files ...) or perform double checks, I don't know, the way I see it, It's due to the fact that

chdir($create_path);

might fail awfully at some point (and we don't know it ...), and hence, the "unlink" calls are performed on the BAD files (that is, files ABOVE the thumbnail cache directory structure).

I think the script should literally bail out on ANY filesystem related error. A broken image on the website is less dramatic than losing php files ... (INCLUDING your index.php)

 

You've been warned :)

 

 

(*) I REALLY think the problem is due to the "loss" of the tree structure (ie: the sub-directories in your thumbnails directory) rather than the "loss" of the files

Edited by Celluloid
Link to comment
Share on other sites

A very big thank to tomjmul for creating such a great contribution!

This was exactley what I needed. I took a look at some other on the fly thumbnailing countributions but noone of them are so powerful as this one. But I have to say that I have some really touch times to get this contribution to work well.

 

Thank you!

Link to comment
Share on other sites

Thanks a lot !

U are right i'm a true beginner but i hate warnings :) I will backup my files and try your solutions !

 

Thank u again

Guillaume

 

Notice and warning are just that ... notices and warning.

The last two you pasted are a simple case of "variable not initiliazed" : PHP is not very strict about variables.

There is not required prior "declaration" (as in C, JAVA, ...) of a variable before its use...

Back in PHP3, there wasn't event the need to set a value to a variable to use it.

BUT if a variable is used in a test condition and has not been set a value before, PHP will issue a notice and create a "blank" variable (whose value will be "" / 0 / false ).

That, is, a "recent" PHP, like yours (PHP5) : the tolerance about the use of unitiliazed variables have greatly changed from PHP3 to PHP4, and from PHP4 to PHP5.

 

To answer your question precisely, the notice about "thumbnail_size" is caused by the (line 60 ... to 70, or something )

switch($thumbnail_size) {
....
}

which is placed after a series of tests to give thumbnail_size a value :

// Get the type of thumbnail we are dealing with
if ( $_GET['w']== SMALL_IMAGE_WIDTH || $_GET['h'] == SMALL_IMAGE_HEIGHT) $thumbnail_size=1;
elseif ($_GET['w'] == HEADING_IMAGE_WIDTH || $_GET['h'] == HEADING_IMAGE_HEIGHT) $thumbnail_size=2;
elseif ($_GET['w'] == SUBCATEGORY_IMAGE_WIDTH || $_GET['h'] == SUBCATEGORY_IMAGE_HEIGHT) $thumbnail_size=3;

if ($_GET['page'] == "prod_info") {
  $thumbnail_size=4;
  $page_prefix = $page ."prod_info_";
}
if ($_GET['page'] == "popup") {
  $thumbnail_size=5;
  $page_prefix = $page ."prod_info_";
}

==> there MIGHT be special cases when the none of the five conditions are met, hence, $thumbnail_size won't have a value yet.

As "$thumbnail_size" is only used for the "switch ... case", you can if you wish, add a

$thumnail_size = 0;

before the series of if(...).

Hence, even if no condition is met, it will have a value (without any consequence for the rest of the script).

 

Same idea about "page_prefix"...

 

But if you don't feel confident, don't try to eliminate the sources of the notice and warning.

The very fact you asked this question means you might not have yet the required level of understanding need to "correct" sources for warning and notices ...

Link to comment
Share on other sites

.....

 

- Is thumbnail folder created?

- Is SAFE MODE is OFF?

- Is DIR_FS_CATALOG path set correctly in configure.php?

- Is thumbnail server caching turned off?

 

Etc.

 

Thanks

 

Jody

THANKYOU!!! I have been searching for ages, this was my answer!!!

 

~bobsi18~

Link to comment
Share on other sites

Just wanted to supply a solution to a problem that I faced.

 

Everything was being done correctly (thumbnails were being created in the right place and they could be displayed if clicked on locally). The images were stil not showing though.

 

I clicked on the "properties" button for the image (right click on image) and copied and pasted the image URL to a new window. Lo and behold there were "warnings" in the actual image with the image information just below it. Images would not be able to work with this additional text showing (the MIME type is for GIF after all).

 

So I went into my php configuration (php.ini) and i turned the setting "display_errors" to "Off" and did a server restart. Images now all show up :D.

 

I hope this helps someone.

 

Thanks for the great contribution! :thumbsup:

Link to comment
Share on other sites

Hello.

 

Contribution is great and I installed it many times. But now I got error and do not investigate yet how to fix. Generated images is in very low quality. I do not know why. Sizes of images (width/height) is different. Here is generated image

qqq.jpg

and here is original

B00097E7QC.jpg

 

Thanks for help.

Link to comment
Share on other sites

great contrib thanks, have tried 2 others for watermarks and they just didnt work - this one does.

 

only problem I had which took me hour or so to work out (I know nothing about coding, just trial and error)

 

is the watermark image and text pull down boxes were empty although the files were there in the correct folders. I dont use the Catalog directory but I checked the code and the config.php on my server and seemed to be fine.

 

in the end I looked at the SQL code to find how that bit worked and see it uses DIR_FS_DOCUMENT_ROOT to reference it

 

So in my admin\includes\configure.php I checked this line and seemed ok. But I tried adding a / to the end of the line in my config file

 

i.e

 

from this

 

define('DIR_FS_DOCUMENT_ROOT','/kunden/homepages/23/d141006650/htdocs/wsb3900560901');

 

to this

 

define('DIR_FS_DOCUMENT_ROOT','/kunden/homepages/23/d141006650/htdocs/wsb3900560901/');

 

then it worked and files were showing up..

 

Im sure it obvious to most, but I thought would point out in case someone else has the same problem.

Link to comment
Share on other sites

Imagemagick installed without a hitch and it's awesome. I noticed an immediate differnece in loading and image quality...HOWEVER! In the admin section of the site, the admin logo and the online catalog icon do not appear. At first I thought I may have broke something, but when i turn imagemagic off, they show up. Any ideas? has this happened to others? The dimensions are the same as the original pics, so I have no clue what could be causing it. please help as it's rather annoying, and in order to print an invoice with the logo on it, i have to go and turn off image magick to get it to show up.

We must be the change we wish to see in the world.

------------------------------------------------------------

p.s. BACKUP!

Link to comment
Share on other sites

I got this contribution to work at a store ad than I was going to install it on another store. I got it working until I was going to activate a graphic watermark on the images. I use excetly the same files that I use on my first store so I don't think I find the problem there. Anyone that have the same problem? My problem is that I can't place any watermarks on my images. No graphic or text watermark.

Link to comment
Share on other sites

Hi all!

 

I have a problem with the sql implementation in phpmyadmin:

I Get #1136 - Column count doesn't match value count at row 1

 

'', 'Watermark Image File', 'WATERMARK_IMAGE', '', 'Select which watermark image you wish to use<br><br>New watermark images may be installed in your:<br><b>/catalog/includes/imagemagic/watermarks/</b><br>directory<br>', 333, 66, NULL , '2005-01-06 20:24:30', NULL

 

So please help me if you can

Link to comment
Share on other sites

Hi all!

 

I have a problem with the sql implementation in phpmyadmin:

I Get #1136 - Column count doesn't match value count at row 1

 

'', 'Watermark Image File', 'WATERMARK_IMAGE', '', 'Select which watermark image you wish to use<br><br>New watermark images may be installed in your:<br><b>/catalog/includes/imagemagic/watermarks/</b><br>directory<br>', 333, 66, NULL , '2005-01-06 20:24:30', NULL

 

So please help me if you can

 

could you post the entire query, with the insert fields and values, so we can see what is going on?

Link to comment
Share on other sites

OK... I got it installed - shows up fine under the admin panel, the /thumbnails directory is there, and there are images under it.... but they're not displaying.

 

To note: My store is in the root directory, I do not have a "catalog" directory - however I didn't notice anything under the code that was edited that pointed to a catalog directory.

 

An example of an image link shows as follows:

 

http://www.stevesstash.com/imagemagic.php?...h=100&page=

 

All of the product images are now showing as a broken image.

 

Any ideas how to fix this? :(

Link to comment
Share on other sites

To note: My store is in the root directory, I do not have a "catalog" directory - however I didn't notice anything under the code that was edited that pointed to a catalog directory.

 

An example of an image link shows as follows:

 

http://www.stevesstash.com/imagemagic.php?...h=100&page=

 

All of the product images are now showing as a broken image.

 

Any ideas how to fix this? :(

 

Had you clicked yourself on the link and you would have had your answer :)

Warning: chdir(): No such file or directory (errno 2) in /home/content/[...]/html/imagemagic.php on line 21

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/[...]/html/imagemagic.php:21) in /home/content/[...]/html/imagemagic.php on line 463

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/[...]/html/imagemagic.php:21) in /home/content/[...]/html/imagemagic.php on line 464

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/[...]/html/imagemagic.php:21) in /home/content/[...]/html/imagemagic.php on line 473

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/[...]/html/imagemagic.php:21) in /home/content/[...]/html/imagemagic.php on line 181

 

That's basic - basic - basic stuff in PHP :

You have a error linked to the context of execution in your script => error ouput message written to the client (that is, your browser)

Hence, you can't send any more headers.

A header in the context of an HTTP request is a message the server sends to the user (or the user sends to the server) to inform him :

+ of the last time the file he requested was modified

+ of the file-type about to be sent

+ of the location to redirect the request.

+ ... many more

PRIOR to sending any "real" output (things that are displayed in the browser or can be saved to a file or ... whatever).

 

In the case of the ImageMagic contribution, they are many headers that could be sent, depending if you activated "browser-side cache", "server-side cache", etc ...

 

But your image is not broken due to these headers missing. It's broken because of the initial errors and the following errors of the "headers couldn't be sent".

Look here :

Warning: Cannot modify header information - headers already sent by (output started at /home/content/s/s/f/ssforza/html/imagemagic.php:21) in /home/content/s/s/f/ssforza/html/imagemagic.php on line 181
????JFIF??

See the JFIF amongst the weird characters ? It's the beginning of your image.

 

So, get rid of your first error, you'll get rid of the subsequent headers errors, and you'll see the images.

 

Warning: chdir(): No such file or directory (errno 2) in /home/content/[...]/html/imagemagic.php on line 21

=> The script can't make it to a directory, likely because it doesn't exists.

if (file_exists('includes/local/configure.php')) {

//use local dev params if available

include('includes/local/configure.php');

} else {

// include server parameters

require('includes/configure.php');

}

require('includes/imagemagic/imagemagic.functions.php');

chdir (DIR_FS_CATALOG); <==== line 21

 

So, either DIR_FS_CATALOG is not set in your includes/configure.php, either it's set to a wrong value.

I would say it needs to be set to the value of "/home/content/s/s/f/ssforza/html/".

It it's already set to this value, you have a serious problem :D

 

Cheers.

Edited by Celluloid
Link to comment
Share on other sites

Ok, here's the second problem I noticed about this contribution, and this one is serious.

 

If you use the caching functionality of the contribution, DO NOT EVER DELETE THE WHOLE TREE STRUCTURE UNDER your thumbnail cache directory. I SAID : DO NOT EVER.

 

Explanation : I don't know the reason, if it's the << glob("*.*") >> call or something else (well, actually, I do have leads), BUT if you delete the whole tree structure under say YOUR_CATALOG_DIRECTORY/thumbnails/ (/thumnails/image/dvd/[...] etc for ) WHILE someone requests a thumbnail from the online website, AT LEAST ALL THE FILES in YOUR_CATALOG_DIRECTORY WILL BE DELETED.

 

And I'm not joking.

 

[...]

4) If anyone has already encounter such problem, drop a message here.

The creator of the mod is welcomed to contribute too ...

May'be there's a way to restrict the glob function call (to image-type files ...) or perform double checks, I don't know, the way I see it, It's due to the fact that

chdir($create_path);

might fail awfully at some point (and we don't know it ...), and hence, the "unlink" calls are performed on the BAD files (that is, files ABOVE the thumbnail cache directory structure).

I think the script should literally bail out on ANY filesystem related error. A broken image on the website is less dramatic than losing php files ... (INCLUDING your index.php)

 

You've been warned :)

(*) I REALLY think the problem is due to the "loss" of the tree structure (ie: the sub-directories in your thumbnails directory) rather than the "loss" of the files

 

 

Well, seems like the author is enjoying his summer like every sane people around here...

So basically, if someone here DOES bother about losing all the files in the "catalog" directory, here's the patch :

In imagemagic.php file,

LOOK FOR (inside 'function modify_tn_path($file, $check_cache)')

			//clean up the cache if settings have changed
		if (CFG_CACHE_AUTO_CLEAN=="True" && $check_cache) {
			  $cwd=getcwd();
			  chdir($create_path);
			  foreach (glob("*.*") as $filename) {
					if (!is_dir($filename) && !strstr($filename,$append_hash)) {
						  unlink($filename);
					}
			  }  
			  chdir($cwd);
		}

AND REPLACE BY

			//clean up the cache if settings have changed
		if (CFG_CACHE_AUTO_CLEAN=="True" && $check_cache) {
			  $cwd=getcwd();
			  /* Just be SURE the chdir worked and that you are not STILL in the /catalog/ directory
				  ... or the glob(*.*) will list your index.php file, your product_info.php file, etc
				  and ... you will "unlink" (ie: DELETE) them : 'Woopsie Daisy !!'.
			   */
			  if (chdir($create_path)) {
					foreach (glob("*.*") as $filename) {
						  if (!is_dir($filename) && !strstr($filename,$append_hash)) {
								unlink($filename);
						  }
					}  
					chdir($cwd);
			  }
		}

 

Have fun.

Edited by Celluloid
Link to comment
Share on other sites

This appears to have been the whole problem - I somehow missed it when I moved my store to the root dir, and it still was pointing to the /catalog directory (yet amazingly everything was working).

Got rid of the /catalog, and the thumbnails appear to be working beautifully now.

 

THANK you :D

 

So, either DIR_FS_CATALOG is not set in your includes/configure.php, either it's set to a wrong value.

I would say it needs to be set to the value of "/home/content/s/s/f/ssforza/html/".

Link to comment
Share on other sites

hmm.. I think I've come across a minor bug with image magick.

 

so I am running jpegs primarily, and they can get pretty large (for a store). I set my jpeg quality to 60 in the configuration page and loaded up my page then a full size popup image. no problem, it went from 89KB down to 18KB. However everytime after the first load I would do a full refresh (CTRL+SHIFT+R on firefox) the image that would then load would again be >80KB. So I looked at every other image on the site.... and noticed the exact same thing. every time I would load an image the first time (with server caching) it would be super small, and then every time after that it would jump back up in filesize. I finally narrowed it down one by one to find it was the server caching. with server caching turned off, the file sizes always remained the same. with server caching turned on, it would jump down for the first load, then jump back up for subsequent loads.

 

this is happening on jpegs only and I found the problem. around line 178 in catalog/imagemagic.php you have the conditional if you are cached and either a jpeg or gif_as_jpeg. the problem is in this conditional, it basically creates a whole new jpeg out of your cache image at 100 quality. now if you know how JPEG works, you know that 100 quality on a heavily compressed jpeg will increase the size substantially. this doesn't affect the GIF or PNG sections because they are lossless, but with jpeg it creates a larger file. so what I did was I deleted out the imagecreatefromjpeg and imagejpeg calls and after the header() call I put in the following:

 

$push_file = fopen($filename,'r');

while (!feof($push_file)) {

print(fread($push_file, 1024));

flush();

@ob_flush();

}

fclose($push_file);

 

this reads in the actual cached file and outputs it directly to the browser. now technically this is what should happen in the other two conditionals as well. the file stays the same as is in those conditionals, but there is still some processing power involved in reprocessing the images.

 

If this seems off let me know, but this was the only way I could get it to stop processing cached files over and over again. I have left the rest of the module alone and it has worked great. this was the only area that I needed to adjust.

Edited by borghe
Link to comment
Share on other sites

hi everyone,

 

 

I have installed the contibution v1.15 dated 20 jun 2006, I did all the changes according to the description and still OS does not show pictures. Sorry to post my message, as a lot of people have asked about it before, but I have checked most of the Contribution Support and I could not find any solution for my problem.

 

1. The IM did not create the "Thumbnails" folder so I did it by mysef, changed chmod to 777

2. after that a new folder "Images" has been created insie "Thumbnails" automaticaly (its chmod is 755 and it cannot be changed - if I change it to 777 it still remains 755)

3. if I switch off Cache Thumbnails on the Server in Admin Panel then the contribution starts working, I can add watermarks etc., - but it does not speed up my webpage... because nothing is cached

4. when I check full path of the image (using properties) it shows imagemagic.php in the link

 

5. no matter what I click and change still the folder /thumbnails remains empty.

... even if I try to copy anything to the folder via ftp it seems not to be stored there but automaticaly deleted

 

 

have any ideas??

Link to comment
Share on other sites

I am trying to install this wonderful contrib and I am receiving this error when I try to access my store.

 

Parse error: parse error, unexpected '}' in /home/horsepow/public_html/includes/functions/html_output.php on line 227

 

Here is my code from the html_output.php file

 

<?php

/*

$Id: html_output.php,v 1.56 2003/07/09 01:15:48 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

////

// The HTML href link wrapper function

function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) {

global $request_type, $session_started, $SID;

 

if (!tep_not_null($page)) {

die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine the page link!<br><br>');

}

 

if ($connection == 'NONSSL') {

$link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;

} elseif ($connection == 'SSL') {

if (ENABLE_SSL == true) {

$link = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG;

} else {

$link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;

}

} else {

die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine connection method on a link!<br><br>Known methods: NONSSL SSL</b><br><br>');

}

 

if (tep_not_null($parameters)) {

$link .= $page . '?' . tep_output_string($parameters);

$separator = '&';

} else {

$link .= $page;

$separator = '?';

}

 

while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1);

 

// Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined

if ( ($add_session_id == true) && ($session_started == true) && (SESSION_FORCE_COOKIE_USE == 'False') ) {

if (tep_not_null($SID)) {

$_sid = $SID;

} elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL == true) ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) {

if (HTTP_COOKIE_DOMAIN != HTTPS_COOKIE_DOMAIN) {

$_sid = tep_session_name() . '=' . tep_session_id();

}

}

}

 

if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {

while (strstr($link, '&&')) $link = str_replace('&&', '&', $link);

 

$link = str_replace('?', '/', $link);

$link = str_replace('&', '/', $link);

$link = str_replace('=', '/', $link);

 

$separator = '?';

}

 

if (isset($_sid)) {

$link .= $separator . $_sid;

}

 

return $link;

}

 

////

// The HTML image wrapper function

// BOF Image Magic

function tep_image($src, $alt = '', $width = '', $height = '', $params = '') {

global $product_info;

 

//Allow for a new intermediate sized thumbnail size to be set

//without any changes having to be made to the product_info page itself.

//(see the lengths I go to to make your life easier :-)

if (strstr($_SERVER['PHP_SELF'],"product_info.php")) {

 

if (isset($product_info['products_image'])

&& $src == DIR_WS_IMAGES . $product_info['products_image']

&& $product_info[products_id]==$_GET['products_id']) { //final check just to make sure that we don't interfere with other contribs

$width = PRODUCT_INFO_IMAGE_WIDTH == 0?'':PRODUCT_INFO_IMAGE_WIDTH;

$height = PRODUCT_INFO_IMAGE_HEIGHT == 0?'':PRODUCT_INFO_IMAGE_HEIGHT;

$product_info_image=true;

$page="prod_info";

}

}

 

//Detect whether this is a pop-up image

if (strstr($_SERVER['PHP_SELF'],"popup_image.php")) $page="popup";

 

//do we apply the IE PNG alpha transparency fix?

if (strstr(strtolower($src),".png") && CFG_PNG_BUG=="True") $fix_png = true;

 

//send the image for processing unless told otherwise

$image = '<img src="' . $src . '"'; //set up the image tag just in case we don't want to process

if (CFG_MASTER_SWITCH=="On") $calculate = true;

else $calculate=false;

 

// Don't calculate if the image is set to a "%" width

if (strstr($width,'%') == true || strstr($height,'%') == true) $calculate = false;

 

// Dont calculate if a pixel image is being passed (hope you dont have pixels for sale)

if (strstr($image, 'pixel')) $calculate = false;

 

 

$image_size = @getimagesize($src);

 

 

// Decide whether or not we want to process this image

if (($width == '' && $height == '' && $page != 'popup' ) || ($width == $image_size[0] && $height == $image_size[0] && $page != 'popup')) {

if (CFG_PROCESS_GRAPHICS=="False") $calculate = false; //looks like this is a store graphic rather than product image

}

 

// Is this image good to go?

if (CONFIG_CALCULATE_IMAGE_SIZE && $calculate) {

 

if ($image_size) {

 

$ratio = $image_size[1] / $image_size[0];

 

// Set the width and height to the proper ratio

if (!$width && $height) {

$ratio = $height / $image_size[1];

$width = intval($image_size[0] * $ratio);

} elseif ($width && !$height) {

$ratio = $width / $image_size[0];

$height = intval($image_size[1] * $ratio);

} elseif (!$width && !$height && !$over_ride) {

$width = $image_size[0];

$height = $image_size[1];

}

 

//Encrypt the image filename if switched on

if (CFG_ENCRYPT_FILENAMES == "True" && CFG_ENCRYPTION_KEY !="") {

$result = '';

$key=CFG_ENCRYPTION_KEY;

for($i=0; $i<strlen($src); $i++) {

$char = substr($src, $i, 1);

$keychar = substr($key, ($i % strlen($key))-1, 1);

$char = chr(ord($char)+ord($keychar));

$result.=$char;

}

$src=urlencode(base64_encode($result));

}

 

//Return the html

$image = '<img src="imagemagic.php?img='.$src.'&w='.

tep_output_string($width).'&h='.tep_output_string($height).'&page='.$page.'"';

 

} elseif (IMAGE_REQUIRED == 'false') {

return false;

}

}

 

//If the size asked for is greater than the image itself, we check the configs to see if this is allowed and if not over-ride

if ($width > $image_size[0] || $height > $image_size[1]) {

if (CFG_ALLOW_LARGER != 'True'){

$width=$image_size[0];

$height=$image_size[1];

$over_ride = true;

}

}

// Add remaining image parameters if they exist

if ($width) {

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

}

 

if ($height) {

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

}

 

if (tep_not_null($params)) $image .= ' ' . $params;

 

$image .= ' border="0" alt="' . tep_output_string($alt) . '"';

 

if (tep_not_null($alt)) {

$image .= ' title="' . tep_output_string($alt) . '"';

}

 

if ($fix_png && CFG_MASTER_SWITCH=="On") {

$image .= ' onload="fixPNG(this)"';

}

 

$image .= '>';

return $image;

}

//EOF Image Magic

// 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="' . tep_output_string($src) . '" border="0" alt="' . tep_output_string($alt) . '"';

 

if (tep_not_null($alt)) {

$image .= ' title=" ' . tep_output_string($alt) . ' "';

}

 

if ( (CONFIG_CALCULATE_IMAGE_SIZE == 'true') && (empty($width) || empty($height)) ) {

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

if (empty($width) && tep_not_null($height)) {

$ratio = $height / $image_size[1];

$width = $image_size[0] * $ratio;

} elseif (tep_not_null($width) && empty($height)) {

$ratio = $width / $image_size[0];

$height = $image_size[1] * $ratio;

} elseif (empty($width) && empty($height)) {

$width = $image_size[0];

$height = $image_size[1];

}

} elseif (IMAGE_REQUIRED == 'false') {

return false;

}

}

 

if (tep_not_null($width) && tep_not_null($height)) {

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

}

 

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

 

$image .= '>';

 

return $image;

}

 

////

// The HTML form submit button wrapper function

// Outputs a button in the selected language

function tep_image_submit($image, $alt = '', $parameters = '') {

global $language;

 

$image_submit = '<input type="image" src="' . tep_output_string(DIR_WS_LANGUAGES . $language . '/images/buttons/' . $image) . '" border="0" alt="' . tep_output_string($alt) . '"';

 

if (tep_not_null($alt)) $image_submit .= ' title=" ' . tep_output_string($alt) . ' "';

 

if (tep_not_null($parameters)) $image_submit .= ' ' . $parameters;

 

$image_submit .= '>';

 

return $image_submit;

}

 

////

// Output a function button in the selected language

function tep_image_button($image, $alt = '', $parameters = '') {

global $language;

 

return tep_image(DIR_WS_LANGUAGES . $language . '/images/buttons/' . $image, $alt, '', '', $parameters);

}

 

////

// Output a separator either through whitespace, or with an image

function tep_draw_separator($image = 'pixel_black.gif', $width = '100%', $height = '1') {

return tep_image(DIR_WS_IMAGES . $image, '', $width, $height);

}

 

////

// Output a form

function tep_draw_form($name, $action, $method = 'post', $parameters = '') {

$form = '<form name="' . tep_output_string($name) . '" action="' . tep_output_string($action) . '" method="' . tep_output_string($method) . '"';

 

if (tep_not_null($parameters)) $form .= ' ' . $parameters;

 

$form .= '>';

 

return $form;

}

 

////

// Output a form input field

function tep_draw_input_field($name, $value = '', $parameters = '', $type = 'text', $reinsert_value = true) {

$field = '<input type="' . tep_output_string($type) . '" name="' . tep_output_string($name) . '"'.($type = 'text' ? '' : '');

 

if ( (isset($GLOBALS[$name])) && ($reinsert_value == true) ) {

$field .= ' value="' . tep_output_string(stripslashes($GLOBALS[$name])) . '"';

} elseif (tep_not_null($value)) {

$field .= ' value="' . tep_output_string($value) . '"';

}

 

if (tep_not_null($parameters)) $field .= ' ' . $parameters;

 

$field .= '>';

 

return $field;

}

 

////

// Output a form password field

function tep_draw_password_field($name, $value = '', $parameters = 'maxlength="40"') {

return tep_draw_input_field($name, $value, $parameters, 'password', false);

}

 

////

// Output a selection field - alias function for tep_draw_checkbox_field() and tep_draw_radio_field()

function tep_draw_selection_field($name, $type, $value = '', $checked = false, $parameters = '') {

$selection = '<input type="' . tep_output_string($type) . '" name="' . tep_output_string($name) . '"';

 

if (tep_not_null($value)) $selection .= ' value="' . tep_output_string($value) . '"';

 

if ( ($checked == true) || ( isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) && ( ($GLOBALS[$name] == 'on') || (isset($value) && (stripslashes($GLOBALS[$name]) == $value)) ) ) ) {

$selection .= ' CHECKED';

}

 

if (tep_not_null($parameters)) $selection .= ' ' . $parameters;

 

$selection .= '>';

 

return $selection;

}

 

////

// Output a form checkbox field

function tep_draw_checkbox_field($name, $value = '', $checked = false, $parameters = '') {

return tep_draw_selection_field($name, 'checkbox', $value, $checked, $parameters);

}

 

////

// Output a form radio field

function tep_draw_radio_field($name, $value = '', $checked = false, $parameters = '') {

return tep_draw_selection_field($name, 'radio', $value, $checked, $parameters);

}

 

////

// Output a form textarea field

function tep_draw_textarea_field($name, $wrap, $width, $height, $text = '', $parameters = '', $reinsert_value = true) {

$field = '<textarea name="' . tep_output_string($name) . '" wrap="' . tep_output_string($wrap) . '" cols="' . tep_output_string($width) . '" rows="' . tep_output_string($height) . '"';

 

if (tep_not_null($parameters)) $field .= ' ' . $parameters;

 

$field .= '>';

 

if ( (isset($GLOBALS[$name])) && ($reinsert_value == true) ) {

$field .= stripslashes($GLOBALS[$name]);

} elseif (tep_not_null($text)) {

$field .= $text;

}

 

$field .= '</textarea>';

 

return $field;

}

 

////

// Output a form hidden field

function tep_draw_hidden_field($name, $value = '', $parameters = '') {

$field = '<input type="hidden" name="' . tep_output_string($name) . '"';

 

if (tep_not_null($value)) {

$field .= ' value="' . tep_output_string($value) . '"';

} elseif (isset($GLOBALS[$name])) {

$field .= ' value="' . tep_output_string(stripslashes($GLOBALS[$name])) . '"';

}

 

if (tep_not_null($parameters)) $field .= ' ' . $parameters;

 

$field .= '>';

 

return $field;

}

 

////

// Hide form elements

function tep_hide_session_id() {

global $session_started, $SID;

 

if (($session_started == true) && tep_not_null($SID)) {

return tep_draw_hidden_field(tep_session_name(), tep_session_id());

}

}

 

////

// Output a form pull down menu

function tep_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) {

$field = '<select name="' . tep_output_string($name) . '"';

 

if (tep_not_null($parameters)) $field .= ' ' . $parameters;

 

$field .= '>';

 

if (empty($default) && isset($GLOBALS[$name])) $default = stripslashes($GLOBALS[$name]);

 

for ($i=0, $n=sizeof($values); $i<$n; $i++) {

$field .= '<option value="' . tep_output_string($values[$i]['id']) . '"';

if ($default == $values[$i]['id']) {

$field .= ' SELECTED';

}

 

$field .= '>' . tep_output_string($values[$i]['text'], array('"' => '"', '\'' => ''')) . '</option>';

}

$field .= '</select>';

 

if ($required == true) $field .= TEXT_FIELD_REQUIRED;

 

return $field;

}

 

////

// Creates a pull-down list of countries

function tep_get_country_list($name, $selected = '', $parameters = '') {

$countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));

$countries = tep_get_countries();

 

for ($i=0, $n=sizeof($countries); $i<$n; $i++) {

$countries_array[] = array('id' => $countries[$i]['countries_id'], 'text' => $countries[$i]['countries_name']);

}

 

return tep_draw_pull_down_menu($name, $countries_array, $selected, $parameters);

}

?>

Link to comment
Share on other sites

(sorry for the duplicate post... I didn't respond in the correct thread)

 

Great contribution. Here are some suggestions for improvement:

 

- Add a sharpening option

- Resize images this way: Set max height or width (make one zero). When resizing images determine if the original image is longer/wider. Make the longer or wider side what is set as max Height or Width. With the current setup, if one image is really wide and one image is really long, the product catalog page looks whacked out... Here's an example

 

Sorry if this has been discussed before... didn't have time to read through 35 pages of messages.

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