1
1
<?php
2
2
3
+ use Optimole \Sdk \Optimole ;
4
+ use Optimole \Sdk \ValueObject \Position ;
5
+
3
6
/**
4
7
* Class Optml_App_Replacer
5
8
*
@@ -615,9 +618,7 @@ protected function parse_dimensions_from_filename( $src ) {
615
618
* @return string The optimized url.
616
619
*/
617
620
public function get_media_optimized_url ( $ url , $ table_id , $ width = 'auto ' , $ height = 'auto ' , $ resize = [] ) {
618
- $ optimized_url = ( new Optml_Image ( $ url , ['width ' => $ width , 'height ' => $ height , 'resize ' => $ resize , 'quality ' => $ this ->settings ->get_numeric_quality ()], $ this ->settings ->get ( 'cache_buster ' ) ) )->get_url ();
619
- $ optimized_url = str_replace ( $ url , Optml_Media_Offload::KEYS ['not_processed_flag ' ] . 'media_cloud ' . '/ ' . Optml_Media_Offload::KEYS ['uploaded_flag ' ] . $ table_id . '/ ' . $ url , $ optimized_url );
620
- return $ optimized_url ;
621
+ return str_replace ( $ url , Optml_Media_Offload::KEYS ['not_processed_flag ' ] . 'media_cloud ' . '/ ' . Optml_Media_Offload::KEYS ['uploaded_flag ' ] . $ table_id . '/ ' . $ url , $ this ->get_optimized_image_url ( $ url , $ width , $ height , $ resize ) );
621
622
}
622
623
623
624
/**
@@ -630,4 +631,29 @@ public function get_media_optimized_url( $url, $table_id, $width = 'auto', $heig
630
631
public function url_has_dam_flag ( $ url ) {
631
632
return strpos ( $ url , Optml_Dam::URL_DAM_FLAG ) !== false ;
632
633
}
634
+
635
+ /**
636
+ * Get the optimized image url for the image url.
637
+ *
638
+ * @param string $url The image URL.
639
+ * @param mixed $width The image width.
640
+ * @param mixed $height The image height.
641
+ * @param array $resize The resize properties.
642
+ *
643
+ * @return string
644
+ */
645
+ protected function get_optimized_image_url ( $ url , $ width , $ height , $ resize = [] ) {
646
+ $ optimized_image = Optimole::image ( $ url , $ this ->settings ->get ( 'cache_buster ' ) )
647
+ ->width ( $ width )
648
+ ->height ( $ height );
649
+
650
+ if ( is_array ( $ resize ) && ! empty ( $ resize ['type ' ] ) ) {
651
+ $ optimized_image ->resize ( $ resize ['type ' ], $ resize ['gravity ' ] ?? Position::CENTER , $ resize ['enlarge ' ] ?? false );
652
+
653
+ }
654
+
655
+ $ optimized_image ->quality ( $ this ->settings ->to_accepted_quality ( $ this ->settings ->get_quality () ) );
656
+
657
+ return $ optimized_image ->getUrl ();
658
+ }
633
659
}
0 commit comments