Guest User

Untitled

a guest
Jul 27th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. function beautyImg($img, $w, $h)
  2. {
  3. $img = (substr($img, 0, 1) == '/' && substr($img, 0, 4) !='http') ? substr(base_url(), 0, -1) .$img : $img;
  4. list($width, $height) = getimagesize($img);
  5. $scale_ratio = $width / $height;
  6. $sr = $w / $h;
  7. ?>
  8. <img style="<?php echo ($scale_ratio < $sr) ? 'width:' .$w .'px;margin-top:-' .intval((intval($w / $scale_ratio) - $h) / 2) .'px': 'height:' .$h .'px;margin-left:-' .intval(($h * $scale_ratio - $w) / 2) .'px'; ?>" src="<?php echo $img; ?>"/>
  9. <?php
  10. }
Add Comment
Please, Sign In to add comment