<?php

class ImageHelper {
  /**
   * Stores the reference to the Page Helper
   */
  private static $_instance = null;

  public static function getInstance()
  {
    if (is_null(self::$_instance)) {
      self::$_instance = new self();
    }

    return self::$_instance;
  }

  /**
   * Return the URL for an image at the required size
   * @param String $imageUrl - The full size URL of the image
   * @param String $size - The size of image you want back
   * @return String - The URL of the image at that size
   */
  public function getImageUrlAtSize( $image_url, $size ) 
  {
    global $wpdb;
    $prefix = $wpdb->prefix;
    $attachment = $wpdb->get_col( "SELECT ID FROM " . $prefix . "posts" . " WHERE guid='" . $image_url . "';"  );
    $imageData = wp_get_attachment_image_src( $attachment[0], $size );
    
    return $imageData[0];
  }
}