我正在开发一个在elgg插件,其中有一些图像为配置文件图标。在那个插件中,有不同大小的文件用于单个图像。
train.jpg = Height : 100px || Width : 100px
train_25px.jpg = Height : 25px || Width : 25px就像上面一样,我剪下了图像。有关于25 images + 25 cropped images的
我希望为每个用户定义一个图像,并在任何时候调用该图像,而不需要在另一个位置重新创建相同的图像。
例如:
原址:sitepath/mod/plugin_name/graphic/profile_icon1/master.jpg
用户图像定位:site_temp_path/year/month/user_guid/master.jpg
我的php函数是
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');发布于 2015-04-16 11:27:58
使用elgg_get_data_path()代替$CONFIG->wwwroot
然后创建icon.php并在identicon_usericon_hook中返回到icon.php的路径以及所需的和大小,然后在icon.php中有以下代码
$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;https://stackoverflow.com/questions/22471595
复制相似问题