ericek111

Width/height resizer

Aug 7th, 2014
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <?php
  2. $args = array(
  3.     'posts_per_page' => 4,
  4.     'orderby'  => 'rand',
  5.     'category__not_in' => 439
  6. );
  7. query_posts($args);
  8. while (have_posts()) : the_post(); $do_not_duplicate = $post->ID;
  9. $output = preg_match_all('/<img[^>]+src=[\'"]([^\'"]+)[\'"][^>]*>/i', get_the_content(), $matches);  
  10. $imageurl = $matches[1][0];
  11. $percenta = 100;
  12. $upravenawidth = 110;
  13. $upravenaheight = 110;
  14. list($width, $height) = getimagesize($imageurl);
  15. if($height > $upravenaheight && $width <= $upravenawidth)
  16. {
  17. while($height > $upravenaheight ){
  18. $percenta = $percenta - 1;
  19. $height = $height / 100 * $percenta;
  20. $width = $width / 100 * $percenta;
  21. }
  22. }
  23.  
  24. if($width > $upravenawidth && $height <= $upravenaheight)
  25. {
  26. while($width > $upravenawidth ){
  27. $percenta = $percenta - 1;
  28. $width = $width / 100 * $percenta;
  29. $height = $height / 100 * $percenta;
  30. }
  31. }
  32.  
  33. if($width > $upravenawidth && $height > $upravenaheight)
  34. {
  35. while($width > $upravenawidth ){
  36. $percenta = $percenta - 1;
  37. $width = $width / 100 * $percenta;
  38. $height = $height / 100 * $percenta;
  39. }
  40. while($height > $upravenaheight ){
  41. $percenta = $percenta - 1;
  42. $width = $width / 100 * $percenta;
  43. $height = $height / 100 * $percenta;
  44. }
  45. }
  46. ?>
  47. <div class="bf-border">
  48. <div class="rssitem"><div class="pinkhover">
  49. <a class="clickable" href="<? the_permalink(); ?>" rel="bookmark" title="" target="_top"><? the_title(); ?></a><br /><br /><br /></div>
  50.  
  51. <div class="rssanotacia"><a href="<? the_permalink(); ?>" rel="bookmark" title="" target="_top"><img src="<?php echo $imageurl; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" style="margin-top:<?php echo((110 - $height) / 2); ?>px" /></a></div>
  52.  
  53. </div>
  54. </div>
  55. <br />
  56. <?php endwhile; ?>
Advertisement
Add Comment
Please, Sign In to add comment