Jamroom Logo Jamroom 5 Core
is now Open Source!
Follow Jamroom on Twitter!


Optional Module File: theme.php Index Optional Module File: get_counts.php

Jamroom Module Guide - image.php

If your Jamroom Module works with images that are uploaded by Jamroom users, then you can take advantage of Jamroom's image.php script to handle the display of your images.  This allows you to use all of the features that the Jamroom Image Script offers (such as caching, resizing and filters) on your own module images.

Here is a sample image.php - note that this code will NOT function properly without being customized to suit your needs.  This code is for illustration purposes only:

<?php
/**
 * Sample Module image.php script
 * @copyright 2009 by Talldude Networks LLC.
 * @author Brian Johnson - bigguy@jamroom.net
 */
defined('IN_JAMROOM') or exit();

/**
 * Image information function
 * @param array $_REQUEST PHP Array
 * @return mixed Returns array on success, false on failure
 */
function ModuleName_sample($_args)
{
    global $jamroom_db;
    if (!checkType($_args['media_id'],'number_nz')) {
        return(false);
    }
    $req = "SELECT *
              FROM {$jamroom_db['ModuleName']}
             WHERE m.module_column_id = '{$_args['media_id']}'";
    $_rt = dbQuery($req,'SINGLE');
    if (isset($_rt) && is_array($_rt)) {
        return($_rt);
    }
    return(false);
}
?>

You can see that this script is actually a very simple script.  The purpose of the single function is to return the information that Jamroom will use to find and display the proper image.  Starting from the top we see:

<?php
/**
 * Sample Module image.php script
 * @copyright 2009 by Talldude Networks LLC.
 * @author Brian Johnson - bigguy@jamroom.net
 */
defined('IN_JAMROOM') or exit();

Like our other module PHP scripts, it is important that we do our "IN_JAMROOM" check - this prevents the PHP script from being executed outside of Jamroom.

/**
 * Image information funtion
 * @param array $_REQUEST PHP Array
 * @return mixed Returns array on success, false on failure
 */
function ModuleName_sample($_args)
{

Next comes our function definition.  The function MUST be named properly, or Jamroom will not see it.  The proper naming convention is:

ModuleName_mode

This is the "mode" that would be used when calling your module image using Jamroom's image.php script.  So for our example function, when calling the image.php script, we would us:

<img src="image.php?mode=ModuleName_mode&media=## .... "

    global $jamroom_db;
    if (!checkType($_args['media_id'],'number_nz')) {
        return(false);
    }
    $req = "SELECT *
              FROM {$jamroom_db['ModuleName']}
             WHERE m.module_column_id = '{$_args['media_id']}'";
    $_rt = dbQuery($req,'SINGLE');
    if (isset($_rt) && is_array($_rt)) {
        return($_rt);
    }
    return(false);
}
?>

The rest of our script is where the actual "work" happens.  The function's purpose is to return the necessary information about the image so the image.php script can process it.  Note that you MUST include the Jamroom "band_info" and "quota" tables in your SQL query - this will ensure the query returns the profile and quota information needed to support the additional features of the image.php script (such as watermarking, etc.).  You also want to be sure that you validate any passed in parameters that you use in your SQL query - in this case we use the "checkType" function to ensure the incoming "module_unique_id" parameter is a number greater then 0.

Required Image Information

Any custom module image function must return at least the following information in an array:

  • image_size - this should be a INT column to store the size (in bytes) of the uploaded image
  • image_height - this should be an INT column to store the height of the image in pixels
  • image_width - this should be an INT column to store the width of the image in pixels
  • image_extension - this should be a VARCHAR column that will contain just the extension (file type) of the image.
  • image_time - this should be a 11 digit INT field to store the Epoch Time the image was created

This can be information that is retrieved from the database (if you are storing the image information in the database), or by querying the file on the file system to retrieve the information.

 

Optional Module File: theme.php Optional Module File: theme.php page 7 of 23 Optional Module File: get_counts.php Optional Module File: get_counts.php
Solutions Products Support Community Company
Social Media Platform
Social Networking Software
Musician Website Manager
Community Builder
Jamroom 5
Jamroom 5 Modules
Jamroom Marketplace
Support Forum
Documentation
Support Center
Contact Support
Community Forum
Member Sites
Developers
About Us
Contact Us
Privacy Policy
©2003 - 2024 The Jamroom Network