function performPhotoUpload($sTmpFile, $aFileInfo, $bAutoAssign2Profile = false, $isMoveUploadedFile = true, $iChangingPhotoID = 0, $iAuthorId = 0) { global $dir; $iLastID = -1; if (!$iAuthorId) { $iAuthorId = $this->_iOwnerId; } $this->oModule = BxDolModule::getInstance('BxPhotosModule'); // checker for flash uploader if (!$this->oModule->_iProfileId) { $this->oModule->_iProfileId = $this->_iOwnerId; } if (!$iAuthorId || file_exists($sTmpFile) == false || !$this->oModule->isAllowedAdd(FALSE, FALSE, FALSE)) { return false; } $sMediaDir = $this->oModule->_oConfig->getFilesPath(); if (!$sMediaDir) { @unlink($sTmpFile); return false; } $sTempFileName = $sMediaDir . $iAuthorId . '_temp'; @unlink($sTempFileName); if ($isMoveUploadedFile && is_uploaded_file($sTmpFile) || !$isMoveUploadedFile) { if ($isMoveUploadedFile) { move_uploaded_file($sTmpFile, $sTempFileName); @unlink($sTmpFile); } else { $sTempFileName = $sTmpFile; } @chmod($sTempFileName, 0644); if (file_exists($sTempFileName) && filesize($sTempFileName) > 0) { $aSize = getimagesize($sTempFileName); if (!$aSize) { @unlink($sTempFileName); return false; } switch ($aSize[2]) { case IMAGETYPE_JPEG: $sExtension = '.jpg'; break; case IMAGETYPE_GIF: $sExtension = '.gif'; break; case IMAGETYPE_PNG: $sExtension = '.png'; break; default: @unlink($sTempFileName); return false; } $sStatus = 'processing'; $iImgWidth = (int) $aSize[0]; $iImgHeight = (int) $aSize[1]; $sDimension = $iImgWidth . 'x' . $iImgHeight; $sFileSize = sprintf("%u", filesize($sTempFileName) / 1024); if ($iChangingPhotoID == 0) { if (is_array($aFileInfo) && count($aFileInfo) > 0) { $aFileInfo['dimension'] = $sDimension; $iLastID = $this->insertSharedMediaToDb($sExtension, $aFileInfo, $iAuthorId); } else { $sExtDb = trim($sExtension, '.'); $sMedUri = $sCurTime = time(); $sTitleDescTemp = $this->sTempFilename != '' ? $this->sTempFilename : $iAuthorId . '_temp'; if (getParam('bx_photos_activation') == 'on') { $bAutoActivate = true; $sStatus = 'approved'; } else { $bAutoActivate = false; $sStatus = 'pending'; } $sAlbum = $_POST['extra_param_album']; $aAlbumParams = isset($_POST['extra_param_albumPrivacy']) ? array('privacy' => (int) $_POST['extra_param_albumPrivacy']) : array(); $iLastID = $this->oModule->_oDb->insertData(array('medProfId' => $iAuthorId, 'medExt' => $sExtDb, 'medTitle' => $sTitleDescTemp, 'medUri' => $sMedUri, 'medDesc' => $sTitleDescTemp, 'medTags' => '', 'Categories' => PROFILE_PHOTO_CATEGORY, 'medSize' => $sDimension, 'Approved' => $sStatus, 'medDate' => $sCurTime)); $this->addObjectToAlbum($this->oModule->oAlbums, $sAlbum, $iLastID, $bAutoActivate, $iAuthorId, $aAlbumParams); $this->oModule->isAllowedAdd(true, true); } } else { $iLastID = $iChangingPhotoID; $this->updateMediaShared($iLastID, $aFileInfo); } $sFunc = $isMoveUploadedFile ? 'rename' : 'copy'; if (!$sFunc($sTempFileName, $sMediaDir . $iLastID . $sExtension)) { @unlink($sTempFileName); return false; } $this->sSendFileInfoFormCaption = $iLastID . $sExtension . " ({$sDimension}) ({$sFileSize}kb)"; $sFile = $sMediaDir . $iLastID . $sExtension; // watermark postprocessing if (getParam('enable_watermark') == 'on') { $iTransparent = getParam('transparent1'); $sWaterMark = $dir['profileImage'] . getParam('Water_Mark'); if (strlen(getParam('Water_Mark')) && file_exists($sWaterMark)) { applyWatermark($sFile, $sFile, $sWaterMark, $iTransparent); } } // generate present pics foreach ($this->oModule->_oConfig->aFilesConfig as $sKey => $aValue) { if (!isset($aValue['size_def'])) { continue; } $iWidth = (int) $this->oModule->_oConfig->getGlParam($sKey . '_width'); $iHeight = (int) $this->oModule->_oConfig->getGlParam($sKey . '_height'); if ($iWidth == 0) { $iWidth = $aValue['size_def']; } if ($iHeight == 0) { $iHeight = $aValue['size_def']; } $sNewFilePath = $sMediaDir . $iLastID . $aValue['postfix']; $iRes = imageResize($sFile, $sNewFilePath, $iWidth, $iHeight, true, isset($aValue['square']) && $aValue['square']); if ($iRes != 0) { return false; } //resizing was failed @chmod($sNewFilePath, 0644); } $aOwnerInfo = getProfileInfo($iAuthorId); $bAutoAssign2Profile = $aOwnerInfo['Avatar'] == 0 ? true : $bAutoAssign2Profile; if ($bAutoAssign2Profile && $iLastID > 0) { $this->setPrimarySharedPhoto($iLastID, $iAuthorId); createUserDataFile($iAuthorId); } if (is_array($aFileInfo) && count($aFileInfo) > 0) { $this->alertAdd($iLastID, true); } } } return $iLastID; }
function uploadMedia() { global $dir; $sMediaDir = $this->getProfileMediaDir(); if (!$sMediaDir) { return false; } $sFileName = time(); $ext = moveUploadedImage($_FILES, 'photo', $sMediaDir . $sFileName, $this->aMediaConfig['max']['photoFile'], false); if (0 == $_FILES[$this->sMediaType]['error']) { if (getParam('enable_watermark') == 'on') { $iTransparent = getParam('transparent1'); $sWaterMark = $dir['profileImage'] . getParam('Water_Mark'); if (strlen(getParam('Water_Mark')) && file_exists($sWaterMark)) { $sFile = $sMediaDir . $sFileName . $ext; applyWatermark($sFile, $sFile, $sWaterMark, $iTransparent); } } if (strlen($ext) && !(int) $ext) { imageResize($sMediaDir . $sFileName . $ext, $sMediaDir . 'icon_' . $sFileName . $ext, $this->aMediaConfig['size']['iconWidth'], $this->aMediaConfig['size']['iconHeight'], true); imageResize($sMediaDir . $sFileName . $ext, $sMediaDir . 'thumb_' . $sFileName . $ext, $this->aMediaConfig['size']['thumbWidth'], $this->aMediaConfig['size']['thumbHeight'], true); imageResize($sMediaDir . $sFileName . $ext, $sMediaDir . 'photo_' . $sFileName . $ext, $this->aMediaConfig['size']['photoWidth'], $this->aMediaConfig['size']['photoHeight'], true); $this->insertMediaToDb($sFileName . $ext); if (0 == $this->iMediaCount || $this->aMedia['0']['PrimPhoto'] == 0) { $iLastID = mysql_insert_id(); $this->oMediaQuery->setPrimaryPhoto($this->iProfileID, $iLastID); } @unlink($sMediaDir . $sFileName . $ext); } } }
function upload_photo($pic_index) { global $pics; global $site; global $p_arr; global $gl_pic; global $dir; global $pictures_text; global $COMPOSITE; global $ADMIN; $autoApproval_ifPhoto = isAutoApproval('photo'); $up_name = "file_{$pic_index}"; $pic_addon_field = "Pic_{$pic_index}_addon"; $temp_filename = tempnam(rtrim($dir['tmp'], '/'), $p_arr['ID']); unlink($temp_filename); $pic_name = $pics[$pic_index]['name']; $pic_tmp = $_FILES[$up_name]['tmp_name']; $ext = strrchr($_FILES[$up_name]['name'], '.'); if ($pics[$pic_index]['exist']) { unlink("{$pic_name}.jpg"); } $scan = getimagesize($_FILES[$up_name]['tmp_name']); if (1 != $scan[2] && 2 != $scan[2] && 3 != $scan[2] && 6 != $scan[2]) { return 0; } if (move_uploaded_file($pic_tmp, "{$temp_filename}{$ext}")) { if (imageResize("{$temp_filename}{$ext}", "{$temp_filename}.jpg", $gl_pic['pic']['width'], $gl_pic['pic']['height'], true)) { echo _t("_FAILED_TO_UPLOAD_PIC", $_FILES[$up_name]['name'], "undef"); return 0; } if (strtolower($ext) != '.jpg') { unlink("{$temp_filename}{$ext}"); } if (getParam('enable_watermark') == 'on') { $transparent1 = getParam('transparent1'); $water_mark = $dir['profileImage'] . getParam('Water_Mark'); if (strlen(getParam('Water_Mark')) && file_exists($water_mark)) { applyWatermark("{$temp_filename}.jpg", "{$temp_filename}.jpg", $water_mark, $transparent1); } } srand(time()); $p_arr[$pic_addon_field] = rand(10000, 99999); $pics[$pic_index]['name'] = "{$dir['profileImage']}{$p_arr['ID']}_{$pic_index}_" . $p_arr[$pic_addon_field]; $pic_name = $pics[$pic_index]['name']; if (!rename("{$temp_filename}.jpg", "{$pic_name}.jpg")) { echo _t("_FAILED_TO_UPLOAD_PIC", $_FILES[$up_name]['name'], "fail to rename"); return 0; } db_res("UPDATE `Profiles` SET {$pic_addon_field} = '" . $p_arr[$pic_addon_field] . "' WHERE ID = {$p_arr['ID']}"); chmod("{$pic_name}.jpg", 0644); $pictures_text = _t_action('_Successfully uploaded'); $pics[$pic_index]['exist'] = true; if ($p_arr['Status'] == 'Active' && !$autoApproval_ifPhoto && !$ADMIN) { $update_res = db_res("UPDATE `Profiles` SET `Status` = 'Approval' WHERE `ID` = {$p_arr['ID']}"); $p_arr['Status'] = 'Approval'; modules_block($p_arr['ID']); } createUserDataFile($p_arr['ID']); return 1; } else { echo _t_err("_FAILED_TO_UPLOAD_PIC", $_FILES[$up_name]['name'], "undef"); } return 0; }
if ($if_modified_since == $filetimeHeader) { // then check if the etag matches if ($if_none_match == $etag) { header($protocol . " 304 Not Modified"); exit; } } // send headers for the image header('Content-Type: ' . $mimetype); header('Content-Disposition: filename="' . addslashes(basename($media->file)) . '"'); if ($generatewatermark) { // generate the watermarked image $imCreateFunc = 'imagecreatefrom' . $type; $im = @$imCreateFunc($serverFilename); if ($im) { $im = applyWatermark($im); $imSendFunc = 'image' . $type; // save the image, if preferences allow if ($which == 'thumb' && $SAVE_WATERMARK_THUMB || $which == 'main' && $SAVE_WATERMARK_IMAGE) { // make sure the folder exists if (!is_dir(dirname($watermarkfile))) { mkdir(dirname($watermarkfile), WT_PERM_EXE, true); } // save the image $imSendFunc($im, $watermarkfile); } // send the image $imSendFunc($im); imagedestroy($im); exit; } else {
ini_set('display_errors', '1'); date_default_timezone_set('UTC'); require_once '../../vendor/autoload.php'; use Elboletaire\Watimage\Watimage; function applyWatermark($image, $watermark, $output_image) { $wm = new Watimage(); $wm->setImage(array('file' => "files/{$image}", 'quality' => 90)); // file to use and export quality $wm->setWatermark(array('file' => "files/{$watermark}", 'position' => 'center')); // watermark to use and its position $wm->applyWatermark(); // apply watermark to the canvas if (!$wm->generate("results/{$output_image}")) { // handle errors... print_r($wm->errors); } } // Watermark a jpg file with a png applyWatermark('image.jpg', 'watermark.png', 'watermark_jpg_with_png.jpg'); // Watermark a jpg file with a gif applyWatermark('image.jpg', 'watermark.gif', 'watermark_jpg_with_gif.jpg'); // Watermark a png file with a png applyWatermark('image.png', 'watermark.png', 'watermark_png_with_png.png'); // Watermark a png file with a gif applyWatermark('image.png', 'watermark.gif', 'watermark_png_with_gif.png'); // Watermark a gif file with a png applyWatermark('image.gif', 'watermark.png', 'watermark_gif_with_png.gif'); // Watermark a gif file with a gif applyWatermark('image.gif', 'watermark.gif', 'watermark_gif_with_gif.gif'); echo "All images have been watermarked.\n";