public function upload_image() { // error_reporting(0); include dirname(__FILE__) . '/../Util/image-cropper-config.class.php'; include dirname(__FILE__) . '/../Util/image-cropper-function.class.php'; if ($_GET['act'] == 'thumb') { preg_match('/Uploaded\\/.*/', $_POST['img_src'], $matches); $img_src = APP_PATH . 'Public/' . $matches[0]; $arr = array('uploaddir' => $imgthumb, 'tempdir' => $imgtemp, 'web_dir' => $webthumb, 'height' => $_POST['height'], 'width' => $_POST['width'], 'x' => $_POST['x'], 'y' => $_POST['y'], 'img_src' => $img_src, 'thumb' => true, 'fileError' => $fileError, 'sizeError' => $sizeError, 'maxfilesize' => $maxuploadfilesize, 'canvasbg' => $canvasbg); resizeThumb($arr); exit; } elseif ($_GET['act'] == 'upload') { $big_arr = array('uploaddir' => $imgbig, 'tempdir' => $imgtemp, 'web_dir' => $webbig, 'height' => $_POST['height'], 'width' => $_POST['width'], 'x' => 0, 'y' => 0, 'fileError' => $fileError, 'sizeError' => $sizeError, 'maxfilesize' => $maxuploadfilesize, 'canvasbg' => $canvasbg); resizeImg($big_arr); } else { //nothing to do here } }
function uploadImg($img, $fileNm, $maxW, $maxH, $cat) { $results['targetPath'] = $_SERVER['DOCUMENT_ROOT'] . '/media/images/price_guide_photos/' . $cat . '/'; $results['actualName'] = $img['name']; $results['ext'] = explode('.', $img['name']); $c = count($results['ext']); $c = $c - 1; $results['fileName'] = $fileNm . '.' . $results['ext'][$c]; $results['targetFile'] = str_replace('//', '/', $results['targetPath']) . $results['fileName']; if (move_uploaded_file($img['tmp_name'], $results['targetFile'])) { $results['readyImg'] = resizeImg($results['targetFile'], $maxW, $maxH); if (!$results['readyImg']) { $results['note'] = $results['readyImg']['note']; } else { $results['note'] .= 'Success!'; } } else { $results['note'] = 'Error with moving file!'; } return $results; }
if (!isValidWebImageType($couponfiletype, $couponfilename, $coupontempname)) { $message_image = " * Invalid Image !! Upload an image (jpg/gif/png)" . "<br>"; $image_flag = 1; } else { $imagewidth_height_type_array = explode(":", ImageTypeBanner($_FILES['txtCouponImage']['tmp_name'])); $imagetype = $imagewidth_height_type_array[0]; $assignedname_small = "gift_coupon_small" . time() . "." . $imagetype; $assignedname_large = "gift_coupon_large" . time() . "." . $imagetype; if (move_uploaded_file($_FILES['txtCouponImage']['tmp_name'], "../products/" . $assignedname_large)) { chmod("../products/{$assignedname_large}", 0777); /*taken from the general site settings table*/ $gift_image_size = '400,400'; $gift_size = split(',', $gift_image_size); resizeImg("../products/" . $assignedname_large, 283, 269, false, 100, 0, "_thumb"); @copy("../products/{$assignedname_large}", "../products/{$assignedname_small}"); resizeImg("../products/" . $assignedname_small, 191, 183, false, 100, 0, "_thumb"); $update_product_options .= ",image_small = '" . $assignedname_small . "',\n\t\t\t\t\t\t\t\t image_big = '" . $assignedname_large . "'"; unlink('../products/' . $_POST['txtCouponBuffer']); } } } $update_product_options .= " WHERE product_id = " . $_GET['edit_product_id']; mysql_query($update_product_options) or die(mysql_error()); if ($image_flag == 0) { header("Location:gift_coupon_artist.php?" . $_GET['qstring'] . "&txtSearch=" . $_GET['txtSearch'] . "&msg=Gift Coupon is updated successfully !!"); } } } ?> <script>
$picsmallname = $final_image_small; $picbigname = $final_image_big; //checking extension and replace $replaceArray = array('jpg', 'jpeg', 'gif'); $findArray = array('JPG', 'JPEG', 'GIF'); @(list($piName, $ext) = @split("[.]", $final_image_small)); $final_image_small = $piName . '.' . str_replace($findArray, $replaceArray, $ext); @(list($piName, $ext) = @split("[.]", $final_image_big)); $final_image_big = $piName . '.' . str_replace($findArray, $replaceArray, $ext); //checking extension and replace copy($image_file_path . "/" . $value, "../products/" . $final_image_small); copy($image_file_path . "/" . $value, "../products/" . $final_image_big); chmod("../products/{$final_image_small}", 0777); chmod("../products/{$final_image_big}", 0777); resizeImg("../products/" . $final_image_small, 191, 183, false, 100, 0, "_thumb"); resizeImg("../products/" . $final_image_big, 283, 269, false, 100, 0, "_thumb"); //generateThumbNail("../products/".$final_image_small,"../products/".$final_image_small,120,150); while ($rr = mysql_fetch_array($rs_t)) { $pid = $rr['product_id']; $sql_update = "update " . $tableprefix . "products set product_image_small='" . $final_image_small . "' \n\t\t\t\t\t,product_image_big='" . $final_image_big . "' where product_artist_id='" . $sellerid . "' and product_id='" . $pid . "' "; $rs_query = mysql_query($sql_update) or die(mysql_error()); $imageArray[] = $imgname; } // end while } // end if number of rows check if ($num_rows == 0) { $imageArrays[] = $imgname; $flag = "false"; } if (mysql_affected_rows() > 0) {
break; default: die('Unsupported File!'); //output error and exit } list($CurWidth, $CurHeight) = getimagesize($TempSrc); $ImageExt = substr($ImageName, strrpos($ImageName, '.')); $ImageExt = str_replace('.', '', $ImageExt); $ImageName = preg_replace("/[^A-Za-z0-9 _\\-\\+\\&]/", "", $ImageName); /* Resize */ $NewImageName = $ImageName . '-' . $RandomNumber . '.' . $ImageExt; $DestRandImageName = $DestinationDirectory . '/' . $NewImageName; $ThumbWidthSize = 150; $ThumbHeightSize = 150; $Quality = 100; resizeImg($CurWidth, $CurHeight, $DestRandImageName, $CreatedImage, $Quality, $ImageType, $ThumbWidthSize, $ThumbHeightSize); /* End Resize */ /* Begin SQL $dataBaseBD = new dataBaseBD(); $userDataBase = $dataBaseBD->getUserDataBase(); $passDataBase = $dataBaseBD->getPassDataBase(); $dataBase = $dataBaseBD->getDataBase(); $conectar = mysql_connect('localhost', $userDataBase, $passDataBase); mysql_select_db($dataBase, $conectar); $sql1 = "UPDATE `transiciones` SET `position` = (`position`+1) WHERE `position` >= " . $_POST['position']; $sql2 = "INSERT INTO transiciones (`ID`,`archivo`,`position`,`link`,`comentario`) VALUES ('NULL','" . $ImageName . '-' . $RandomNumber . '.' . $ImageExt . "','" . $_POST['position'] . "','" . $_POST['link'] . "','" . nl2br($_POST['comentario']) . "');";
public function changeAvatar() { if (isset($_POST["newAvatar"]) && $this->isLogged()) { $data = explode(',', $_POST["newAvatar"]); if (count($data) == 2 && $data[0] == "data:image/png;base64" && base64_decode($data[1])) { $dir = "includes/images/200x200/"; $img = imagecreatefromstring(base64_decode($data[1])); do { $name = token(20) . ".png"; $path = $dir . $name; } while (file_exists($path)); $_SESSION["user"]->getImage()->setPath($name)->setThumbnailPath($name)->setType("200x200")->setDescription("Profilový obrázek uživatele " . $_SESSION["user"]->getUsername())->save(); imagepng($img, $path); $dir = "includes/images/50x50/"; $path = $dir . $name; imagepng(resizeImg($img, 50, 50), $path); $this->addPopup('success', 'Váš avatar byl úspěšně změněn.'); redirectTo('/nastaveni'); } else { setHTTPStatusCode("400"); } } else { setHTTPStatusCode("400"); } }
function clean($url) { $url = preg_replace('~[^\\pL0-9_]+~u', '-', $url); $url = trim($url, "-"); $url = iconv("utf-8", "us-ascii//TRANSLIT", $url); $url = strtolower($url); $url = preg_replace('~[^-a-z0-9_]+~', '', $url); return $url; } if (!$abort) { $src = ltrim($postData->img, '/'); $crop = $postData->crop; $sizes = [(object) ["w" => "41", "h" => "41", "suffix" => "_41x41"], (object) ["w" => "180", "h" => "180", "suffix" => "_180x180"]]; $dir = "winnow/uploads/" . $_SESSION['username'] . "/"; require_once $_SERVER['DOCUMENT_ROOT'] . '/winnow/components/shared/resizeImg.php'; $savedImgs = resizeImg($src, $crop, $sizes, $dir); if (!isset($savedImgs->_41x41)) { $abort = true; $errorArray[] = "Failed to resize profile image."; } } if (!$abort) { //All data verified, update userinfo $images = $es->update(['index' => 'users', 'type' => 'info', 'id' => $_SESSION['username'], 'body' => ["doc" => ['imgs' => ['img41' => $savedImgs->_41x41, 'img180' => $savedImgs->_180x180, 'imgFullsize' => $postData->img, 'crop' => $postData->crop]]]]); $userInfo = $es->get(['index' => 'users', 'type' => 'info', 'id' => $_SESSION['username']]); unset($userInfo['_source']['email']); echo json_encode(array("profileImgs" => $userInfo['_source']['imgs'])); } if ($abort) { echo json_encode(array("error" => $errorArray)); }
function uploadFile($name, $tmp_name, $error, $size, $toDir, $allowedExtensions, $maxSize, $imgEnlarge, $imgWidth, $imgHeight, $doThumb, $thumbEnlarge, $thumbWidth, $thumbHeight) { if ($error != 0) { $message = "There was an upload error for file `'.{$name}.'`, code #" . $error . ". Check your server's configuration"; switch ($error) { case UPLOAD_ERR_INI_SIZE: $message = "The uploaded file `'.{$name}.'` exceeds the upload_max_filesize directive in php.ini"; break; case UPLOAD_ERR_FORM_SIZE: $message = "The uploaded file `'.{$name}.'` exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"; break; case UPLOAD_ERR_PARTIAL: $message = "The uploaded file `'.{$name}.'` was only partially uploaded"; break; case UPLOAD_ERR_NO_FILE: $message = "No file was uploaded"; break; case UPLOAD_ERR_NO_TMP_DIR: $message = "Missing a temporary folder on your server"; break; case UPLOAD_ERR_CANT_WRITE: $message = "Failed to write file to disk on your server"; break; case UPLOAD_ERR_EXTENSION: $message = "File upload stopped by extension"; break; } return array(false, $message); } if ($size == 0) { return array(false, 'File `' . $name . '` size = 0'); } if ($maxSize > 0 && $size > $maxSize) { return array(false, 'Size of file `' . $name . '` exceeds the limit of ' . $maxSize . ' bytes'); } $a = explode('.', $name); $type = $a[count($a) - 1]; error_log($type); if ($allowedExtensions[0] != '*' && !in_array(strtolower($type), array_map('strtolower', $allowedExtensions))) { return array(false, 'Wrong extension for file `' . $name . '`. Allowed extensions are: ' . implode(', ', $allowedExtensions)); } $fileName; $fileNameThumb; // Search for file name $ok = false; $i = -1; do { $i++; if ($i == 0) { $fileName = $name; } else { $fileName = $i . '_' . $name; } $ok = !is_file($toDir . $fileName); if ($doThumb) { $fileNameThumb = getThumbFileName($fileName); $ok = $ok && !file_exists($toDir . $fileNameThumb); } } while (!$ok); $filePath = $toDir . $fileName; if (is_uploaded_file($tmp_name)) { $moveResult = move_uploaded_file($tmp_name, $filePath); } else { $moveResult = rename($tmp_name, $filePath); } if ($moveResult === false) { return array(false, 'Error while moving uploaded file to destination folder: check folder permissions on server side'); } if ($imgWidth > 0 || $imgHeight > 0) { $err = resizeImg($filePath, $imgEnlarge, $imgWidth, $imgHeight, true); if ($err != null) { return array(false, 'Error while resizing image `' . $name . '`: ' . $err); } } if ($doThumb) { $err = resizeImg($filePath, $thumbEnlarge, $thumbWidth, $thumbHeight, false); if ($err != null) { return array(false, 'Error while making thumbnail of image `' . $name . '`: ' . $err); } } return array(true, $fileName); }
//error_reporting(0); include_once 'includes/config.php'; include_once 'includes/functions.php'; /* if ($_GET['act'] == 'thumb') { $arr = array( 'uploaddir' => $imgthumb, 'tempdir' => $imgtemp, 'height' => $_POST['height'], 'width' => $_POST['width'], 'x' => $_POST['x'], 'y' => $_POST['y'], 'img_src' => $_POST['img_src'], 'thumb' => true, 'fileError' => $fileError, 'sizeError' => $sizeError, 'maxfilesize' => $maxuploadfilesize, 'canvasbg' => $canvasbg, 'bigWidthPrev' => $bigWidthPrev, 'bigHeightPrev' => $bigHeightPrev, ); resizeThumb($arr); exit; } else */ if ($_GET['act'] == 'upload') { $big_arr = array('uploaddir' => $imgbig, 'tempdir' => $imgtemp, 'height' => $_POST['height'], 'width' => $_POST['width'], 'x' => 0, 'y' => 0, 'thumb' => false, 'fileError' => $fileError, 'sizeError' => $sizeError, 'maxfilesize' => $maxuploadfilesize, 'canvasbg' => $canvasbg, 'bigWidthPrev' => $bigWidthPrev, 'bigHeightPrev' => $bigHeightPrev); resizeImg($big_arr); } else { //nothing to do here }
public function saveEditedGallery($id) { $gal = GalleryQuery::create()->findPk($id); $dir = "includes/images/fullsize/"; foreach ($_POST["image"] as $post) { $d = explode(',', $post); $img = imagecreatefromstring(base64_decode($d[1])); do { $name = token(20) . ".png"; $path = $dir . $name; } while (file_exists($path)); $i = new Image(); $i->setPath($name)->setDescription("Fotografie z galerie " . $gal->getName())->setThumbnailPath($name)->setType("fullsize")->save(); imagepng(resizeImg($img, 1280, 720), $path); $dir = "includes/images/960x540/"; $path = $dir . $name; imagepng(resizeImg($img, 960, 540), $path); $dir = "includes/images/50x50/"; $path = $dir . $name; imagepng(resizeImg($img, 50, 50), $path); $names[] = $name; } $imgs = ImageQuery::create()->filterByPath($names)->find(); foreach ($imgs as $i) { $map = new ImageGalleryMap(); $map->setIdImage($i->getId()); $map->setIdGallery($id); $map->save(); } $this->addPopup('success', 'Fotografie byly úspěšné přidány do galerie.'); redirectTo('/administrace/galerie'); }
$image = imagecreatefrompng($imagepath); break; case '.gif': $image = imagecreatefromgif($imagepath); break; } $newimage = imagerotate($image, $angle, $bgd_color); imagealphablending($newimage, false); imagesavealpha($newimage, false); //imagejpeg($newimage, $imagepath, 100); unlink($imagepath); switch (strtolower($extension)) { case '.jpg': case '.jpeg': imagejpeg($newimage, $imagepath, 100); break; case '.png': imagepng($newimage, $imagepath, 9); break; case '.gif': imagegif($newimage, $imagepath); break; } // rescale image resizeImg(1150, $imagepath, $extension, 75); $smallimagepath = "./../content/uploads/small_" . $schilderij["Img"]; copy($imagepath, $smallimagepath); resizeImg(228, $smallimagepath, $extension, 50); header("location:editSchilderij.php?id={$_GET['id']}"); exit; }
function _fnGenerateImages($img_file, $new_file, $dir = "", $add_thumbnail = False) { $SP_WIDTH = 540; $SP_HEIGHT = 360; $PC_WIDTH = 420; $PC_HEIGHT = 360; $TN_WIDTH = 119; $TN_HEIGHT = 102; $size = @getimagesize($img_file); if (!$size) { return false; } switch ($size[2]) { case 1: // IMAGETYPE_GIF $im = @imagecreatefromgif($img_file); break; case 2: // IMAGETYPE_JPEG $im = @imagecreatefromjpeg($img_file); break; case 3: // IMAGETYPE_PNG $im = @imagecreatefrompng($img_file); break; default: return false; } // 適正サイズに縮小 $w = $size[0]; $h = $size[1]; $target_w = $SP_WIDTH; $target_h = $SP_HEIGHT; $w_ratio = $target_w / $w; $h_tmp = $h * $w_ratio; if ($target_h > $h_tmp) { $ratio = $target_h / $h; } else { $ratio = $w_ratio; } $new_w = intval($w * $ratio); $new_h = intval($h * $ratio); $img = resizeImg($im, $new_w, $new_h); // 切り出してスマフォ画像を保存 $horizontal_margin = intval(($new_w - $target_w) * 0.5); $vertical_margin = intval(($new_h - $target_h) * 0.5); $rect = array("x" => $horizontal_margin, "y" => $vertical_margin, "width" => $target_w, "height" => $target_h); $sp_image = imagecrop($img, $rect); imagejpeg($sp_image, APP_IMG_PATH . $dir . "sp_" . $new_file . ".jpg", 100); // さらに切り出してPC画像を保存 $new_w = $SP_WIDTH; $new_h = $SP_HEIGHT; $target_w = $PC_WIDTH; $target_h = $PC_HEIGHT; $horizontal_margin = intval(($new_w - $target_w) * 0.5); $vertical_margin = intval(($new_h - $target_h) * 0.5); $rect = array("x" => $horizontal_margin, "y" => $vertical_margin, "width" => $target_w, "height" => $target_h); $pc_image = imagecrop($sp_image, $rect); imagejpeg($pc_image, APP_IMG_PATH . $dir . "pc_" . $new_file . ".jpg", 100); // さらに縮小してサムネイル画像を保存 if ($add_thumbnail) { $tn_image = resizeImg($pc_image, $TN_WIDTH, $TN_HEIGHT); imagejpeg($tn_image, APP_IMG_PATH . $dir . "tn_" . $new_file . ".jpg", 100); } // メモリを開放します @imagedestroy($im); @imagedestroy($img); @imagedestroy($sp_image); @imagedestroy($pc_image); @imagedestroy($tn_image); unlink($img_file); return false; }
public function upload() { // disable error if you want //error_reporting(0); include_once DIR_SYSTEM . 'upload/config.php'; include_once DIR_SYSTEM . 'upload/functions.php'; if ($this->request->get['act'] == 'thumb') { $arr = array('uploaddir' => $imgthumb, 'tempdir' => $imgtemp, 'height' => $_POST['height'], 'width' => $_POST['width'], 'x' => $_POST['x'], 'y' => $_POST['y'], 'img_src' => $_POST['img_src'], 'thumb' => true, 'fileError' => $fileError, 'sizeError' => $sizeError, 'maxfilesize' => $maxuploadfilesize, 'canvasbg' => $canvasbg, 'bigWidthPrev' => $bigWidthPrev, 'bigHeightPrev' => $bigHeightPrev); resizeThumb($arr); exit; } elseif ($this->request->get['act'] == 'upload') { $big_arr = array('uploaddir' => $imgbig, 'tempdir' => $imgtemp, 'height' => $_POST['height'], 'width' => $_POST['width'], 'x' => 0, 'y' => 0, 'thumb' => false, 'fileError' => $fileError, 'sizeError' => $sizeError, 'maxfilesize' => $maxuploadfilesize, 'canvasbg' => $canvasbg, 'bigWidthPrev' => $bigWidthPrev, 'bigHeightPrev' => $bigHeightPrev); resizeImg($big_arr); } else { //nothing to do here } }
function uploadSchilderijImg($id, $imgExtension, $old, $preupload) { if ($old != null) { if (file_exists("./../content/uploads/" . $old)) { unlink("./../content/uploads/" . $old); } if (file_exists("./../content/uploads/small_" . $old)) { unlink("./../content/uploads/small_" . $old); } } $newpath = "./../content/uploads/" . $id . $imgExtension; $smallpath = "./../content/uploads/small_" . $id . $imgExtension; query("UPDATE schilderij SET Img = ? WHERE Schilderij_ID = ?", array($id . $imgExtension, $id)); if ($preupload == null) { move_uploaded_file($_FILES["img"]["tmp_name"], $newpath); } else { copy($preupload, $newpath); unlink($preupload); } copy($newpath, $smallpath); resizeImg(1150, $newpath, $imgExtension, 75); resizeImg(228, $smallpath, $imgExtension, 50); }
protected function updateAvatar() { if (isset($_POST["newAvatar"])) { $data = explode(',', $_POST["newAvatar"]); if (count($data) == 2 && $data[0] == "data:image/png;base64" && base64_decode($data[1])) { $img = imagecreatefromstring(base64_decode($data[1])); $nameToDelete = $this->data["loggedUser"]->getAvatarPath(); $name = md5(uniqid()) . ".png"; $this->data["loggedUser"]->setAvatarPath($name)->save(); $dir = "Includes/images/avatars/250x250/"; if (is_file($dir . $nameToDelete)) { unlink($dir . $nameToDelete); } imagepng(resizeImg($img, 250, 250), $dir . $name); $dir = "Includes/images/avatars/40x40/"; if (is_file($dir . $nameToDelete)) { unlink($dir . $nameToDelete); } imagepng(resizeImg($img, 40, 40), $dir . $name); $this->sendFlashMessage("Your avatar has been successfuly changed. ", "success"); $this->redirect($this->data["referersURI"]); } else { setHTTPStatusCode("400"); } } else { setHTTPStatusCode("400"); } }
$y = floor(($maxheight - $heightr) / 2); $imgr = imagecreatetruecolor($widthr, $heightr); //$blue = imagecolorallocatealpha($imgr, 180, 193, 205, 0); //imagefill($imgr, 0, 0, $blue); imagecopyresized($imgr, $imgo, 0, 0, 0, 0, $widthr, $heightr, $widtho, $heighto); //$color_txt = imagecolorallocatealpha($imgr, 175, 175, 175, 0); //imagettftext($imgr, 12, 0, $widthr - 135, $heightr - 3, $color_txt, $font, $txt); //$imgt = imagecreatetruecolor($maxwidth, $maxheight); //$blue = imagecolorallocatealpha($imgt, 255, 235, 136, 0); //imagefill($imgt, 0, 0, $blue); //imagecopyresized($imgt, $imgr, $x, $y, 0, 0, $widthr, $heightr, $widthr, $heightr); imagecopyresampled($imgr, $imgo, 0, 0, 0, 0, $widthr, $heightr, $widtho, $heighto); ob_start(); header('Content-type: image/jpeg'); imagejpeg($imgr, null, 100); ob_end_flush(); //imagedestroy($imgt); imagedestroy($imgo); imagedestroy($imgr); } putenv('GDFONTPATH=.'); //$cheminphoto = $RepertoirePhoto.$idDescription."/"; //$imgfile = $cheminphoto.$file; //$imgsize = $_SESSION['dim_img']; //$imgsize = array($imglargeur,$imghauteur); //$config = new ArchiConfig(); if (is_file($photoOriginale)) { resizeImg($photoOriginale, $dimX, $dimX); } else { http_response_code(404); }