I have a function that pulls images from an external location and the arrive with the proportions of 952 x 390
but they are displayed on my site 960 by 380
is there anyway using PHP that I could change the ratio so they do not look so stretched?
Asked
Active
Viewed 107 times
0

Jess McKenzie
- 8,345
- 27
- 100
- 170
-
quick - you can just specify it in the image tag, img width=, height=, most browsers will display that way. – cartalot Dec 01 '12 at 00:49
1 Answers
0
Use the codigniters Image Library and parse maintain_ratio as one of the attributes
$this->load->library('image_lib');
$params = array();
$params['source_image'] = /path/to/image
$params['new_image'] = /path/to/mynewimage
$params['width'] = 960;
$params['height'] = 380; //leave height or with only for aspect ratio to work
$params['maintain_ratio'] = true;
$this->image_lib->initialize($params);
$this->image_lib->resize();

Elijan
- 1,406
- 1
- 8
- 11
-
Thanks, interms of the source_image & new_image does this mean I have to save them to server? – Jess McKenzie Nov 30 '12 at 06:32
-
Yes they will have to be on the server. Won't you need to crop them, rather than resize them? – Jeemusu Nov 30 '12 at 07:39