コード例 #1
0
ファイル: DatabaseSeeder.php プロジェクト: ivial98/imagemod
 public function run()
 {
     DB::table('images')->delete();
     Image::create(['file_name' => 'first.jpg']);
     Image::create(['file_name' => 'second.jpg']);
     Image::create(['file_name' => 'third.jpg']);
 }
コード例 #2
0
 public function run()
 {
     DB::table('images')->delete();
     $faker = $this->getFaker();
     $image_list = ["http://i.imgur.com/j3NXQsK.jpg", "http://i.imgur.com/VxmP5AS.jpg", "http://i.imgur.com/IlFQw7c.jpg", "http://i.imgur.com/YFlyOti.jpg", "http://i.imgur.com/wU6f7XT.jpg"];
     for ($i = 0; $i < $this->num_records; $i++) {
         $array = ["url_location" => $image_list[$i % 5], "description" => $this->getFaker()->text];
         Image::create($array);
     }
 }
コード例 #3
0
 public function handle(StoreUploadedImageCommand $command)
 {
     $intImg = IntImage::make($command->image->getRealPath())->orientate();
     $randomFilename = uniqid();
     $fullPath = 'uploads/' . $randomFilename . '.jpg';
     \Storage::disk('images')->put($fullPath, $intImg->encode('jpg', 75));
     $width = $intImg->width();
     $height = $intImg->height();
     $average = $intImg->resize(1, 1)->pickColor(0, 0, 'rgba');
     $newImage = Image::create(['width' => $width, 'height' => $height, 'mime_type' => 'image/jpeg', 'extension' => '.jpg', 'path' => $fullPath, 'description' => '', 'average_colour' => $average]);
     return $newImage->id;
 }
コード例 #4
0
 public function run()
 {
     if (class_exists('Faker\\Factory')) {
         $faker = Faker\Factory::create();
         $scans = Scan::all()->all();
         $images = ['/img/eusthenopteron_foordi.jpg', '/img/iridotriton_hechti.jpg', '/img/sipalocyon_sp.jpg', '/img/teinolophos_trusleri.jpg'];
         foreach ($scans as $scan) {
             for ($i = 1; $i <= 500; $i++) {
                 Image::create(['filePath' => '/' . $faker->word, 'fileName' => $faker->word . $faker->randomNumber(2) . '.tif', 'fileUrl' => $faker->randomElement($images), 'scanId' => $scan->id]);
             }
         }
     }
 }
コード例 #5
0
 public static function uploadImage($nameOfImageInput)
 {
     $message = "";
     $target_dir = DIR_IMAGE_FOLDER;
     $imageId = Image::count() + 1;
     $imageExt = substr($_FILES[$nameOfImageInput]["name"], -4);
     $target_file = $target_dir . basename($imageId . $imageExt);
     $uploadOk = 1;
     $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
     // Check if image file is a actual image or fake image
     if (isset($_POST["submit"])) {
         $check = getimagesize($_FILES[$nameOfImageInput]["tmp_name"]);
         if ($check !== false) {
             $uploadOk = 1;
         } else {
             $uploadOk = 0;
         }
     }
     // Check file size
     if ($_FILES[$nameOfImageInput]["size"] > 500000) {
         $message = "Sorry, your file is too large.";
         $uploadOk = 0;
         echo "loi";
         die;
     }
     // Allow certain file formats
     if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
         $uploadOk = 0;
         $message = $message . "Not Image file type!";
     }
     // Check if $uploadOk is set to 0 by an error
     if ($uploadOk == 0) {
         Session::put("imageMessage", $message);
         return "";
         // if everything is ok, try to upload file
     } else {
         if (move_uploaded_file($_FILES[$nameOfImageInput]["tmp_name"], $target_file)) {
             Image::create(['id' => $imageId, 'path' => $target_file]);
             echo "";
             return $target_file;
         } else {
             $message = $message . "Cannot upload!";
             Session::put("imageMessage", $message);
             return "";
         }
     }
 }
コード例 #6
0
 /**
  * 上传图片,返回图片的相对路径
  * @param File  $file
  * @param int  $width
  * @param null $height
  * @return string
  */
 public function uploadImage($file, $width = 1440, $height = null)
 {
     if (!is_object($file)) {
         return '';
     }
     $allowed_extensions = ["png", "jpg", "gif"];
     if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
         return ['error' => 'You may only upload png, jpg or gif.'];
     }
     $fileName = $file->getClientOriginalName();
     $extension = $file->getClientOriginalExtension() ?: 'png';
     $folderName = rtrim(config('custom.uploads.images'), '/') . '/' . date("Ym", time()) . '/' . date("d", time());
     $destinationPath = public_path() . '/' . $folderName;
     $safeNameWithoutExt = str_random(10);
     $safeName = $safeNameWithoutExt . '.' . $extension;
     $file->move($destinationPath, $safeName);
     // If is not gif file, we will try to reduse the file size
     if ($file->getClientOriginalExtension() != 'gif') {
         // open an image file
         //            $img = Image::make($destinationPath . '/' . $safeName);
         //            // prevent possible upsizing
         //            $img->resize($width, $height, function ($constraint) {
         //                    $constraint->aspectRatio();
         //                    $constraint->upsize();
         //                });
         //            // finally we save the image as a new file
         //            $img->save();
         //save to db
         Image::create(['image_name' => $safeNameWithoutExt, 'image_path' => $folderName . '/' . $safeName, 'user_id' => Auth::user()->id]);
     }
     return ['origin_name' => $fileName, 'extension' => $extension, 'image_path' => $folderName . '/' . $safeName];
 }