本文整理汇总了PHP中Toolbox::resizePicture方法的典型用法代码示例。如果您正苦于以下问题:PHP Toolbox::resizePicture方法的具体用法?PHP Toolbox::resizePicture怎么用?PHP Toolbox::resizePicture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Toolbox
的用法示例。
在下文中一共展示了Toolbox::resizePicture方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: syncLdapPhoto
/**
* Synchronise picture (photo) of the user
*
* ÷@since version 0.85
*
* @return string : the filename to be stored in user picture field
**/
function syncLdapPhoto()
{
if (isset($this->fields["authtype"]) && ($this->fields["authtype"] == Auth::LDAP || Auth::isAlternateAuth($this->fields['authtype']))) {
if (isset($this->fields["id"]) && $this->fields["id"] > 0) {
$config_ldap = new AuthLDAP();
$ds = false;
//connect ldap server
if ($config_ldap->getFromDB($this->fields['auths_id'])) {
$ds = $config_ldap->connect();
}
if ($ds) {
//get picture fields
$picture_field = $config_ldap->fields['picture_field'];
if (empty($picture_field)) {
return false;
}
//get picture content in ldap
$info = AuthLdap::getUserByDn($ds, $this->fields['user_dn'], array($picture_field), false);
//getUserByDn returns an array. If the picture is empty,
//$info[$picture_field][0] is null
if (!isset($info[$picture_field][0]) || empty($info[$picture_field][0])) {
return "";
}
//prepare paths
$img = array_pop($info[$picture_field]);
$filename = uniqid($this->fields['id'] . '_');
$sub = substr($filename, -2);
/* 2 hex digit */
$file = GLPI_PICTURE_DIR . "/{$sub}/{$filename}.jpg";
$oldfile = GLPI_PICTURE_DIR . "/" . $this->fields["picture"];
// update picture if not exist or changed
if (!file_exists($oldfile) || sha1_file($oldfile) !== sha1($img)) {
if (!is_dir(GLPI_PICTURE_DIR . "/{$sub}")) {
mkdir(GLPI_PICTURE_DIR . "/{$sub}");
}
//save picture
$outjpeg = fopen($file, 'wb');
fwrite($outjpeg, $img);
fclose($outjpeg);
//save thumbnail
$thumb = GLPI_PICTURE_DIR . "/{$sub}/{$filename}_min.jpg";
Toolbox::resizePicture($file, $thumb);
return "{$sub}/{$filename}.jpg";
}
return $this->fields["picture"];
}
}
}
return false;
}
示例2: addFiles
/**
* add files (from $this->input['_filename']) to an ITIL object
* create document if needed
* create link from document to ITIL object
*
* @param $donotif Boolean if we want to raise notification (default 1)
* @param $disablenotif (default 0)
*
* @return array of doc added name
**/
function addFiles($donotif = 1, $disablenotif = 0)
{
global $CFG_GLPI;
if (!isset($this->input['_filename']) || count($this->input['_filename']) == 0) {
return array();
}
$docadded = array();
foreach ($this->input['_filename'] as $key => $file) {
$doc = new Document();
$docitem = new Document_Item();
$docID = 0;
$filename = GLPI_TMP_DIR . "/" . $file;
$input2 = array();
// Crop/Resize image file if needed
if (isset($this->input['_coordinates']) && !empty($this->input['_coordinates'][$key])) {
$image_coordinates = json_decode(urldecode($this->input['_coordinates'][$key]), true);
Toolbox::resizePicture($filename, $filename, $image_coordinates['img_w'], $image_coordinates['img_h'], $image_coordinates['img_y'], $image_coordinates['img_x'], $image_coordinates['img_w'], $image_coordinates['img_h'], 0);
} else {
Toolbox::resizePicture($filename, $filename, 0, 0, 0, 0, 0, 0, 0);
}
//If file tag is present
if (isset($this->input['_tag_filename']) && !empty($this->input['_tag_filename'][$key])) {
$this->input['_tag'][$key] = $this->input['_tag_filename'][$key];
}
// Check for duplicate
if ($doc->getFromDBbyContent($this->fields["entities_id"], $filename)) {
if (!$doc->fields['is_blacklisted']) {
$docID = $doc->fields["id"];
}
// File already exist, we replace the tag by the existing one
if (isset($this->input['_tag'][$key]) && $docID > 0 && isset($this->input['content'])) {
$this->input['content'] = preg_replace('/' . Document::getImageTag($this->input['_tag'][$key]) . '/', Document::getImageTag($doc->fields["tag"]), $this->input['content']);
$docadded[$docID]['tag'] = $doc->fields["tag"];
}
} else {
//TRANS: Default document to files attached to tickets : %d is the ticket id
$input2["name"] = addslashes(sprintf(__('Document Ticket %d'), $this->getID()));
if ($this->getType() == 'Ticket') {
$input2["tickets_id"] = $this->getID();
// Insert image tag
if (isset($this->input['_tag'][$key])) {
$input2["tag"] = $this->input['_tag'][$key];
}
}
$input2["entities_id"] = $this->fields["entities_id"];
$input2["documentcategories_id"] = $CFG_GLPI["documentcategories_id_forticket"];
$input2["_only_if_upload_succeed"] = 1;
$input2["entities_id"] = $this->fields["entities_id"];
$input2["_filename"] = array($file);
$docID = $doc->add($input2);
}
if ($docID > 0) {
if ($docitem->add(array('documents_id' => $docID, '_do_notif' => $donotif, '_disablenotif' => $disablenotif, 'itemtype' => $this->getType(), 'items_id' => $this->getID()))) {
$docadded[$docID]['data'] = sprintf(__('%1$s - %2$s'), stripslashes($doc->fields["name"]), stripslashes($doc->fields["filename"]));
if (isset($input2["tag"])) {
$docadded[$docID]['tag'] = $input2["tag"];
unset($this->input['_filename'][$key]);
unset($this->input['_tag'][$key]);
}
if (isset($this->input['_coordinates'][$key])) {
unset($this->input['_coordinates'][$key]);
}
}
}
// Only notification for the first New doc
$donotif = 0;
}
// Ticket update
if (isset($this->input['content'])) {
if ($CFG_GLPI["use_rich_text"]) {
$this->input['content'] = $this->convertTagToImage($this->input['content'], true, $docadded);
$this->input['_forcenotif'] = true;
} else {
$this->fields['content'] = $this->setSimpleTextContent($this->input['content']);
$this->updateInDB(array('content'));
}
}
return $docadded;
}
示例3: syncLdapPhoto
/**
* Synchronise picture (photo) of the user
*
* ÷@since version 0.85
*
* @return string : the filename to be stored in user picture field
**/
function syncLdapPhoto()
{
if (isset($this->fields["authtype"]) && $this->fields["authtype"] == Auth::LDAP) {
if (isset($this->fields["id"]) && $this->fields["id"] > 0) {
$config_ldap = new AuthLDAP();
$ds = false;
//connect ldap server
if ($config_ldap->getFromDB($this->fields['auths_id'])) {
$ds = $config_ldap->connect();
}
if ($ds) {
//get picture fields
$picture_field = $config_ldap->fields['picture_field'];
if (empty($picture_field)) {
return false;
}
//get picture content in ldap
$info = AuthLdap::getUserByDn($ds, $this->fields['user_dn'], array($picture_field), false);
//getUserByDn returns an array. If the picture is empty,
//$info[$picture_field][0] is null
if (!isset($info[$picture_field][0]) || empty($info[$picture_field][0])) {
return "";
}
//prepare paths
$img = array_pop($info[$picture_field]);
$filename = $this->fields["id"];
$file = GLPI_PICTURE_DIR . "/" . $filename . '.jpg';
//save picture
$outjpeg = fopen($file, 'wb');
fwrite($outjpeg, $img);
fclose($outjpeg);
//save thumbnail
$thumb = GLPI_PICTURE_DIR . "/" . $filename . '_min.jpg';
Toolbox::resizePicture($file, $thumb);
return $filename . ".jpg";
}
}
}
return false;
}