Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] Keep Image Proportions 1.0


Guest

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

 

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.

Link to comment
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.

Link to comment
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:

Link to comment
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?

Link to comment
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.

Link to comment
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;

}

Link to comment
Share on other sites

  • 1 year later...

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

Link to comment
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

Link to comment
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

Link to comment
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

Link to comment
Share on other sites

  • 5 months later...

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?

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