سؤال

I am developing a plugin in elgg which has a some images for profile icon. in that plugin there are various sized file for a single image for eg

train.jpg = Height : 100px || Width : 100px

train_25px.jpg = Height : 25px || Width : 25px

Like above i have cropped images. there are about 25 images + 25 cropped images

i want to define one image per user and call the image at any time without recreating the same image in another location

for eg :

Original Location : sitepath/mod/plugin_name/graphic/profile_icon1/master.jpg

User Image Location : site_temp_path/year/month/user_guid/master.jpg

My php function is

global $CONFIG;

function identicon_init() {
    extend_view('profile/editicon', 'identicon/editicon');
    register_action('identicon/preference', false, $CONFIG->pluginspath . 'identicon/actions/preference.php');
    register_plugin_hook('entity:icon:url', 'user', 'identicon_usericon_hook', 900); 
}  


function identicon_usericon_hook($hook, $entity_type, $returnvalue, $params) {

    if (($hook == 'entity:icon:url') && ($params['entity'] instanceof ElggUser)) {
        $ent = $params['entity'];
        if ($ent->preferIdenticon || !$returnvalue) {
            return identicon_url($ent, $params['size']);
        }
    } else {
        return $returnvalue;
    }
}


function identicon_url($ent, $size) {
    global $CONFIG;
    return $CONFIG->wwwroot . 'mod/fp_auto_profile_image/img.php?entity=' . $ent->getGUID() . '&size=' . $size;
}

register_elgg_event_handler('init','system','identicon_init');
هل كانت مفيدة؟

المحلول

use elgg_get_data_path() instead of $CONFIG->wwwroot

then create icon.php and return path to icon.php in identicon_usericon_hook along with required with and size then in icon.php have this code

$news_guid = get_input('guid');

$contents = readfile(filepath);
$size = strtolower(get_input('size'));
if (!in_array($size, array('large', 'medium', 'small', 'tiny', 'master', 'topbar')))
$size = "large";


header("Content-type: image/jpeg");
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true);
header("Pragma: public");
header("Cache-Control: public");
header("Content-Length: " . strlen($contents));
header("ETag: \"$etag\"");
echo $contents;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top