Jump to content
Sign in to follow this  
tpros

[Contribution] Keep Image Proportions 1.0

Recommended Posts

Thanks for your contribution, i'm getting this error:

Parse error: parse error, unexpected $ in /home/xxx/xxx/xxx/includes/functions/html_output.php on line 365

 

Do I need to change in 2 places? there are 2 html_output

Share this post


Link to post
Share on other sites
Thanks for your contribution, i'm getting this error:
Parse error: parse error, unexpected $ in /home/xxx/xxx/xxx/includes/functions/html_output.php on line 365

 

Do I need to change in 2 places? there are 2 html_output

 

I wouldn't worry too much about the admin side of things. I couldn't tell you why you're getting that error except that maybe you have a very old or very new snapshot that possibly may not work, but my php and programming skill-age is very small.


<>< <>< <>< <>< <>< <><

<><

<>< Tony Pros - tony@funksmith.com

<><

<>< <>< <>< <>< <>< <><

 

I've learned that if someone says something unkind about me, I must live so that no one will believe it.

Share this post


Link to post
Share on other sites

I believe there is a missing { in the code and when there is no image but it is defined you get division by zero errors.

 

I had this same issue with other code I had once seen posted and ended up re-writting for similar issues.

 

This seems to work on most sites ... but no promises for all sites :D

 

Replace (I rename the original tep_image to tep_image_old) all of function tep_image with this:

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

 if ( (($src == '') || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED=='false') ) {

   return;

 }

 $image = '<img src="' . $src . '" border="0" alt=" ' . htmlspecialchars($alt) . ' "';

 if ((strstr($width,'%')!='') || (strstr($height,'%')!='')) {

   $dont_calculate = 1;

 }

 if ( (CONFIG_CALCULATE_IMAGE_SIZE) && ((!$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 '';

   }

 }

 if ( CONFIG_CALCULATE_IMAGE_SIZE && (!$dont_calculate) ){

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

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

     // do we need scaling

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

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

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

       if ($rx < $ry) {

         $width = $height / $ratio;

       } else {

         $height = $width * $ratio;

       }

     } else {

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

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

       if ($rx < $ry) {

         $width = $height / $ratio;

       } else {

         $height = $width * $ratio;

       }

     }

   }

 }

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

   $image .= ' width="' . $width . '" height="' . $height . '"';

 }

 if ($params != '') {

   $image .= ' ' . $params;

 }

 $image .= '>';

 return $image;

}

 

Let me know if this fails for people who try it. I have not found out why it fails for some, unless my last fix to it was the solution.

Share this post


Link to post
Share on other sites

Thanks Linda, I think that might be the trick, I've been using place holder images. So I never ran into missing image problems.


<>< <>< <>< <>< <>< <><

<><

<>< Tony Pros - tony@funksmith.com

<><

<>< <>< <>< <>< <>< <><

 

I've learned that if someone says something unkind about me, I must live so that no one will believe it.

Share this post


Link to post
Share on other sites
Thanks Linda, I think that might be the trick, I've been using place holder images. So I never ran into missing image problems.

By coincidence the site I am working on right now is a duplicate of another site without the images loaded so it was real apparent when I got 40 errors on the first page then when I went to a page with just 2 images and had 2 errors I remembered an error I got first time I ever tried to change this code based on a suggestion someone else made to fix this.

 

And no, I cannot for the life of me recall who first posted the code I modified for images :shock:

Share this post


Link to post
Share on other sites

Linda im not sure if im understanding this properly....(stupid pills at work) but your code will take any image and resize it correctly so that a thumbnail isnt out of proportion is that right???

 

Currently i use the big image mod and load the full size image into it and then create a copy of each image and re-size it to a size of 140x120 and save them with _sml added to their names and upload them as the normal image.

 

This ensure that all my product images are exactly 140x120

 

Does this code remove the need to do that???

 

I kind of want everything laying out in a neat uniform way so will this do this or do you think i shoudl stick to the way i do it now???

 

what do you think?

Share this post


Link to post
Share on other sites
Linda im not sure if im understanding this properly....(stupid pills at work) but your code will take any image and resize it correctly so that a thumbnail isnt out of proportion is that right???

 

It's just a replacement of function tep_image. When I use it, all of my images are no longer distorted. Any code that uses the tep_image for displaying the image will now display a proportioned image based on the settings in Admin.

 

Usually I create proper sized images, but often times, there are those images or jobs where you are just tired of being 'perfect' on your settings or the image just isn't going to fit or look right. This revised routine appears to handle it for me.

Share this post


Link to post
Share on other sites

My snapshot is around jun. 25/02-

any ideas?

here is what I have in there:

 

function tep_image($src, $alt = '', $width = '', $height = '',

$params = '') {

? if ( (($src == '') || ($src == DIR_WS_IMAGES)) &&

(IMAGE_REQUIRED=='false') ) {

? ? return;

? }

? $image = '<img src="' . $src . '" border="0" alt=" ' . htmlspecialchars($alt) . ' "';

? if ((strstr($width,'%')!='') || (strstr($height,'%')!='')) {

? ? $dont_calculate = 1;

? }

? if ( (CONFIG_CALCULATE_IMAGE_SIZE) && ((!$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 '';

? ? }

? }

? if ( CONFIG_CALCULATE_IMAGE_SIZE && (!$dont_calculate) ){

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

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

? ? ? // do we need scaling

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

? ? ? ? $rx = $image_size[0] / $width;

? ? ? ? $ry = $image_size[1] / $height;

? ? ? ? if ($rx < $ry) {

? ? ? ? ? $width = $height / $ratio;

? ? ? ? } else {

? ? ? ? ? $height = $width * $ratio;

? ? ? ? }

? ? ? } else {

? ? ? ? $rx = $image_size[0] / $width;

? ? ? ? $ry = $image_size[1] / $height;

? ? ? ? if ($rx < $ry) {

? ? ? ? ? $width = $height / $ratio;

? ? ? ? } else {

? ? ? ? ? $height = $width * $ratio;

? ? ? ? }

? ? ? }

? ? }

? }

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

? ? $image .= ' width="' . $width . '" height="' . $height . '"';

? }

? if ($params != '') {

? ? $image .= ' ' . $params;

? }

? $image .= '>';

? return $image;

}

 

////

// The HTML form submit button wrapper function

// Outputs a button in the selected language

function tep_image_submit($image, $alt) {

global $language;

 

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

if (tep_not_null($alt)) {

$image_submit .= ' title=" ' . htmlspecialchars($alt) . ' ">';

}

 

return $image_submit;

}

Share this post


Link to post
Share on other sites

I'm a novice at sticking things in the database. Nonetheless, I'm using myphpadmin and I don't see "admin image config" anywhere. Can someone tell me where (exactly) to stick the SQL string for this hack?

 

Sincerely,

Jason

Share this post


Link to post
Share on other sites

Ok. I'm getting it. I see the places in mysql that need the code. I received an error, though.

 

Error

 

SQL-query :

 

`configuration_title` , `configuration_key` , `configuration_value` , `configuration_description` , `configuration_group_id` , `sort_order` , `date_added` , `set_function` 'IMAGE_CONSTRAIN_PROPORTIONS', 'true', 'Maintain image proportions when setting sizes', 4, 9, now( ) , 'tep_cfg_select_option(array(\'true\', \'false\'),'

 

)

 

MySQL said:

 

 

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'configuration_title` , `configuration_key` , `configuration_v

Back

 

Any ideas for what I should do? The "now()" was highlighted as something it didn't like.

 

JG

Share this post


Link to post
Share on other sites

Ok. It seems that I've done that part correctly.

 

Now, I have this error on my page:

 

Parse error: parse error, expecting `')'' in /home/jcsm/public_html/cart/includes/functions/html_output.php on line 291

 

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/jcsm/public_html/cart/includes/functions/html_output.php:291) in /home/jcsm/public_html/cart/includes/functions/sessions.php on line 67

 

You can see it at http://jcsm.org/cart/

 

Any ideas?

 

JG

Share this post


Link to post
Share on other sites

This error has popped up, too:

 

Fatal error: Call to undefined function: tep_draw_pull_down_menu() in /home/jcsm/public_html/cart/includes/boxes/currencies.php on line 41

 

JG

Share this post


Link to post
Share on other sites

Ok. The errors are gone. I replaced the file with my backup copy.

 

Now, the problem is finding the first part of this code. It doesn't exist. How can I replace it if I cannot find it?

 

 

//////////////////////////////////////////////////////////

//FIND THE CODE LIKE THIS: (in function tep_image)

/////////////////////////////////////////////////////////

 

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

 

$image .= ' width="' . tep_parse_input_field_data($width, array('"' => '"')) . '" height="' . tep_parse_input

_field_data($height, array('"' => '"')) . '"';

}

 

////////////////////////////////////////////////////////////////////////////

// AND REPLACE WITH THIS: ( or simply insert the part between BEGIN & END)

////////////////////////////////////////////////////////////////////////////

 

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

 

// BEGIN Code inserted to maintain proportions of images.

if (IMAGE_CONSTRAIN_PROPORTIONS == 'true') {

$image_size = @getimagesize($src);

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

if ($image_size[1]*$ratio > $height) {

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

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

} else {

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

}

}

// END Code inserted to maintain proportions of images.

 

$image .= ' width="' . tep_parse_input_field_data($width, array('"' => '"')) . '" height="' . tep_parse_input

_field_data($height, array('"' => '"')) . '"';

}

 

JG

Share this post


Link to post
Share on other sites

Anyone know the right code for this version?

 

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

 

JG

Share this post


Link to post
Share on other sites

I have the same problem, I can't find the code to replace on a new installtion of oscommerce (version $Id: html_output.php,v 1.56 2003/07/09 01:15:48 hpdl Exp $) :(

 

Can anyone please help?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×