PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/forumrunner/image.php

https://gitlab.com/elasa/vb-elasa.ir
PHP | 74 lines | 54 code | 11 blank | 9 comment | 16 complexity | 31379bf3e364e44025796ccf518eb123 MD5 | raw file
  1. <?php
  2. /*
  3. * Forum Runner
  4. *
  5. * Copyright (c) 2010-2011 to End of Time Studios, LLC
  6. *
  7. * This file may not be redistributed in whole or significant part.
  8. *
  9. * http://www.forumrunner.com
  10. */
  11. define('MCWD', (($getcwd = getcwd()) ? $getcwd : '.'));
  12. require_once(MCWD . '/support/utils.php');
  13. require_once(MCWD . '/support/Snoopy.class.php');
  14. $args = process_input(
  15. array(
  16. 'url' => STRING,
  17. 'w' => INTEGER,
  18. 'h' => INTEGER,
  19. )
  20. );
  21. if (isset($args['w']) && ($args['w'] > 1024 || $args['w'] <= 0)) {
  22. $args['w'] = 75;
  23. }
  24. if (isset($args['h']) && ($args['h'] > 1024 || $args['h'] <= 0)) {
  25. $args['h'] = 75;
  26. }
  27. if (!$args['url']) {
  28. return;
  29. }
  30. if (!extension_loaded('gd') && !extension_loaded('gd2')) {
  31. trigger_error("GD is not loaded", E_USER_ERROR);
  32. exit;
  33. }
  34. $snoopy = new snoopy();
  35. $snoopy->cookies = $_COOKIE;
  36. $args['url'] = trim(str_replace(' ', '%20', $args['url']));
  37. if ($snoopy->fetch($args['url'])) {
  38. $image = @imagecreatefromstring($snoopy->results);
  39. if ($image) {
  40. if (isset($args['w']) && isset($args['h'])) {
  41. $oldwidth = imagesx($image);
  42. $oldheight = imagesy($image);
  43. $newwidth = $oldwidth;
  44. $newheight = $oldheight;
  45. if ($oldwidth > $oldheight) {
  46. $newwidth = $args['w'];
  47. $newheight = ((float)$newwidth / (float)$oldwidth) * $oldheight;
  48. } else {
  49. $newheight = $args['h'];
  50. $newwidth = ((float)$newheight / (float)$oldheight) * $oldwidth;
  51. }
  52. $new_image = imagecreatetruecolor($newwidth, $newheight);
  53. imagecopyresampled($new_image, $image, 0, 0, 0, 0, $newwidth, $newheight, imagesx($image), imagesy($image));
  54. header('Content-type: image/jpeg');
  55. imagejpeg($new_image);
  56. exit;
  57. } else {
  58. header('Content-type: image/jpeg');
  59. imagejpeg($image);
  60. exit;
  61. }
  62. }
  63. }