Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Contribution 2094 - Image resize


galen

Recommended Posts

I really like this contribution, thank you.

 

One quick question, couldn't this code:

 

if ( !strstr($width, '%') && $res) {

$width = round($width);

$height = round($height);

preg_match("/.*\/(.*)\.(\w*)$/", $src, $fname);

list($oiwidth, $oiheight, $oitype) = getimagesize($src);

if (($width || $height) && ($height < $oiheight || $width < $oiwidth)) {

if (!$height) $height = 1;

if (!$width) $width = 1;

$k = max($oiheight / $height, $oiwidth / $width); //use smallest size

$width = round($oiwidth / $k);

$height = round($oiheight / $k);

// createthumb($filename, $width, $height, "test.jpg");

$filename_small = DIR_WS_RSIMAGES . $fname[1] . '_' . $width . '_' . $height . '.' . $fname[2];

if (!file_exists($filename_small)) {

copy($src, $filename_small);

exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $width . " " . $filename_small);

}

$src = $filename_small;

}

}

 

be changed to this:

 

if ( !strstr($width, '%') && $res) {

$width = round($width);

$height = round($height);

preg_match("/.*\/(.*)\.(\w*)$/", $src, $fname);

if (!file_exists($filename_small)) {

list($oiwidth, $oiheight, $oitype) = getimagesize($src);

if (($width || $height) && ($height < $oiheight || $width < $oiwidth)) {

if (!$height) $height = 1;

if (!$width) $width = 1;

$k = max($oiheight / $height, $oiwidth / $width); //use smallest size

$width = round($oiwidth / $k);

$height = round($oiheight / $k);

// createthumb($filename, $width, $height, "test.jpg");

$filename_small = DIR_WS_RSIMAGES . $fname[1] . '_' . $width . '_' . $height . '.' . $fname[2];

 

copy($src, $filename_small);

exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $width . " " . $filename_small);

}

$src = $filename_small;

}

}

Link to comment
Share on other sites

  • Replies 133
  • Created
  • Last Reply

Top Posters In This Topic

Hi Yakseller,

 

For the admin section, i kinda looked at it and i'm sure you have read my notes in the config files.. but it isn't really a proeity for me... so i kinda left it alone.

 

The problem occours when its looking for images.. i'm sure i could get it working now as i had to mod a little more code to convert it from /catalog/images to http://url/catalog/images..

 

The problem with the admin section is you need it to goto direct links.. Heres a little bit of code that mite help for the admin when placed at the top.. its a little expanded as my regexps skills aren't that great

 

$exacturl=0;

if (!is_file($src)){

$test=explode ("/", $src);

$domain=explode ("/", HTTP_SERVER);

if ($test[2]==$domain[2]){

$src=DIR_WS_IMAGES.$test['5'];

$exacturl=1;

}

}

 

 

then after the $src=$filename_small }}

add in this

 

if($exacturl==1){

$src = HTTP_SERVER.DIR_WS_HTTP_CATALOG.$src;

}

 

I use the above code for my html emails.. as it was linking to the non-resized images.

 

As for your re-coding.. you are testing if a varable exists before it is defined($filename_small)

 

so I wouldn't suggest using it. The resized image name needs to be worked out before it can been seen there.

 

If the original images changes in size, it will put another image in there.

 

If you change this line

 

$filename_small = DIR_WS_RSIMAGES . $fname[1] . '_' . $width . '_' . $height . '.' . $fname[2];

 

to something like

 

$filename_small = DIR_WS_RSIMAGES . $fname[1] . '_small' . '.' . $fname[2];

 

then all the resized images would be under the same name and you could define $filename_small before the if statement.

 

Galen

Link to comment
Share on other sites

Hi Shanna,

 

Heres something to try..

 

Where the tep image function is... add this echo statement in..

 

After this line

function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '', $res = 1, $addattribs = 1){

Add in

echo $src;

 

This will tell you if the function is being called, and if it is it will echo $src which will probably be along the lines of images/image.name.jpg

 

This is probably the first step to see if the function is actually being called.

Link to comment
Share on other sites

Hi Shanna,

 

well this is a good sign.... now lets proceed to find how they are seeing them

 

can you please paste to me your

 

DIR_WS_IMAGES and tell me what your IMAGE_REQUIRED is set to..

 

you also can move the echo statement into this if statements

 

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

echo $src;

return false;

}

 

If you are seeing the /images/imagename still comment out that if statment by placing // in front of each line.

 

Remember we are still playing.. this isn't a solution.

 

Galen

Link to comment
Share on other sites

Hi Galen! Ok.. in my configure.php here is what the DIR WS IMAGES line says:

 

define('DIR_WS_IMAGES', '/bowtique/images/');

 

Is that what you are looking for? The Image Required in my admin is set to True.

 

I replaced the echo statement with the if statement you posted and I still see the same thing. You can see here:

 

Ragabelle Bowtique

 

I can comment this out if you want me to. Just LMK. And.. If i did somehting wrong... LMK. I can change stuff ASAP.

 

Thanks Galen!

 

Shanna

Link to comment
Share on other sites

ok,

 

the fact that you can still see this is bad.. eg why its not working

 

probably whats happening is !is_file($src) isn't seeing it as a real file..

 

comment out that bit which I said in the previous post.

 

You should see some kind of picutres then.

 

then we will do some tests to see which of the following in that statment is causing the problems..

 

Galen

Link to comment
Share on other sites

Just for other users who have problems similar to shanna's make sure in your configure.php DIR_WS_IMAGES are defined correctly..

 

They should look like this...

 

define('DIR_WS_IMAGES', 'images/');

define('DIR_WS_ICONS', 'icons/');

define('DIR_WS_RSIMAGES', DIR_WS_IMAGES . 'res/');

 

 

This ended up being the problem.

 

Galen

Link to comment
Share on other sites

Instead of creating thumbnails at the same ratio as the larger images, is it possible to pad an image with white to make all thumbnails the same size?

 

Thanks in advance... I tried messing with mogrify without too much luck.

Link to comment
Share on other sites

I was able to do what I would like to do ay the command line by doing this:

 

$convert -size 100x80 xc:white canvas.jpg

$composite -gravity center input.jpg canvas.jpg output.jpg

 

I tried incorporating it into the contrib unsuccessfully. Before these two lines, I rescaled the image using the same mogrify line in the contib.

 

Thanks for any help in advance.

Link to comment
Share on other sites

I have now read the whole topic...

 

But I still have problems.. There is now pictures showing up on my page.. But in my images/res/ directory there is alot of new picture files...

 

But why dosn't their show up on the page...

 

My configure.php:

 

define('DIR_WS_IMAGES', 'images/');

define('DIR_WS_RSIMAGES', DIR_WS_IMAGES . 'res/');

define('DIR_WS_ICONS', DIR_WS_IMAGES . 'icons/');

define('DIR_IMAGEMAGICK', '/usr/bin/');

 

It is producering the pictures but not showing them ?? Anyone have a solution on this problem ?

/Olzen

Link to comment
Share on other sites

ok,

 

chrisstylez,

 

is it possible to use the GD library 2x with this contribution? or is it limited to only IMAGEMAGICK, becuase i can't get this to work for the life of it.

 

yes it is possilbe to use other image librarys/programs. All you need to change is this line..

 

exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $width . " " . $filename_small);

 

all that does is excute mogrify ... like you were using a command line so you can change it to other programs.

 

you may already find that imagemagick is installed in /usr/bin or /usr/local/bin

 

 

yakseller

$convert -size 100x80 xc:white canvas.jpg

 

if that is the command you used.. then its wrong.. you need to use this..

 

exec(DIR_IMAGEMAGICK . "convert -size 100x80 xc:white . " $filename_small. " ");

 

Olzen

 

Have a look at the source and see if its actaully putting the image tag in there..

 

If its not then its not finding the image files.. all looks good with your define statements. Also make sure that the /res/ directory has the re-sized images in there as the function copies the original image then re-sizes.

 

Also place and echo statment at the end of the tep_image function to check that its calling it and you can check the results of the function as it progresses throught.

 

sorry for the rushed respone guys.. if you can't make sence just re-post :)

gotta run..

 

Galen

Link to comment
Share on other sites

It is a little bit embarrassing, but the only thong I did to get it to work was change 1 to 100... :-)

 

if (($width || $height) && ($height < $oiheight || $width < $oiwidth)) {

if (!$height) $height = 100;

if (!$width) $width = 100;

/Olzen

Link to comment
Share on other sites

This is a great conrib and I have it working perfectly (at least I haven't noticed any problems yet) but in the description it mentions it's possible to make this watermark your images as well.

 

Anyone tried this yet? A quick search of the imagemagick.org website yeilds no results on watermarking but I was thinking of trying to tackle this... I'm just not exactly sure where to start.

 

-Ryan

Link to comment
Share on other sites

Ryan:

 

Sorry to disappoint you but resize is not working. It is copying an image to your res directory but the image is exactly the same size as your original. You can verify this by right clicking on the thumbnail and choose view image. If it were working you would then see a small resized image. Instead you are viewing the original size photo.

Link to comment
Share on other sites

Ryan,

 

Dennisra is correct the resize is not working. This is directly related to imagemagick, either its not installed or you haven't defined IMAGEMAGICK_DIR to the correct location.

 

As for the watermarks have a look at this page.

 

http://www.cit.gu.edu.au/~anthony/graphics...tating/#overlay

 

Remember only the thumbnail picture is changed, the original image(the click to see larger image) is not changed.

 

Regards

Galen

Link to comment
Share on other sites

Thanks to both of you -- I just assumed since I didn't get any error messages (which I have before with other programs when the path to ImageMagick was wrong) that it was all working correctly. I guess it was just my imagination that the pages seemed to load faster as well.

 

Goes to show you what assuming makes me...

 

It's all working now, thanks.

 

-Ryan

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