This topic is locked

Image upload to fit area.

4/28/2010 3:14:11 PM
PHPRunner General questions
R
rpain author

Hi,
I need to be able to resize a image to fit in a certain area on upload. I know that I can set the max height or width (which would allow a picture to fit within a square) but I'd like to set it so a picture that's uploaded will fit into a non square area (slightly landscape in proportions). This would mean that a portrait picture would have white area around it. See:
http://www.rightmove.co.uk/property-for-sale/property-10272792.html
The middle of the thumbnails is an example of this.
Is there any way I can set this up in the upload system?
Thanks,

Richard

Sergey Kornilov admin 4/28/2010

Richard,
PHPRunner, unfortunately, doesn't provide this functionality out of the box.
You can try to implement what you looking using events. Here are a few links to get started.
http://xlinesoft.com/phprunner/docs/check_size_and_extension_of_uploadfiles.htm

http://xlinesoft.com/phprunner/docs/rename_uploaded_file.htm

http://xlinesoft.com/phprunner/docs/upload_files_to_users_folders.htm

R
rpain author 4/29/2010



Richard,
PHPRunner, unfortunately, doesn't provide this functionality out of the box.
You can try to implement what you looking using events. Here are a few links to get started.
http://xlinesoft.com/phprunner/docs/check_size_and_extension_of_uploadfiles.htm

http://xlinesoft.com/phprunner/docs/rename_uploaded_file.htm

http://xlinesoft.com/phprunner/docs/upload_files_to_users_folders.htm


OK....then is there a way I can just set the max height to a certain value? The landscape shots will fit exactly and the portrait will be squashed (in proportion) which would also be fine.
If this isn't possible then can you think of another solution? I took a look at the links about but they only referred to filesize and not pixel size.
Thanks,

Richard

Sergey Kornilov admin 4/29/2010

Setting max height of thumbnails is not possible - that's why you need to roll your own solution.
Check CreateThumbnail() function in phpfunctions.php file. The current implementation calculates both height and width:

$width_old = imagesx($image);

$height_old = imagesy($image);



if($width_old>$size || $height_old>$size){

if($width_old>=$height_old)

{

$final_height=(integer)($height_old*$size/$width_old);

$final_width=$size;

}

else

{

$final_width=(integer)($width_old*$size/$height_old);

$final_height=$size;

}


You can change this piece of code to take in account image height only. Please note that this change will affect all thumbnails-related functionality.

R
rpain author 4/30/2010



Setting max height of thumbnails is not possible - that's why you need to roll your own solution.
Check CreateThumbnail() function in phpfunctions.php file. The current implementation calculates both height and width:

$width_old = imagesx($image);

$height_old = imagesy($image);
if($width_old>$size || $height_old>$size){

if($width_old>=$height_old)

{

$final_height=(integer)($height_old*$size/$width_old);

$final_width=$size;

}

else

{

$final_width=(integer)($width_old*$size/$height_old);

$final_height=$size;

}


You can change this piece of code to take in account image height only. Please note that this change will affect all thumbnails-related functionality.


Thanks I'll have a play.
Richard