0

May i know is there any simple codes to scale images i have retrieved from my database to be displayed. There are many solutions out that but it seems all of them are pretty complex to me.

Basically, im just fetching the image file from a database and displaying it. I want images displayed to be in uniform dimensions.

  • http://stackoverflow.com/questions/4590441/php-thumbnail-image-resizing-with-proportions?rq=1 – nand Aug 05 '13 at 18:41

3 Answers3

4

If you are looking for simplicity, I suggest you use CSS to scale the image.

Look at this threat: Resize image proportionally with CSS?

You can also use the CSS clip property to crop the image as you want it to be: http://www.w3schools.com/cssref/pr_pos_clip.asp

Community
  • 1
  • 1
flakomalo
  • 710
  • 5
  • 4
2
<?php
$image = new Imagick( $filename );
$image->resizeImage(200,200, imagick::FILTER_LANCZOS, 0.9, true);
?>

you will need Imagemagik api for this or do it with css way, like above said

shashikant_
  • 122
  • 5
0

The image size is somewhat independent from the file size because bit depth resolution is the major factor in file size. But for scaling, and keeping aspect ratio (so it doesn't look funny) you would find the proportional equivalent for height with the fixed target width. Images stored in a table is a big performance hit compared to storing them on the webstorage, but we can discuss alternatives to this.

for an example, lets say you want to have a fixed width of 500, but the picture is 1280x900.

cross multiply the ratio 1280/900 with 500/x to result in (450000)=1280x and now solve X=(450000)/1280 or x=351.5625 for the new height.

so we can translate this to php like:

   //detect picture size
 list($width, $height, $type, $attr) = getimagesize("image_file_name.gif");

Since we already know out target width, lets get our target height by using a simplified version of our cross-multiplication:

  $newHeight=($height*500)/$width;

Now all we have to do now is to use a resizer method since now we have target height too.

this is a good article on this subject: https://dzone.com/articles/resize-image-class-php

I don't have time right now for a detailed post.

drtechno
  • 298
  • 2
  • 9