@@ -238,7 +238,6 @@ public function add(array $files, $albumID = 0, $returnOnError = false) {
238
238
239
239
}
240
240
241
- // Save to DB
242
241
$ values = array (LYCHEE_TABLE_PHOTOS , $ id , $ info ['title ' ], $ photo_name , $ info ['description ' ], $ info ['tags ' ], $ info ['type ' ], $ info ['width ' ], $ info ['height ' ], $ info ['size ' ], $ info ['iso ' ], $ info ['aperture ' ], $ info ['make ' ], $ info ['model ' ], $ info ['shutter ' ], $ info ['focal ' ], $ info ['takestamp ' ], $ path_thumb , $ albumID , $ public , $ star , $ checksum , $ medium );
243
242
$ query = Database::prepare (Database::get (), "INSERT INTO ? (id, title, url, description, tags, type, width, height, size, iso, aperture, make, model, shutter, focal, takestamp, thumbUrl, album, public, star, checksum, medium) VALUES ('?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?') " , $ values );
244
243
$ result = Database::execute (Database::get (), $ query , __METHOD__ , __LINE__ );
@@ -296,7 +295,7 @@ private function createThumb($url, $filename, $type, $width, $height) {
296
295
Plugins::get ()->activate (__METHOD__ , 0 , func_get_args ());
297
296
298
297
// Quality of thumbnails
299
- $ thumbQuality = 90 ;
298
+ $ quality = 90 ;
300
299
301
300
// Size of the thumbnail
302
301
$ newWidth = 200 ;
@@ -312,9 +311,12 @@ private function createThumb($url, $filename, $type, $width, $height) {
312
311
// Read image
313
312
$ thumb = new Imagick ();
314
313
$ thumb ->readImage ($ url );
315
- $ thumb ->setImageCompressionQuality ($ thumbQuality );
314
+ $ thumb ->setImageCompressionQuality ($ quality );
316
315
$ thumb ->setImageFormat ('jpeg ' );
317
316
317
+ // Remove metadata to save some bytes
318
+ $ thumb ->stripImage ();
319
+
318
320
// Copy image for 2nd thumb version
319
321
$ thumb2x = clone $ thumb ;
320
322
@@ -359,12 +361,12 @@ private function createThumb($url, $filename, $type, $width, $height) {
359
361
360
362
// Create thumb
361
363
fastImageCopyResampled ($ thumb , $ sourceImg , 0 , 0 , $ startWidth , $ startHeight , $ newWidth , $ newHeight , $ newSize , $ newSize );
362
- imagejpeg ($ thumb , $ newUrl , $ thumbQuality );
364
+ imagejpeg ($ thumb , $ newUrl , $ quality );
363
365
imagedestroy ($ thumb );
364
366
365
367
// Create retina thumb
366
368
fastImageCopyResampled ($ thumb2x , $ sourceImg , 0 , 0 , $ startWidth , $ startHeight , $ newWidth *2 , $ newHeight *2 , $ newSize , $ newSize );
367
- imagejpeg ($ thumb2x , $ newUrl2x , $ thumbQuality );
369
+ imagejpeg ($ thumb2x , $ newUrl2x , $ quality );
368
370
imagedestroy ($ thumb2x );
369
371
370
372
// Free memory
@@ -395,6 +397,9 @@ private function createMedium($url, $filename, $width, $height) {
395
397
// Call plugins
396
398
Plugins::get ()->activate (__METHOD__ , 0 , func_get_args ());
397
399
400
+ // Quality of medium-photo
401
+ $ quality = 90 ;
402
+
398
403
// Set to true when creation of medium-photo failed
399
404
$ error = false ;
400
405
@@ -427,6 +432,8 @@ private function createMedium($url, $filename, $width, $height) {
427
432
428
433
// Adjust image
429
434
$ medium ->scaleImage ($ newWidth , $ newHeight , true );
435
+ $ medium ->stripImage ();
436
+ $ medium ->setImageCompressionQuality ($ quality );
430
437
431
438
// Save image
432
439
try { $ medium ->writeImage ($ newUrl ); }
@@ -472,20 +479,50 @@ public function adjustFile($path, array $info) {
472
479
473
480
if (extension_loaded ('imagick ' )&&Settings::get ()['imagick ' ]==='1 ' ) {
474
481
475
- switch ($ info ['orientation ' ]) {
482
+ $ image = new Imagick ();
483
+ $ image ->readImage ($ path );
476
484
477
- case 3 :
478
- $ rotateImage = 180 ;
485
+ $ orientation = $ image ->getImageOrientation ();
486
+
487
+ switch ($ orientation ) {
488
+
489
+ case Imagick::ORIENTATION_TOPLEFT :
490
+ return false ;
479
491
break ;
480
492
481
- case 6 :
482
- $ rotateImage = 90 ;
483
- $ swapSize = true ;
493
+ case Imagick::ORIENTATION_TOPRIGHT :
494
+ $ image ->flopImage ();
484
495
break ;
485
496
486
- case 8 :
487
- $ rotateImage = 270 ;
488
- $ swapSize = true ;
497
+ case Imagick::ORIENTATION_BOTTOMRIGHT :
498
+ $ image ->rotateImage (new ImagickPixel (), 180 );
499
+ break ;
500
+
501
+ case Imagick::ORIENTATION_BOTTOMLEFT :
502
+ $ image ->flopImage ();
503
+ $ image ->rotateImage (new ImagickPixel (), 180 );
504
+ break ;
505
+
506
+ case Imagick::ORIENTATION_LEFTTOP :
507
+ $ image ->flopImage ();
508
+ $ image ->rotateImage (new ImagickPixel (), -90 );
509
+ $ swapSize = true ;
510
+ break ;
511
+
512
+ case Imagick::ORIENTATION_RIGHTTOP :
513
+ $ image ->rotateImage (new ImagickPixel (), 90 );
514
+ $ swapSize = true ;
515
+ break ;
516
+
517
+ case Imagick::ORIENTATION_RIGHTBOTTOM :
518
+ $ image ->flopImage ();
519
+ $ image ->rotateImage (new ImagickPixel (), 90 );
520
+ $ swapSize = true ;
521
+ break ;
522
+
523
+ case Imagick::ORIENTATION_LEFTBOTTOM :
524
+ $ image ->rotateImage (new ImagickPixel (), -90 );
525
+ $ swapSize = true ;
489
526
break ;
490
527
491
528
default :
@@ -494,15 +531,13 @@ public function adjustFile($path, array $info) {
494
531
495
532
}
496
533
497
- if ($ rotateImage !==0 ) {
498
- $ image = new Imagick ();
499
- $ image ->readImage ($ path );
500
- $ image ->rotateImage (new ImagickPixel (), $ rotateImage );
501
- $ image ->setImageOrientation (1 );
502
- $ image ->writeImage ($ path );
503
- $ image ->clear ();
504
- $ image ->destroy ();
505
- }
534
+ // Adjust photo
535
+ $ image ->setImageOrientation (Imagick::ORIENTATION_TOPLEFT );
536
+ $ image ->writeImage ($ path );
537
+
538
+ // Free memory
539
+ $ image ->clear ();
540
+ $ image ->destroy ();
506
541
507
542
} else {
508
543
@@ -512,6 +547,11 @@ public function adjustFile($path, array $info) {
512
547
513
548
switch ($ info ['orientation ' ]) {
514
549
550
+ case 1 :
551
+ // do nothing
552
+ return false ;
553
+ break ;
554
+
515
555
case 2 :
516
556
// mirror
517
557
// not yet implemented
@@ -561,6 +601,7 @@ public function adjustFile($path, array $info) {
561
601
}
562
602
563
603
// Recreate photo
604
+ // In this step the photos also loses its metadata :(
564
605
$ newSourceImg = imagecreatetruecolor ($ newWidth , $ newHeight );
565
606
imagecopyresampled ($ newSourceImg , $ sourceImg , 0 , 0 , 0 , 0 , $ newWidth , $ newHeight , $ newWidth , $ newHeight );
566
607
imagejpeg ($ newSourceImg , $ path , 100 );
0 commit comments