Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

resource_random_jpg()

Description

Generates a random JPEG image for a given resource with random background color and text.

This function creates an image of specified dimensions with a random background color
and text indicating the resource reference. The image is then saved to the resource's
designated path and also triggers the creation of previews for the resource.

Parameters

ColumnTypeDefaultDescription
$resource int The reference ID of the resource for which the image is being created.
$width int The width of the generated image in pixels.
$height int The height of the generated image in pixels.

Return

bool Returns true on success, indicating that the image was created and saved successfully.

Location

include/test_functions.php lines 17 to 37

Definition

 
function resource_random_jpg($resource,$width$height)
    {
    
// Set random colours 
    
$bg_r =  mt_rand(0,255);
    
$bg_g mt_rand(0,255);
    
$bg_b mt_rand(0,255);

    
// Create image
    
$test_image imagecreate($width$height);
    
$text_r $bg_r 128 $bg_r 100 $bg_r 100;
    
$text_g $bg_g 128 $bg_g 100 $bg_g 100;
    
$text_b $bg_b 128 $bg_b 100 $bg_b 100;
    
$text_col imagecolorallocate($test_image$text_r$text_g$text_b);
    
imagestring($test_image52015,  'Image ' $resource$text_col);

    
$path get_resource_path($resource,true,'',true,'jpg');
    
imagejpeg($test_image$path,50);
    
create_previews($resource,false,'jpg');

    return 
true;
    }

This article was last updated 17th November 2024 15:35 Europe/London time based on the source file dated 8th November 2024 11:45 Europe/London time.