public function beforeSave($options = array()) { $imageRes = new ImageResize(); $this->data['User']['status'] = 1; if (isset($this->data['User']['photo'])) { $data = $this->data['User']['photo']; $path = dirname(__FILE__) . '/../../app/webroot/user_image/'; $file = $imageRes->resize($data, 300, 220, $path); $this->data['User']['photo'] = $file; } }
public static function postImage($file, $filename, $uploadDir, $isThumb = false, $width = 800, $uploadThumb = "", $widthThumb = 150) { $destinationPath = $uploadDir; if (!file_exists($destinationPath)) { mkdir($destinationPath, 0777); } if ($uploadThumb != "") { if (!file_exists($uploadThumb)) { mkdir($uploadThumb, 0777); } } $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); $filename = $filename . "." . $extension; $uploadSuccess = ""; if ($extension == "jpg" || $extension == "jpeg" || $extension == "gif" || $extension == "png" || $extension == "tiff") { $uploadSuccess1 = move_uploaded_file($file['tmp_name'], $destinationPath . "/" . $filename); if (!$uploadSuccess1) { return; } if ($isThumb === true) { $uploadSuccess2 = copy($destinationPath . "/" . $filename, $uploadThumb . "/" . $filename); } } ImageResize::load($destinationPath . "/" . $filename); ImageResize::resizeToWidth($width); ImageResize::save(); if ($isThumb === true) { ImageResize::load($uploadThumb . "/" . $filename); ImageResize::resizeToWidth($widthThumb); ImageResize::save(); } return $filename; }
function uihelper_resize_img($picture, $max_x, $max_y, $alternate = NULL, $extra_attrs = 'alt="PA"', $opts = RESIZE_CROP) { global $path_prefix, $base_url; $ret = ImageResize::resize_img("{$path_prefix}/web", $base_url, "files/rsz", $max_x, $max_y, $picture, $alternate, FALSE, $opts); $ret['url'] = $base_url . '/' . $ret['final_path']; return $ret; }
public function updateUserInfo($user_id, $post, $user_photo, $user_cover) { if (!empty($user_photo)) { $user_photo_res = Yii::app()->request->getBaseUrl(true) . '/' . $user_photo; } if (!empty($user_cover)) { $user_cover_res = Yii::app()->request->getBaseUrl(true) . '/' . $user_cover; } $model = User::model()->findByAttributes(array('id' => $user_id)); $model->setAttributes($post); //echo $user_photo; die; if (!empty($user_photo_res)) { $photo = ImageResize::resize_image($user_photo_res, '', 128, 128, false, 'avatar', false, false, 100); $model->photo = $photo; } if (!empty($user_cover_res)) { $cover = ImageResize::resize_image($user_cover_res, '', 1800, 1200, false, 'cover', false, false, 80); $model->cover = $cover; } $model->updated_at = time(); if ($model->save(FALSE)) { return TRUE; } return FALSE; }
protected function runInternal() { list($originalWidth, $originalHeight) = getimagesize($this->filePath); // Defaults offset - center $minOriginalSize = min($originalWidth, $originalHeight); if ($this->width > $this->height) { $cropWidth = $minOriginalSize; $cropHeight = (int) floor($minOriginalSize * ($this->height / $this->width)); } else { $cropWidth = $minOriginalSize; $cropHeight = (int) floor($minOriginalSize * ($this->width / $this->height)); } // Crop $cropProcessor = new ImageCrop(['filePath' => $this->filePath, 'width' => $cropWidth, 'height' => $cropHeight, 'thumbQuality' => $this->thumbQuality, 'offsetX' => round(($originalWidth - $cropWidth) / 2), 'offsetY' => round(($originalHeight - $cropHeight) / 2)]); $cropProcessor->run(); // Resize $fitProcessor = new ImageResize(['filePath' => $this->filePath, 'width' => $this->width, 'height' => $this->height, 'thumbQuality' => $this->thumbQuality]); $fitProcessor->run(); $this->width = $fitProcessor->width; $this->height = $fitProcessor->height; }
/** * リサイズ */ public function resize($fileName, $mimeType, $sizeType = 'normal') { // 画像のサイズを取得する。 $imageSize = $this->sizes($fileName); // 画像の拡張性を設定スル。 $mimeType = explode('/', $mimeType); App::uses('ImageResize', 'Vendor'); // 切り抜きサイズを取得 $resize = Configure::read('resize_info'); $resize = $resize[$sizeType]; //画像を幅100pxでリサイズして保存 $newImgname = time() . rand(100000, 999999) . '.png'; $thumb = new ImageResize($fileName, $mimeType[1]); $thumb->name($newImgname); if ($resize['height'] > $resize['width']) { $thumb->height($resize['height']); } else { $thumb->width($resize['width']); } $thumb->save(); // サイズの中心から抜き取り。 $tmp_dir = ini_get('upload_tmp_dir'); if (empty($tmp_dir)) { $tmp_dir = '/tmp'; } if ($resize['height'] != null) { $thumb = new ImageResize($tmp_dir . '/' . $newImgname, $mimeType[1]); $thumb->name($newImgname); $thumb->width($resize['width']); $thumb->height($resize['height']); $thumb->crop(0, 0); $thumb->save(); } return $tmp_dir . '/' . $newImgname; }
function save($temp_name, $field_name = false, $table = false, $id = false, $dir = false, $img_sizes = false, $field_name_n = false) { global $CFG; if ($temp_name) { $temp_name1 = $temp_name; $temp_name = $CFG->dirroot . $CFG->temp_file_location . $temp_name; $dir1 = $dir; $dir = $dir ? $CFG->dirroot . $dir : $CFG->dirroot . $CFG->default_upload_location; $dir = !stristr($dir, '/') ? $dir . '/' : $dir; $file_parts = explode('.', $temp_name); $ext = strtolower(end($file_parts)); DB::saveImageSizes($field_name, $_REQUEST['image_sizes'][$field_name]); $image_sizes = DB::getImageSizes($field_name); if ($id) { $ext1 = in_array($ext, $CFG->accepted_image_formats) ? 'jpg' : $ext; $i = DB::insert($table . '_files', array('f_id' => $id, 'ext' => $ext1, 'dir' => $dir1, 'old_name' => $temp_name1, 'field_name' => $field_name)); self::saveDescriptions($table, $field_name_n, $i); if (in_array($ext, $CFG->accepted_image_formats)) { $ir = new ImageResize($temp_name, false, false, false); if ($_REQUEST['crop_images'][$field_name]) { $ir->setAutoCrop(true); } $ir->setHighQuality(); if (!is_array($img_sizes)) { $ir->save($dir . $table . '_' . $id . '_' . $i . '.' . $ext1, 'jpeg', 90); if ($_REQUEST['encrypt_files'][$field_name]) { File::encrypt($dir . $table . '_' . $id . '_' . $i . '.' . $ext1); } } else { foreach ($image_sizes as $key => $size) { $ir->setSize($size['width'], $size['height']); $ir->save($dir . $table . '_' . $id . '_' . $i . '_' . $key . '.' . $ext1, 'jpeg', 90); if ($_REQUEST['encrypt_files'][$field_name]) { File::encrypt($dir . $table . '_' . $id . '_' . $i . '_' . $key . '.' . $ext1); } } } @unlink($temp_name); return true; } else { if (rename($temp_name, $dir . $table . '_' . $id . '_' . $i . '.' . $ext)) { if ($_REQUEST['encrypt_files'][$field_name]) { File::encrypt($dir . $table . '_' . $id . '_' . $i . '.' . $ext); } return true; } } } else { if (@rename($temp_name, $dir . $temp_name)) { if ($_REQUEST['encrypt_files'][$field_name]) { File::encrypt($dir . $dir . $temp_name); } return $dir . $temp_name; } } } else { return false; } }
function ResizeImage($x, $y, $imageurl) { if ($x > 0 && $y > 0 && strlen($imageurl) > 3) { $data = parse_url(str_replace('/', '!', $imageurl)); $newfilename = $data['scheme'] . '~' . $data['host'] . '~' . $x . '~' . $y . $data['path']; $newfilepath = 'temp/' . $newfilename; $newsavedfilepath = 'resized/' . $newfilename; $baseurl = 'http://futurestore.areality3d.com'; if (!file_exists($newsavedfilepath)) { $handle = copy($imageurl, $newfilepath); $image = new ImageResize($newfilepath); $image->crop($x, $y); $image->save($newsavedfilepath); $newurl = $baseurl . '/' . $newsavedfilepath; } else { $newurl = $baseurl . '/' . $newsavedfilepath; } return $newurl; } else { return 'need x,y,imageurl'; } }
/** * Parse the filename of the requested image * for size information and resize accordingly. */ function image_resize_scale($path) { $params = explode("/", $path); $namepart = array_pop($params); $public_path = URL_PUBLIC . "/" . join("/", $params); $server_path = FROG_ROOT . "/" . join("/", $params); // Dissect filename to find dimension information $pattern = <<<FILENAME_PATTERN /^ # Acceptable input examples (non-exhaustive): # Width scaling: file.200.jpg file.200x.jpg # Height scaling: file.x200.jpg # Arbitrary scaling: file.200x200.jpg # Cropping: file.200c.jpg file.200x200c.jpg (.+) # source file name-part \\.(?!x?c?\\.) # prevents "image..jpg" and so forth (\\d+)? # width x?(\\d+)? # height (c)? # optional crop (\\.[a-z]+) # source file extension \$/ix FILENAME_PATTERN; if (preg_match($pattern, $namepart, $match)) { $filename = $match[1] . $match[5]; $width = (int) $match[2]; $height = (int) $match[3]; $crop = 'c' == $match[4]; $source = $server_path . "/" . $filename; $destination = $server_path . "/" . $namepart; } else { return false; } if ($crop) { return ImageResize::image_scale_cropped($source, $destination, $width, $height); } else { return ImageResize::image_scale($source, $destination, $width, $height); } }
$funcNum = $_GET['CKEditorFuncNum']; // Optional: instance name (might be used to load a specific configuration file or anything else). $CKEditor = $_GET['CKEditor']; // Optional: might be used to provide localized messages. $langCode = $_GET['langCode']; // Check the $_FILES array and save the file. Assign the correct path to a variable ($url). $url = "http://horrieinternational.com/news/uploads/" . $fileName; // Usually you will only assign something here if the file could not be uploaded. $message = "File uploaded successfully!"; echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction({$funcNum}, '{$url}', '{$message}');</script>"; list($width, $height, $type, $attr) = getimagesize("uploads/" . $fileName); if ($width > 450) { include "../util/image_resize.php"; $height = $height > 450 ? 450 : $height; // Resize image $imgResizer = new ImageResize("uploads/" . $fileName); // options: exact, portrait, landscape, auto, crop) $imgResizer->resizeImage(450, $height, "landscape"); $imgResizer->saveImage("uploads/" . $fileName, 100); } // Load the stamp and the photo to apply the watermark to $stamp = imagecreatefrompng('watermark.png'); $im = NULL; switch ($ext) { case "gif": $im = imagecreatefromgif("uploads/" . $fileName); break; case "jpeg": case "jpg": $im = imagecreatefromjpeg("uploads/" . $fileName); break;
public function uploadFiles($folder, $formdata, $itemId = null, $user_defined_filename = null, $thumbnails = array(), $force = false) { // setup dir names absolute and relative $folder_url = WWW_ROOT . $folder; $rel_url = $folder; // create the folder if it does not exist if (!is_dir($folder_url)) { mkdir($folder_url); } // if itemId is set create an item folder if ($itemId) { // set new absolute folder $folder_url = WWW_ROOT . $folder . '/' . $itemId; // set new relative folder $rel_url = $folder . '/' . $itemId; // create directory if (!is_dir($folder_url)) { mkdir($folder_url); } } // list of permitted file types, this is only images but documents can be added $permitted = array('image/gif', 'image/jpeg', 'image/jpg', 'image/pjpeg', 'image/png', 'text/csv', 'application/vnd.ms-excel', 'text/html', 'text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/x-csv', 'text/x-csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain', 'application/pdf'); // loop through and deal with the files // error_log("file".print_r($formdata,true)); foreach ($formdata as $file) { // replace spaces with underscores $filename = str_replace(' ', '_', $file['name']); //error_log("file".print_r($file,true)); if (!empty($user_defined_filename)) { $filename = $user_defined_filename; } // assume filetype is false $typeOK = false; // check filetype is ok foreach ($permitted as $type) { if ($type == $file['type']) { $typeOK = true; break; } } // if file type ok upload the file // error_log("tyrp".$typeOK); if ($typeOK) { // switch based on error code switch ($file['error']) { case 0: // check filename already exists if (!file_exists($folder_url . '/' . $filename) || $force) { // create full filename $full_url = $folder_url . '/' . $filename; $url = $rel_url . '/' . $filename; // upload the file $success = move_uploaded_file($file['tmp_name'], $url); } else { // create unique filename and upload file ini_set('date.timezone', 'Asia/Kolkata'); $now = date('Y-m-d-His'); $filename = $now . $filename; $full_url = $folder_url . '/' . $filename; $url = $rel_url . '/' . $filename; $success = move_uploaded_file($file['tmp_name'], $url); } // if upload was successful if ($success) { // save the url of the file foreach ($thumbnails as $thumbnail) { $file = explode(".", $filename); $file = $folder_url . "/" . $file[0] . "_" . $thumbnail . "." . $file[1]; $ThumbnailGenerator = new ImageResize(); $ThumbnailGenerator->GenerateThumbnail($full_url, $file, $thumbnail, 0, 0.8); } $result['urls'][] = $url; } else { $result['errors'][] = "Error uploaded {$filename}. Please try again."; } break; case 3: // an error occured $result['errors'][] = "Error uploading {$filename}. Please try again."; break; default: // an error occured $result['errors'][] = "System error uploading {$filename}. Contact webmaster."; break; } } elseif ($file['error'] == 4) { // no file was selected for upload $result['nofiles'][] = "No file Selected"; } else { // unacceptable file type $result['errors'][] = "{$filename} cannot be uploaded. Acceptable file types: gif, jpg, png,csv."; } } return $result; }
* Resgata nome da imagem final */ private function getImageName($options) { $name = $this->file['name']; if (isset($options['name'])) { $name = $options['name'] . '.' . $this->config['ext']; } return $name; } /** * Resgata nomes dos uploads */ public function getName() { return $this->name; } /** * Verifica se é imagem o upload */ public function isImage() { $images = array('jpg', 'jpeg', 'gif', 'png'); if (in_array($this->info['ext'], $images)) { return true; } return false; } } $image = new ImageResize(); $image->display();
if ($Content == $TagInfo['Description']) { AlertMsg($Lang['Do_Not_Modify'], $Lang['Do_Not_Modify']); } if ($DB->query('UPDATE ' . $Prefix . 'tags SET Description = :Content WHERE ID=:TagID', array('TagID' => $ID, 'Content' => $Content))) { $Message = $Lang['Edited']; } else { AlertMsg($Lang['Failure_Edit'], $Lang['Failure_Edit']); } break; // 修改标签图标 // 修改标签图标 case 'UploadIcon': Auth(3); if ($_FILES['TagIcon']['size'] && $_FILES['TagIcon']['size'] < 1048576) { require __DIR__ . "/includes/ImageResize.class.php"; $UploadIcon = new ImageResize('PostField', 'TagIcon'); $LUploadResult = $UploadIcon->Resize(256, 'upload/tag/large/' . $ID . '.png', 80); $MUploadResult = $UploadIcon->Resize(48, 'upload/tag/middle/' . $ID . '.png', 90); $SUploadResult = $UploadIcon->Resize(24, 'upload/tag/small/' . $ID . '.png', 90); if ($LUploadResult && $MUploadResult && $SUploadResult) { $SetTagIconStatus = $TagInfo['Icon'] == 0 ? $DB->query('UPDATE ' . $Prefix . 'tags SET Icon = 1 Where ID=:TagID', array('TagID' => $ID)) : true; $Message = $SetTagIconStatus ? $Lang['Icon_Upload_Success'] : $Lang['Icon_Upload_Failure']; } else { $Message = $Lang['Icon_Upload_Failure']; } } else { $Message = $Lang['Icon_Is_Oversize']; } break; // 禁用/启用该标签 // 禁用/启用该标签
global $wgUser; $start_at = 99442; $batch_size = 1000; //save user $tempUser = $wgUser; //swap user $wgUser = User::newFromName('LargeImageBot'); //get all $articles = self::getArticles($start_at, 150000); $count = 0; $full_count = $start_at; //cycle through 1000 at a time while ($a = array_shift($articles)) { $res = self::resizeImages($a); print $full_count . ' - ' . $res . "\n"; if ($count >= $batch_size) { $count = 0; //SLEEP IN HEAVENLY PEACE!!! print "sleeping...\n"; sleep(4 * 60); } else { $count++; } $full_count++; } //swap back $wgUser = $tempUser; } } ImageResize::main();
public function beforeSave() { //Загрузка аватара пользователем $path = Yii::getPathOfAlias('webroot') . DS . 'upload' . DS; Yii::app()->cFile->createDir(0775, $path . 'avatars' . DS); Yii::app()->cFile->set($path . 'avatars', true)->setPermissions('0775'); if ($this->image) { $file = $path . 'temp' . DIRECTORY_SEPARATOR . $this->image->name; $this->image->saveAs($file); if ($file) { $resizeObj = new ImageResize($file); $resizeObj->resizeImage(100, 100, 'crop'); $resizeObj->saveImage($path . DS . 'avatars' . DS . $this->id . '.jpg', 100); unlink($file); } } parent::beforeSave(); return true; }
function subirImagen($descripcion){ include_once("imageresize.class.php"); $f=new funciones(); $pagina="mantenimiento.php?usuario=".$_GET["usuario"]."&tipo=".$_GET["tipo"]."&transaccion=picsGal&galPage="; $idFolder=$_GET["idFolder"]; $ruta=$f->subir_archivos("galerias"); if(mysql::consulta("INSERT INTO fotosgaleria(id,idGaleria,ruta,descripcion) VALUES(Null,'".$idFolder."','".$ruta."','".$descripcion."')")){ //////////////////// Crear thumbnail ////////////////////// $source = $ruta; $dest = str_replace("galerias","galerias/thumbs",$ruta); $oResize = new ImageResize($source); //$oResize->resizeArea(8); //porcentaje //$oResize->resizeWidth(160); $oResize->resizeWidthHeight(130,130); $oResize->save($dest); ////////////////////////////////////////// header("Location: ".$pagina."optFolder&idFolder=".$idFolder.""); } }
/** * Resizes an image and returns the image contents * @param string $image_location * @param integer $dest_width * @param integer $dest_height * @param integer $dest_padding * @return string */ static function resizeImageFromString($image_source_contents, $dest_width = 128, $dest_height = 128, $dest_padding = 5) { $image_resize = new ImageResize(); $image_resize->setDestinationImageHeight($dest_height); $image_resize->setDestinationImageWidth($dest_width); $image_resize->setDestinationImagePadding($dest_padding); return $image_resize->resize($image_source_contents); }
WHERE UserID=?', array($CurUserID)); $TemporaryOauthData = json_decode($Config['CacheOauth'], true); $TemporaryOauthData = $TemporaryOauthData ? $TemporaryOauthData : array(); $OauthData = array(); foreach ($TemporaryOauthData as $Value) { $OauthData[$Value['ID']] = $Value; } unset($TemporaryOauthData); // $DoNotNeedOriginalPassword === True表示该用户为oAuth登陆用户,修改密码不需要原密码 if ($_SERVER['REQUEST_METHOD'] == 'POST') { $Action = Request('POST', 'Action', false); switch ($Action) { case 'UploadAvatar': if ($_FILES['Avatar']['size'] && $_FILES['Avatar']['size'] < 1048576) { require __DIR__ . "/includes/ImageResize.class.php"; $UploadAvatar = new ImageResize('PostField', 'Avatar'); $LUploadResult = $UploadAvatar->Resize(256, 'upload/avatar/large/' . $CurUserID . '.png', 80); $MUploadResult = $UploadAvatar->Resize(48, 'upload/avatar/middle/' . $CurUserID . '.png', 90); $SUploadResult = $UploadAvatar->Resize(24, 'upload/avatar/small/' . $CurUserID . '.png', 90); if ($LUploadResult && $MUploadResult && $SUploadResult) { $UploadAvatarMessage = $Lang['Avatar_Upload_Success']; } else { $UploadAvatarMessage = $Lang['Avatar_Upload_Failure']; } } else { $UploadAvatarMessage = $Lang['Avatar_Is_Oversize']; } break; case 'UpdateUserInfo': $CurUserInfo['UserSex'] = intval(Request('POST', 'UserSex', 0)); $CurUserInfo['UserMail'] = IsEmail(Request('POST', 'UserMail', $CurUserInfo['UserMail'])) ? Request('POST', 'UserMail', $CurUserInfo['UserMail']) : $CurUserInfo['UserMail'];
if (isset($_POST['send_students_data'])) { if (empty($_POST['name']) || empty($_POST['class']) || empty($_POST['roll'])) { echo '<script>std_empty();</script>'; echo "<meta http-equiv='refresh' content='1;url='>"; exit; } $image_name = isset($_FILES['edit-students-image']['name']) ? $_FILES['edit-students-image']['name'] : NULL; $tmp_name = isset($_FILES['edit-students-image']['tmp_name']) ? $_FILES['edit-students-image']['tmp_name'] : NULL; $rand_img = !empty($image_name) ? rand(1000, 9999) . '.jpg' : ''; if (!empty($image_name)) { $students_img_location = $plug_path . 'images/scl_students/' . $rand_img; if (!empty($image_name)) { $mime = getimagesize($tmp_name); if (in_array('image', explode('/', $mime['mime']))) { move_uploaded_file($tmp_name, $students_img_location); $image = new ImageResize($students_img_location); $image->resize(140, 140); $image->save(); copy($students_img_location, 'img/admin/student_' . $rand_img); } } } $fields = array('id' => $_POST['id'], 'name' => $_POST['name'], 'class' => $_POST['class'], 'roll' => $_POST['roll'], 'gender' => $_POST['gender'], 'address' => $_POST['address'], 'date_of_birth' => $_POST['date_of_birth'], 'mobile' => $_POST['mobile'], 'email' => $_POST['email']); if (!empty($image_name)) { $fields['image'] = $rand_img; } $where = array('id' => $_POST['id']); if (db_update('scl_students', $fields, $where)) { $fields = array('full_name' => $_POST['name'], 'email' => $_POST['email']); $where = array('username' => 'student_' . $_POST['id']); if (isset($image_name)) {
$login_required = FALSE; include dirname(__FILE__)."/../includes/page.php"; include "$path_prefix/web/update/admin_login.php"; switch (@$_REQUEST['engine']) { case 'gd': ImageResize::$skip_magick = TRUE; break; case 'magick': ImageResize::$skip_gd = TRUE; break; } ?><h1>testing ImageResize module with engine <?php echo ImageResize::get_engine(); ?> </h1> <p><a href="test_imageresize.php">default</a> | <a href="test_imageresize.php?engine=gd">gd</a> | <a href="test_imageresize.php?engine=magick">magick</a> (make sure to hit ctrl-F5 after clicking, to clear the cache)</p> <p>flushing cache ... <?php flush(); system("rm -rf ../files/rsz"); ?> ... done</p> <p>orig: <img src="../images/palogo_black_bg.jpg"></p> <h2>stretching 135x75 to 300x300</h2>
//////////////////////////////// CREAR THUMBNAILS //////////////////////////////////////////// $totalimagenes=count($imagenes); $totalthumbs=delvolvercantidaddefotos($rutafolder."/thumbs/"); if($totalimagenes!=$totalthumbs){ for($x=0;$x<$totalimagenes;$x++){ $source = $rutafolder."/".$imagenes[$x]; $dest = $rutafolder."/thumbs/".$imagenes[$x]; if (!file_exists($dest)){ @unlink($dest); $oResize = new ImageResize($source); //$oResize->resizeArea(8); //porcentaje //$oResize->resizeWidth(120); $oResize->resizeWidthHeight(120,90); $oResize->save($dest); } } } ////////////////////////////////////////////////////////////////////////////////////// $totalxpagina=15; $totalpaginas=($totalimagenes/$totalxpagina); if(is_float($totalpaginas)){ $totalpaginas=ceil($totalpaginas);}
function api_resize_user_image($picture, $imageWidth, $imageHeight) { $picture = trim($picture); if (empty($picture)) { return NULL; } // ripped off from web/includes/image_resize.php (uihelper_preprocess_pic_path) if (defined("NEW_STORAGE") && preg_match("|^pa://|", $picture)) { $picture = Storage::get($picture); } else { $picture = "files/{$picture}"; if (!file_exists(PA::$project_dir . "/web/{$picture}") && !file_exists(PA::$core_dir . "/web/{$picture}")) { return NULL; } } if ($imageWidth) { // scale image down $im_info = ImageResize::resize_img("web", PA::$url, "files/rsz", $imageWidth, $imageHeight, $picture); } else { $im_size = @getimagesize(Storage::getPath($picture)); $im_info = array('url' => Storage::getURL($picture), 'width' => $im_size[0], 'height' => $im_size[1]); } return array('url' => $im_info['url'], 'height' => (int) $im_info['height'], 'width' => (int) $im_info['width']); }
<?php require_once './ImageResize.php'; $imgsdir = 'imgs/'; $scale = 300; $im = new ImageResize($imgsdir, $scale); $filelist = $im->get_file($im->dirname); $path = $im->filetype($filelist); $target = $im->image_info($path); $im->resize($target); $im->reduction($im->resized);
<?php $UploadAvatarMessage = ''; require dirname(__FILE__) . "/src/ImageResize.class.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_URL, 'https://avatars0.githubusercontent.com/u/5785188?v=3&s=460'); $response = curl_exec($ch); curl_close($ch); if (!empty($response)) { $UploadAvatar = new ImageResize('String', $response); $LUploadResult = $UploadAvatar->Resize(256, 'curl_large.png', 100); $MUploadResult = $UploadAvatar->Resize(48, 'curl_middle.png', 90); $SUploadResult = $UploadAvatar->Resize(24, 'curl_small.png', 90); if ($LUploadResult && $MUploadResult && $SUploadResult) { $UploadAvatarMessage = 'Success'; } else { $UploadAvatarMessage = 'Failure. This file may not be image.'; } } echo $UploadAvatarMessage;
private function make_square_image($infn, $gd_OR_magick = "GD") { // global var $path_prefix has been removed - please, use PA::$path static variable $directory = PA::$project_dir . "/web/files/square/"; //TO DO: Remove hardcoding here. if (!is_dir($directory)) { ImageResize::try_mkdir($directory); } $file_path = explode("/", $infn); // TO DO: Rename images to avoid conflicts. $imageName = $file_path[count($file_path) - 1]; $destination = $directory . $imageName; if (file_exists($destination) && filemtime($destination) > filemtime($infn)) { return SQUARE_IMAGES . '/' . $imageName; } $dimensions = getimagesize($infn); $width = $dimensions[0]; $height = $dimensions[1]; if ($width == $height) { // Image is a square image copy($infn, $destination); return SQUARE_IMAGES . '/' . $imageName; } $X_start = $Y_start = $width_final = $height_final = $offset = 0; if ($width > $height) { // width more than height $X_start = round(($width - $height) / 2); $Y_start = 0; $offset = $height; $width_final = $height_final = $height; } else { // height more than width $X_start = 0; $Y_start = round(($height - $width) / 2); $width_final = $height_final = $width; $offset = $width; } if ($gd_OR_magick == "MAGICK") { $cmd = 'convert -crop ' . $width_final . 'x' . $height_final . '+' . $X_start . '+' . $Y_start . ' ' . $infn . ' ' . SQUARE_IMAGES . '/' . $imageName; system($cmd, $retval); return SQUARE_IMAGES . '/' . $imageName; } $orig = ImageResize::loadimage($infn); $imageDestination = imagecreatetruecolor($width_final, $height_final); imagecopyresampled($imageDestination, $orig, 0, 0, $X_start, $Y_start, $width_final, $height_final, $offset, $offset); imagejpeg($imageDestination, $destination, 100); imagedestroy($imageDestination); imagedestroy($orig); return SQUARE_IMAGES . '/' . $imageName; }
function show_amazon_s3_image($picture_path, $max_x, $max_y, $extra_attrs = "") { if (!isset($picture_path) || empty($picture_path)) { $defaultImg = PA::$url . '/files/default.png'; return ImageResize::display_image_from_url($defaultImg, $max_x, $max_y, $extra_attrs); } if (preg_match("|^http://|", $picture_path)) { return ImageResize::display_image_from_url($picture_path, $max_x, $max_y, $extra_attrs); } else { $full_amazon_path = get_full_amazon_s3_url($picture_path); return ImageResize::display_image_from_url($full_amazon_path, $max_x, $max_y, $extra_attrs); } }
public function upload(Request $request) { Log::info('Uploading Files!'); $file = $request->file; $extension = $file->getClientOriginalExtension(); Storage::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file)); $entry = new Fileentry(); $entry->mime = $file->getClientMimeType(); $entry->original_filename = $file->getClientOriginalName(); $entry->filename = $file->getFilename() . '.' . $extension; $entry->model_id = "0"; //create thumb for images if (strpos($file->getClientMimeType(), "image/") !== false) { $image = new ImageResize($file); $image->resizeToHeight(150); $entry->thumb = $image->getImageAsString(); } $entry->save(); return ['success' => false, 'data' => 200]; }
public function documentation() { $this->display('image_resize/views/documentation', array('gd_status' => ImageResize::gd_available(), 'mod_rewrite_status' => USE_MOD_REWRITE)); }
<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <title>Ejemplo</title> </head> <body> <h1 id="titulo">Ejemplo</h1> <div> <?php require "ImageResize.php"; $src = "archivo.jpg"; $dest = "archivo150x150.jpg"; $resize = new ImageResize($src); $resize->resize(150, 150); if (!@$resize->save($dest)) { echo "Archivo no fue generado. Error: " . error_get_last(); } else { echo "Archivo {$dest} generado."; } ?> </div> </body> </html>
public function resize() { $this->loadFile(); $imageResize = new ImageResize($this->file); $imageResize->resize(900); }