public function add() { $form = watermark::get_add_form(); if ($form->validate()) { $file = $_POST["file"]; $pathinfo = pathinfo($file); // Forge prefixes files with "uploadfile-xxxxxxx" for uniqueness $name = preg_replace("/uploadfile-[^-]+-(.*)/", '$1', $pathinfo["basename"]); if (!($image_info = getimagesize($file)) || !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) { message::error(t("Unable to identify this image file")); @unlink($file); return; } rename($file, VARPATH . "modules/watermark/{$name}"); module::set_var("watermark", "name", $name); module::set_var("watermark", "width", $image_info[0]); module::set_var("watermark", "height", $image_info[1]); module::set_var("watermark", "mime_type", $image_info["mime"]); module::set_var("watermark", "position", $form->add_watermark->position->value); module::set_var("watermark", "transparency", $form->add_watermark->transparency->value); $this->_update_graphics_rules(); @unlink($file); message::success(t("Watermark saved")); log::success("watermark", t("Watermark saved")); print json_encode(array("result" => "success", "location" => url::site("admin/watermarks"))); } else { print json_encode(array("result" => "error", "form" => $form->__toString())); } }
function create_watermark($main_img_obj, $watermark_image, $alpha_level = 100) { $alpha_level /= (int) $alpha_level; $main_img_obj_w = imagesx($main_img_obj); $main_img_obj_h = imagesy($main_img_obj); $Wsizes = getimagesize($watermark_image); $watermark_img_obj_w = $Wsizes[0]; $watermark_img_obj_h = $Wsizes[1]; if ($watermark_img_obj_w > $main_img_obj_w / $this->coeff || $watermark_img_obj_h > $main_img_obj_h / $this->coeff) { $msizes = array('width' => $main_img_obj_w, 'height' => $main_img_obj_h); watermark::resize_watermark($watermark_image, $msizes, $watermark_img_obj_w, $watermark_img_obj_h); } else { $this->watermark_img_obj = imagecreatefrompng($watermark_image); } $main_img_obj_min_x = watermark::xposition($main_img_obj_w, $watermark_img_obj_w, $this->positionX); $main_img_obj_min_y = watermark::yposition($main_img_obj_h, $watermark_img_obj_h, $this->positionY); $return_img = @imagecreatetruecolor($main_img_obj_w, $main_img_obj_h); for ($y = 0; $y < $main_img_obj_h; $y++) { for ($x = 0; $x < $main_img_obj_w; $x++) { $return_color = NULL; $watermark_x = $x - $main_img_obj_min_x; $watermark_y = $y - $main_img_obj_min_y; $main_rgb = imagecolorsforindex($main_img_obj, imagecolorat($main_img_obj, $x, $y)); if ($watermark_x >= 0 && $watermark_x < $watermark_img_obj_w && $watermark_y >= 0 && $watermark_y < $watermark_img_obj_h) { $watermark_rbg = imagecolorsforindex($this->watermark_img_obj, imagecolorat($this->watermark_img_obj, $watermark_x, $watermark_y)); $watermark_alpha = round((127 - $watermark_rbg['alpha']) / 127, 2); $watermark_alpha = $watermark_alpha * $alpha_level; $avg_red = $this->_get_ave_color($main_rgb['red'], $watermark_rbg['red'], $watermark_alpha); $avg_green = $this->_get_ave_color($main_rgb['green'], $watermark_rbg['green'], $watermark_alpha); $avg_blue = $this->_get_ave_color($main_rgb['blue'], $watermark_rbg['blue'], $watermark_alpha); $return_color = $this->_get_image_color($return_img, $avg_red, $avg_green, $avg_blue); } else { $rbg = imagecolorsforindex($main_img_obj, imagecolorat($main_img_obj, $x, $y)); $return_color = $this->_get_image_color($return_img, $rbg['red'], $rbg['green'], $rbg['blue']); } imagesetpixel($return_img, $x, $y, $return_color); } } return $return_img; }
public function add() { access::verify_csrf(); $form = watermark::get_add_form(); if ($form->validate()) { $file = $_POST["file"]; $pathinfo = pathinfo($file); // Forge prefixes files with "uploadfile-xxxxxxx" for uniqueness $name = preg_replace("/uploadfile-[^-]+-(.*)/", '$1', $pathinfo["basename"]); if (!($image_info = getimagesize($file)) || !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) { message::error(t("Unable to identify this image file")); @unlink($file); return; } rename($file, VARPATH . "modules/watermark/{$name}"); module::set_var("watermark", "name", $name); module::set_var("watermark", "width", $image_info[0]); module::set_var("watermark", "height", $image_info[1]); module::set_var("watermark", "mime_type", $image_info["mime"]); module::set_var("watermark", "position", $form->add_watermark->position->value); module::set_var("watermark", "transparency", $form->add_watermark->transparency->value); $this->_update_graphics_rules(); @unlink($file); message::success(t("Watermark saved")); log::success("watermark", t("Watermark saved")); json::reply(array("result" => "success", "location" => url::site("admin/watermarks"))); } else { // rawurlencode the results because the JS code that uploads the file buffers it in an // iframe which entitizes the HTML and makes it difficult for the JS to process. If we url // encode it now, it passes through cleanly. See ticket #797. json::reply(array("result" => "error", "html" => rawurlencode((string) $form))); } // Override the application/json mime type. The dialog based HTML uploader uses an iframe to // buffer the reply, and on some browsers (Firefox 3.6) it does not know what to do with the // JSON that it gets back so it puts up a dialog asking the user what to do with it. So force // the encoding type back to HTML for the iframe. // See: http://jquery.malsup.com/form/#file-upload header("Content-Type: text/html; charset=" . Kohana::CHARSET); }
if ($n >= 4) { exit("-7"); } require_once QISHI_ROOT_PATH . 'include/upload.php'; !$_FILES['resume_img']['name'] ? exit('请上传图片!') : ""; $datedir = date("Y/m/d/"); $up_dir = "../../data/photo/" . $datedir; make_dir($up_dir); $setsqlarr['img'] = _asUpFiles($up_dir, "resume_img", 800, 'gif/jpg/bmp/png/jpeg', true); if ($setsqlarr['img']) { // 新增打水印 if (extension_loaded('gd')) { include_once QISHI_ROOT_PATH . 'include/watermark.php'; $font_dir = QISHI_ROOT_PATH . "data/contactimgfont/cn.ttc"; if (file_exists($font_dir)) { $tpl = new watermark(); $tpl->img($up_dir . $setsqlarr['img'], gbk_to_utf8($_CFG['site_name']), $font_dir, 13, 0); } } $img_src = $up_dir . $setsqlarr['resume_img']; makethumb($img_src, $up_dir, 600, 600); $setsqlarr['uid'] = $uid; $setsqlarr['resume_id'] = $pid; $setsqlarr['addtime'] = time(); $setsqlarr['img'] = $datedir . $setsqlarr['img']; $img_id = $db->inserttable(table('resume_img'), $setsqlarr, true); if ($img_id > 0) { perfect_resume($_SESSION['uid'], $_SESSION['username'], $pid, 1); $data['save_url'] = $setsqlarr['img']; $data['url'] = $setsqlarr['img']; $data['title'] = $setsqlarr['title'];
function watermark($file) { require_once ENGINE_PATH . 'classes/watermark.class.php'; $wm = new watermark($this->watermarkFile, $this->watermarkPosition); $wm->addWatermark($file); return true; }
</p> <div> <div class="image"> <img width="<?php echo $width; ?> " height="<?php echo $height; ?> " src="<?php echo $url; ?> "/> <p> <?php echo t("Position: %position", array("position" => watermark::position($position))); ?> </p> <p> <?php echo t("Transparency: %transparency%", array("transparency" => module::get_var("watermark", "transparency"))); ?> </p> </div> <div class="controls"> <a href="<?php echo url::site("admin/watermarks/form_edit"); ?> " title="<?php echo t("Edit Watermark");
public function add() { access::verify_csrf(); $form = watermark::get_add_form(); // For TEST_MODE, we want to simulate a file upload. Because this is not a true upload, Forge's // validation logic will correctly reject it. So, we skip validation when we're running tests. if (TEST_MODE || $form->validate()) { $file = $_POST["file"]; // Forge prefixes files with "uploadfile-xxxxxxx" for uniqueness $name = preg_replace("/uploadfile-[^-]+-(.*)/", '$1', basename($file)); try { list($width, $height, $mime_type, $extension) = photo::get_file_metadata($file); // Sanitize filename, which ensures a valid extension. This renaming prevents the issues // addressed in ticket #1855, where an image that looked valid (header said jpg) with a // php extension was previously accepted without changing its extension. $name = legal_file::sanitize_filename($name, $extension, "photo"); } catch (Exception $e) { message::error(t("Invalid or unidentifiable image file")); system::delete_later($file); return; } rename($file, VARPATH . "modules/watermark/{$name}"); module::set_var("watermark", "name", $name); module::set_var("watermark", "width", $width); module::set_var("watermark", "height", $height); module::set_var("watermark", "mime_type", $mime_type); module::set_var("watermark", "position", $form->add_watermark->position->value); module::set_var("watermark", "transparency", $form->add_watermark->transparency->value); $this->_update_graphics_rules(); system::delete_later($file); message::success(t("Watermark saved")); log::success("watermark", t("Watermark saved")); json::reply(array("result" => "success", "location" => url::site("admin/watermarks"))); } else { // rawurlencode the results because the JS code that uploads the file buffers it in an // iframe which entitizes the HTML and makes it difficult for the JS to process. If we url // encode it now, it passes through cleanly. See ticket #797. json::reply(array("result" => "error", "html" => rawurlencode((string) $form))); } // Override the application/json mime type. The dialog based HTML uploader uses an iframe to // buffer the reply, and on some browsers (Firefox 3.6) it does not know what to do with the // JSON that it gets back so it puts up a dialog asking the user what to do with it. So force // the encoding type back to HTML for the iframe. // See: http://jquery.malsup.com/form/#file-upload header("Content-Type: text/html; charset=" . Kohana::CHARSET); }
public function picUpload() { $result = array(); if (count($_POST)) { $result['post'] = $_POST; } if (count($_FILES)) { $result['files'] = $_FILES; } // Validation $error = false; if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name'])) { $error = 'Invalid Upload'; exit; } // Processing start $photo = $_FILES['Filedata']; $time = SYS_TIME; $year = date('Y', $time); $month = date('m', $time); $day = date('d', $time); $pathInfo = upFileFolders($time); $dstFolder = $pathInfo['path']; $rand = randStr(4); $dstFile = $dstFolder . $time . $rand . $photo['name']; //the size of file uploaded must under 1M if ($photo['size'] > 3000000) { $error = '图片太大不能超过3M'; exit; } //save the temporary file @move_uploaded_file($photo['tmp_name'], $dstFile); // //自动缩放 $imgInfo = @getimagesize($dstFile); $maxPicWidth = intval(loadConfig('cmsContent', 'maxPicWidth')); $maxPicWidth = $maxPicWidth < 1 ? 500 : $maxPicWidth; if ($imgInfo[0] > $maxPicWidth) { $newWidth = $maxPicWidth; $newHeight = $imgInfo[1] * $newWidth / $imgInfo[0]; } else { $newWidth = $imgInfo[0]; $newHeight = $imgInfo[1]; } bpBase::loadSysClass('image'); bpBase::loadSysClass('watermark'); image::zfResize($dstFile, $dstFolder . $time . $rand . '.jpg', $newWidth, $newHeight, 1, 2, 0, 0, 1); //delete the temporary file @unlink($dstFile); $location = CMS_DIR_PATH . $pathInfo['url'] . $time . $rand . '.jpg'; // bpBase::loadSysClass('image'); bpBase::loadSysClass('watermark'); $wm = new watermark(); $wm->wm($dstFolder . $time . $rand . '.jpg'); // $filePath = $location; //processing end if ($error) { $return = array('status' => '0', 'error' => $error); } else { $return = array('status' => '1', 'name' => ABS_PATH . $filePath); // Our processing, we get a hash value from the file $return['hash'] = ''; // ... and if available, we get image data if ($imgInfo) { $return['width'] = $newWidth; $return['height'] = $newHeight; $return['mime'] = $imgInfo['mime']; $return['url'] = $filePath; $return['randnum'] = rand(0, 999999); } } // Output if (isset($_REQUEST['response']) && $_REQUEST['response'] == 'xml') { // header('Content-type: text/xml'); // Really dirty, use DOM and CDATA section! echo '<response>'; foreach ($return as $key => $value) { echo "<{$key}><![CDATA[{$value}]]></{$key}>"; } echo '</response>'; } else { // header('Content-type: application/json'); echo json_encode($return); } }
require_once QISHI_ROOT_PATH . 'include/upload.php'; $setsqlarr['audit'] = 2; //添加默认审核中.. !$_FILES['photo_img']['name'] ? showmsg('请上传照片!', 1) : ""; $photo_dir = "../../data/hunter/" . date("Y/m/d/"); make_dir($photo_dir); $setsqlarr['photo_img'] = _asUpFiles($photo_dir, "photo_img", $_CFG['resume_photo_max'], 'gif/jpg/bmp/png', true); if ($setsqlarr['photo_img']) { /* 3.5新增打水印start */ if (extension_loaded('gd')) { include_once QISHI_ROOT_PATH . 'include/watermark.php'; $font_dir = QISHI_ROOT_PATH . "data/contactimgfont/cn.ttc"; if (file_exists($font_dir)) { $tpl = new watermark(); $tpl->img($photo_dir . $setsqlarr['photo_img'], gbk_to_utf8($_CFG['site_name']), $font_dir, 15, 0); } } /* 3.5新增end */ $setsqlarr['photo_img'] = date("Y/m/d/") . $setsqlarr['photo_img']; $auth = $hunter_profile; @unlink("../../data/hunter/" . $auth['photo_img']); !$db->updatetable(table('hunter_profile'), $setsqlarr, " id='" . intval($hunter_profile['id']) . "' AND uid='" . intval($_SESSION['uid']) . "'") ? showmsg("保存失败!", 0) : showmsg("保存成功!", 2); } else { showmsg('保存失败!', 1); } } unset($smarty);
/** * Process the actions, crop, scale(resize), rotate, flip, and save. * When ever an action is performed, the result is save into a * temporary image file, see createUnique on the filename specs. * It does not return the saved file, alway returning the tmp file. * @param string $action, should be 'crop', 'scale', 'rotate','flip', or 'save' * @param string $relative the relative image filename * @param string $fullpath the fullpath to the image file * @return array with image information * <code>array('src'=>'url of the image', 'dimensions'=>'width="xx" height="yy"', * 'file'=>'image file, relative', 'fullpath'=>'full path to the image');</code> */ function processAction($action, $relative, $fullpath) { $params = ''; if (isset($_GET['params'])) { $params = $_GET['params']; } $values = explode(',', $params, 4); $saveFile = $this->getSaveFileName($values[0]); $img = Image_Transform::factory(IMAGE_CLASS); $img->load($fullpath); switch ($action) { case 'replace': // 'ImageManager.php' handled the uploaded file, it's now on the server. // If maximum size is specified, constrain image to it. $dimensionsIndex = isset($_REQUEST['uploadSize']) ? $_REQUEST['uploadSize'] : 0; if ($this->manager->config['maxWidth'][$dimensionsIndex] > 0 && $this->manager->config['maxHeight'][$dimensionsIndex] > 0 && ($img->img_x > $this->manager->config['maxWidth'][$dimensionsIndex] || $img->img_y > $this->manager->config['maxHeight'][$dimensionsIndex])) { $percentage = min($this->manager->config['maxWidth'][$dimensionsIndex] / $img->img_x, $this->manager->config['maxHeight'][$dimensionsIndex] / $img->img_y); $img->scale($percentage); } break; case 'watermark': // loading target image $functionName = 'ImageCreateFrom' . $img->type; if (function_exists($functionName)) { $imageResource = $functionName($fullpath); } else { echo "<script>alert(\"Error when loading '" . basename($fullpath) . "' - Loading '" . $img->type . "' files not supported\");</script>"; return false; } // loading watermark $watermarkFullPath = $_GET['watermarkFullPath']; $watermarkImageType = strtolower(substr($watermarkFullPath, strrpos($watermarkFullPath, ".") + 1)); if ($watermarkImageType == "jpg") { $watermarkImageType = "jpeg"; } if ($watermarkImageType == "tif") { $watermarkImageType = "tiff"; } $functionName = 'ImageCreateFrom' . $watermarkImageType; if (function_exists($functionName)) { $watermarkResource = $functionName($watermarkFullPath); } else { echo "<script>alert(\"Error when loading '" . basename($watermarkFullPath) . "' - Loading '" . $img->type . "' files not supported\");</script>"; return false; } $numberOfColors = imagecolorstotal($watermarkResource); $watermarkX = isset($_GET['watermarkX']) ? $_GET['watermarkX'] : -1; $watermarkY = isset($_GET['watermarkY']) ? $_GET['watermarkY'] : -1; $opacity = $_GET['opacity']; // PNG24 watermark on GIF target needs special handling // PNG24 watermark with alpha transparency on other targets need also this handling if ($watermarkImageType == "png" && $numberOfColors == 0 && ($img->type == "gif" || $opacity < 100)) { require_once 'Classes/api.watermark.php'; $watermarkAPI = new watermark(); $imageResource = $watermarkAPI->create_watermark($imageResource, $watermarkResource, $opacity, $watermarkX, $watermarkY); } elseif ($watermarkImageType == "png" && $numberOfColors == 0 && $opacity == 100) { $watermark_width = imagesx($watermarkResource); $watermark_height = imagesy($watermarkResource); imagecopy($imageResource, $watermarkResource, $watermarkX, $watermarkY, 0, 0, $watermark_width, $watermark_height); } else { $watermark_width = imagesx($watermarkResource); $watermark_height = imagesy($watermarkResource); imagecopymerge($imageResource, $watermarkResource, $watermarkX, $watermarkY, 0, 0, $watermark_width, $watermark_height, $opacity); } break; case 'crop': $img->crop(intval($values[0]), intval($values[1]), intval($values[2]), intval($values[3])); break; case 'scale': $img->resize(intval($values[0]), intval($values[1])); break; case 'rotate': $img->rotate(floatval($values[0])); break; case 'flip': if ($values[0] == 'hoz') { $img->flip(true); } else { if ($values[0] == 'ver') { $img->flip(false); } } break; case 'save': if (!is_null($saveFile)) { $quality = intval($values[1]); if ($quality < 0) { $quality = 85; } $newSaveFile = $this->makeRelative($relative, $saveFile); $oldSaveFile = $newSaveFile; if ($this->manager->config['allow_newFileName'] && !$this->manager->config['allow_overwrite']) { // check whether a file already exist and if there is, create a variant of the filename $newName = $this->getUniqueFilename($newSaveFile); //get unique filename just returns the filename, so //we need to make the relative path again. $newSaveFile = $this->makeRelative($relative, $newName); } // forced new name? if ($oldSaveFile != $newSaveFile) { $this->forcedNewName = $newName; } else { $this->forcedNewName = false; } $newSaveFullpath = $this->manager->getFullPath($newSaveFile); $img->save($newSaveFullpath, $values[0], $quality); if (is_file($newSaveFullpath)) { $this->filesaved = 1; } else { $this->filesaved = -1; } } break; } //create the tmp image file $filename = $this->createUnique($fullpath); $newRelative = $this->makeRelative($relative, $filename); $newFullpath = $this->manager->getFullPath($newRelative); $newURL = $this->manager->getFileURL($newRelative); // when uploaded and not resized, rename and don't save if ($action == "replace" && $percentage <= 0) { rename($fullpath, $newFullpath); } elseif ($action == "watermark") { // save image $functionName = 'image' . $img->type; if (function_exists($functionName)) { if ($type == 'jpeg') { $functionName($imageResource, $newFullpath, 100); } else { $functionName($imageResource, $newFullpath); } } else { echo "<script>alert(\"Error when saving '" . basename($newFullpath) . "' - Saving '" . $img->type . "' files not supported\");</script>"; return false; } } else { //save the file. $img->save($newFullpath); $img->free(); } // when uploaded was resized and saved, remove original if ($action == "replace" && $percentage > 0) { unlink($fullpath); } //get the image information $imgInfo = @getimagesize($newFullpath); $image['src'] = $newURL; $image['dimensions'] = $imgInfo[3]; $image['width'] = $imgInfo[0]; $image['height'] = $imgInfo[1]; $image['file'] = $newRelative; $image['fullpath'] = $newFullpath; return $image; }
$setsqlarr['license'] = trim($_POST['license']) ? trim($_POST['license']) : showmsg('您没有输入营业执照注册号!', 1); $setsqlarr['audit'] = 2; //添加默认审核中.. !$_FILES['certificate_img']['name'] ? showmsg('请上传图片!', 1) : ""; $certificate_dir = "../../data/" . $_CFG['updir_certificate'] . "/" . date("Y/m/d/"); make_dir($certificate_dir); $setsqlarr['certificate_img'] = _asUpFiles($certificate_dir, "certificate_img", $_CFG['certificate_max_size'], 'gif/jpg/bmp/png', true); if ($setsqlarr['certificate_img']) { /* 3.5新增打水印start */ if (extension_loaded('gd')) { include_once QISHI_ROOT_PATH . 'include/watermark.php'; $font_dir = QISHI_ROOT_PATH . "data/contactimgfont/cn.ttc"; if (file_exists($font_dir)) { $tpl = new watermark(); $tpl->img($certificate_dir . $setsqlarr['certificate_img'], gbk_to_utf8($_CFG['site_name']), $font_dir, 15, 0); } } /* 3.5新增end */ $setsqlarr['certificate_img'] = date("Y/m/d/") . $setsqlarr['certificate_img']; $auth = $company_profile; @unlink("../../data/" . $_CFG['updir_certificate'] . "/" . $auth['certificate_img']); $wheresql = "uid='" . $_SESSION['uid'] . "'"; write_memberslog($_SESSION['uid'], 1, 8002, $_SESSION['username'], "上传了营业执照"); updatetable(table('jobs'), array('company_audit' => 2), $wheresql); updatetable(table('jobs_tmp'), array('company_audit' => 2), $wheresql); !updatetable(table('company_profile'), $setsqlarr, $wheresql) ? showmsg('保存失败!', 1) : showmsg('保存成功,请耐心等待管理员审核!', 2); } else {
function watermarkImage($SourceFile) { global $settings, $DIR_TEMP; $font = CFLIBPATH . 'font/arial.ttf'; // the location on the server that the font can be found $font_size = 40; // size of the font require CFLIBPATH . 'watermark.class.php'; $img = new watermark($SourceFile, empty($settings['SET_WATERMARK_IMAGE']) ? null : $settings['SET_WATERMARK_IMAGE']); $img->cacheDir = $DIR_TEMP; //$img->saveQuality = 9; if (empty($settings['SET_WATERMARK_IMAGE'])) { $img->padding = 10; $img->textWatermark($settings['SET_WATERMARK_TEXT'], $font_size, $font); $img->opacityVal = 30; $img->watermarkSizing(0.75); } $img->watermarkPosition($settings['SET_WATERMARK_PLACED']); $img->makeImage(); return; }
imagecopy($im_s, $im, $wpos, $hpos, 0, 0, $width_orig, $height_orig); } else { $wpos = (PRODUCT_MEDIUM_LARGE_WIDTH - $width) / 2; $hpos = (PRODUCT_MEDIUM_LARGE_HEIGHT - $height) / 2; imagecopyresampled($im_s, $im, $wpos, $hpos, 0, 0, $width, $height, $width_orig, $height_orig); } //生成水印图 list($water_w, $water_h) = getimagesize($watermark); $dst_x = (PRODUCT_MEDIUM_LARGE_WIDTH - $water_w) / 2; $dst_y = (PRODUCT_MEDIUM_LARGE_HEIGHT + $water_h) / 1.5; //caizhouqing update pic_Location $im_watermark = @imagecreatefrompng($watermark); if (WATERMARK_TRANSPARENT == 'yes') { @imagejpeg($im_s, $destination_name_large, 100); include_once DIR_WS_CLASSES . 'watermark.php'; $im_s = watermark::emboss($destination_name_large, $watermark, PRODUCT_MEDIUM_LARGE_WIDTH, PRODUCT_MEDIUM_LARGE_HEIGHT); } else { imagecopymerge($im_s, $im_watermark, $dst_x, $dst_y, 0, 0, $water_w, $water_h, $wateralpha); } @imagejpeg($im_s, $destination_name_large, 100); @imagedestroy($im); } if ($data['ImgExtension'] == ".jpg" || $data['ImgExtension'] == ".jpeg") { $im = @imagecreatefromjpeg($destination_name_small); } if ($data['ImgExtension'] == ".gif") { $im = @imagecreatefromgif($destination_name_small); } if ($data['ImgExtension'] == ".png") { $im = @imagecreatefrompng($destination_name_small); }
function load_foto($file, $img_old, $img_small_old, $x, $y) { global $user; require_once 'classes/thumblib.inc.php'; require_once 'classes/resize.class.php'; require_once 'classes/watermark.class.php'; $size = new Resize(); $folder = 'files/foto/' . $user['id'] . '/'; @mkdir($folder, 0777); $size->dir = $folder; // Директория изображений $size->original = true; if ($file['name']) { $size->setResize($file); if (!$size->error) { @unlink($img_old); @unlink($img_small_old); $img_small = $size->small; $img = $size->image; $thumb = PhpThumbFactory::create($img); $thumb->adaptiveresize($x, $y); $thumb->save($img_small); $img_small = $img_small; $img_small2 = str_replace("_s", "_m", $size->small); $thumb = PhpThumbFactory::create($img); $thumb->adaptiveresize(150, 100); $thumb->save($img_small2); $thumb = PhpThumbFactory::create($img); $thumb->Resize(637, 0); $thumb->save($img); $path_info = pathinfo($img_small); $img_small = str_replace($path_info['extension'], 'jpg', $img_small); $this->convert_foto($size->small, $img_small); //@unlink($size->small); $path_info = pathinfo($img); $img = str_replace($path_info['extension'], 'jpg', $size->image); $this->convert_foto($size->image, $img); //@unlink($size->image); $watermark = new watermark(); # создаем объекты-изображения используя исходные файлы (main.jpg и watermark.png) $main_img_obj = imagecreatefromjpeg($img); $watermark_img_obj = imagecreatefrompng('watermark.png'); # создаем изображение с водяным знаком - значение прозрачности альфа-канала водяного знака установим в 66% $return_img_obj = $watermark->create_watermark($main_img_obj, $watermark_img_obj, 66, $img, $ext); # отобразим наше полученное изображение в браузере - но сначала сообщим ему, что это jpeg-файл $img = $img; } else { $error = $size->error; } } else { $img_small = $img_small_old; $img = $img_old; } $result = array('error' => $error, 'img' => $img, 'img_small' => $img_small); return $result; }
public function add() { access::verify_csrf(); $form = watermark::get_add_form(); // For TEST_MODE, we want to simulate a file upload. Because this is not a true upload, Forge's // validation logic will correctly reject it. So, we skip validation when we're running tests. if (TEST_MODE || $form->validate()) { $file = $_POST["file"]; // Forge prefixes files with "uploadfile-xxxxxxx" for uniqueness $name = preg_replace("/uploadfile-[^-]+-(.*)/", '$1', basename($file)); try { list($width, $height, $mime_type, $extension) = photo::get_file_metadata($file); // Sanitize filename, which ensures a valid extension. This renaming prevents the issues // addressed in ticket #1855, where an image that looked valid (header said jpg) with a // php extension was previously accepted without changing its extension. $name = legal_file::sanitize_filename($name, $extension, "photo"); } catch (Exception $e) { message::error(t("Invalid or unidentifiable image file")); system::delete_later($file); return; } rename($file, VARPATH . "modules/watermark/{$name}"); module::set_var("watermark", "name", $name); module::set_var("watermark", "width", $width); module::set_var("watermark", "height", $height); module::set_var("watermark", "mime_type", $mime_type); module::set_var("watermark", "position", $form->add_watermark->position->value); module::set_var("watermark", "transparency", $form->add_watermark->transparency->value); $this->_update_graphics_rules(); system::delete_later($file); message::success(t("Watermark saved")); log::success("watermark", t("Watermark saved")); json::reply(array("result" => "success", "location" => url::site("admin/watermarks"))); } else { json::reply(array("result" => "error", "html" => (string) $form)); } // Override the application/json mime type for iframe compatibility. See ticket #2022. header("Content-Type: text/plain; charset=" . Kohana::CHARSET); }
function add_watermark($source_img, $watermark_img, $destination_folder, $filename) { $watermark = new watermark(); if ($source_img && $watermark_img) { $main_img_obj = imagecreatefromjpeg($source_img); $watermark_img_obj = imagecreatefrompng($watermark_img); # create our watermarked image $return_img_obj = $watermark->create_watermark($main_img_obj, $watermark_img_obj, $alpha_level = 100, $watermark_v_position = WATERMARK_V_POSITION, $watermark_h_position = WATERMARK_H_POSITION); # create watermarked image imagejpeg($return_img_obj, $destination_folder . $filename, 80); } }