Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP- I want to display the image with specifec height n width

Tags:

html

cakephp

I am creating a cakephp application in which im uploading a image. But on some functionality of my app i want to display the image in specific height n width, without compromissing in image quality. So please suggest me if ther is any way to do this.

like image 998
sandeep Avatar asked Dec 09 '22 13:12

sandeep


2 Answers

You can set only width or height attribute and to leave empty the other one. This way the image will be shown with proper resolution.

But, the performance really depends how big is the image.

Your code will be something like:

$this->Html->image('image1.jpg', array('width'=>'200px'));
like image 180
Nik Chankov Avatar answered May 01 '23 22:05

Nik Chankov


I suggest you to use a Plugin and its relatively simple..

http://www.milesj.me/resources/script/uploader-plugin

its very easy to implement. it takes care of validation and also attaching it to the model etc.

Organising the Images

  1. Store the user submitted original photos as it is in a folder called say original. so that incase u later change the theme or layout u can write a script to get various thumb nails :D
  2. store various sizes in their own folder say u have 200*200, 125*125, 50*50 you can store them in either folders with names with the sizes or like - large, medium, small.

  3. the reason why we are using different folders is. the file name will be the same for all sized versions only folder will change. so it relatively eaiser to be addressed than renaming the files while resizing and cropping.

There are many more plugins out there. here is a good list

http://josediazgonzalez.com/2010/08/16/cakephp-plugins-a-biblical-retelling/

here is a directory for cakephp related resources

http://cakepackages.com/

Hope this helps

like image 31
Harsha M V Avatar answered May 01 '23 20:05

Harsha M V