Browse Source

file

master
Mohammad Khazaee 2 years ago
parent
commit
a2567ed6b5
  1. 28
      app/Image/Processor.php
  2. BIN
      public/image-modified.jpg
  3. BIN
      public/image-modified.png
  4. BIN
      public/image-modified2.jpg
  5. BIN
      public/imagecircle.png
  6. 83
      routes/web.php

28
app/Image/Processor.php

@ -0,0 +1,28 @@
<?php
namespace App\Image;
use Jcupitt\Vips\Interpretation;
class Processor {
public static function brightness($image, float $brightness = 1.0, float $saturation = 1.0, float $hue = 0.0) {
$oldInterpretation = $image->interpretation;
$hue %= 360;
if ($hue < 0) {
$hue = 360 + $hue;
}
if ($image->hasAlpha()) {
$imageWithoutAlpha = $image->extract_band(0, ['n' => $image->bands - 1]);
$alpha = $image->extract_band($image->bands - 1, ['n' => 1]);
return $imageWithoutAlpha
->colourspace(Interpretation::LCH)
->linear([$brightness, $saturation, 1.0], [0.0, 0.0, $hue])
->colourspace($oldInterpretation)
->bandjoin($alpha);
}
return $image
->colourspace(Interpretation::LCH)
->linear([$brightness, $saturation, 1.0], [0.0, 0.0, $hue])
->colourspace($oldInterpretation);
}
}

BIN
public/image-modified.jpg

Binary file not shown.

Before

Width: 1000  |  Height: 652  |  Size: 13 KiB

After

Width: 5000  |  Height: 5000  |  Size: 2.9 MiB

BIN
public/image-modified.png

Binary file not shown.

After

Width: 1000  |  Height: 652  |  Size: 935 KiB

BIN
public/image-modified2.jpg

Binary file not shown.

After

Width: 180  |  Height: 417  |  Size: 20 KiB

BIN
public/imagecircle.png

Binary file not shown.

After

Width: 180  |  Height: 417  |  Size: 146 KiB

83
routes/web.php

@ -1,8 +1,10 @@
<?php
use App\Image\Processor;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Jcupitt\Vips\Image;
/*
|--------------------------------------------------------------------------
| Web Routes
@ -14,21 +16,80 @@ use Jcupitt\Vips\Image;
|
*/
// Route::get('/update', function () {
// $user = \App\Models\User::first();
// $user->fill(['name' => 'xxxxxx']);
// $user->saveRich();
Route::get('/', function (Request $request) {
// && !isset($request->h)
if (isset($request->w) && isset($request->h)) {
$image = Image::thumbnail('../public/image.jpg', $request->w, ['height' => $request->h, 'crop' => 'centre']);
}
if (isset($request->w) && !isset($request->h)) {
$image = Image::thumbnail('../public/image.jpg', $request->w, ['height' => getimagesize('../public/image.jpg')[1]]);
}
if (!isset($request->w) && isset($request->h)) {
$image = Image::thumbnail('../public/image.jpg', getimagesize('../public/image.jpg')[0], ['height' => $request->h]);
}
$y = null;
$x = null;
if (isset($request->brightness) || isset($request->saturation)) {
$image = Processor::brightness($image, isset($request->brightness) ? $request->brightness : 1.0, isset($request->saturation) ? $request->saturation : 1.0);
}
if ($request->rotation) {
$image = $image->rotate($request->rotation);
}
// ----------------------------------------------------------------------------------------
if ($request->cpx) {
$GLOBALS['x'] = $request->cpx;
} else {
$GLOBALS['x'] = ($image->width - $request->w) / 2;
}
if ($request->cpy) {
$GLOBALS['y'] = $request->cpy;
} else {
$GLOBALS['y'] = ($image->height - $request->h) / 2;
}
if ($request->debug == true) {
if (!$request->cpx) {
$image = $image->draw_line(1000, $image->width / 2, 0, $image->width / 2, $image->height);
}
if (!$request->cpy) {
$image = $image->draw_line(1000, 0, $image->height / 2, $image->width, $image->height / 2);
}
if ($request->cpx) {
$image = $image->draw_line(1000, $request->cpx, 0, $request->cpx, $image->height);
}
if ($request->cpy) {
$image = $image->draw_line(1000, 0, $request->cpy, $image->width, $request->cpy);
}
}
// ----------------------------------------------------------------------------------------
if ($request->flip == "h") {
$image = $image->fliphor();
}
if ($request->flip == "v") {
$image = $image->flipver();
}
// return 'done';
// return view('welcome');
// });
Route::get('/', function (Request $request) {
$image = Image::thumbnail('../public/image.jpg', $request->w);
$image->writeToFile('image-modified.jpg',[
$image->writeToFile('image-modified.jpg', [
'Q' => $request->q
]);
echo '<img src="image-modified.jpg" alt="">';
return response()->file(public_path("image-modified.jpg"));
});
Loading…
Cancel
Save