Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 537
  • Last Modified:

Image Resize to fit custom width and height.

Hi

Can anyone recommend some code for resizing uploaded images to fit a custom width and height whilst keeping the correct ratio.

I have the image upload working fine but need code which takes the existing with and height and then resizes the image to fit a 186x123 thumb ( i can make it a square if need be)

I need the image aligned to the top.

I then need to pad out the image with whitespace on the left and right if the width is below 186.

I need to do the same with the height but if possible crop the whitespace from the bottom, if it goes below the defined height??

Has anyone got any suggestions!

Many thanks

--s--
0
socross
Asked:
socross
  • 8
  • 6
1 Solution
 
socrossAuthor Commented:
Ok Great Looks like it does everything i need

Could you advise how i could work it into my existing example, its a bit of mess at the moment as im reusing old code, i just need to get it working asap!

See attached file, it has the functions i use to upload the image and then two functions for creating a thumb and a main image, its the thumb i need to get working.

Many many thanks

--s--
core-fnc-image-upload.php.txt
0
 
RoonaanCommented:
The script I showed actually does not create a thumb on upload. It allows the creation of thumbs on the fly from your html.

You just create an <img> tag with <img src="thumbnailer.php?i=myimage.jpg&x=168&y=168" /> and have the script create your thumbnail.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
socrossAuthor Commented:
What impact does this have on server load, what happens if the image is quite large.

Does the image catch have something to do with this!

--s--
0
 
RoonaanCommented:
The size of the image should be filtered in the upload phase. As to realtime thumbnailing performance; that should be fine as a cache is build for the thumbnails that are created.
0
 
socrossAuthor Commented:
Excellent, looks ideal!

Will get it implemented this afternoon and get back to you.

Many thanks

--s--
0
 
socrossAuthor Commented:
Have implemented the script and it works great!!

With regards the catching, can you confirm where the folder needs to be placed and confim what you mean by '... to which the thumbnailer has write access." Does this just mean chmod 777.

I have placed the script in a directory called classes which is in the rot directory.

Many thanks

--s--

0
 
ayus80Commented:
study GDImage script for php
0
 
RoonaanCommented:
Doesn't need to be 777, can be 666 I think or even 664 if the php is running as apache user and the directory is owned by the apache user.
0
 
socrossAuthor Commented:
ok great but where does the folder need to be in relation to the thumnailer script??

--s--
0
 
socrossAuthor Commented:
roonaan

great script works a treat, just need to get the cache working, where do i need to store the cache folder??

Regards

--s--
0
 
RoonaanCommented:
You can create an image_cache folder, or edit the script to change the path to something you prefer.
0
 
socrossAuthor Commented:
Ok

Im still not 100% where i create the cache folder in relation to the thumbnailer script.

-s-
0
 
RoonaanCommented:
In same folder:

folder/thumbnailer.php
folder/imagecache/
0
 
socrossAuthor Commented:
Great Script

--s--
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now