/
var
/
www
/
html
/
gnet
/
gnet
/
App
/
Helpers
/
Upload File
HOME
<?php use Jenssegers\Agent\Agent; function isLowQualityConnection() { // Implement logic to determine if the connection is slow // Misalnya, kita anggap koneksi lambat jika rata-rata kecepatan di bawah 1 Mbps $thresholdSpeed = 1000; // Dalam kilobit per detik return getCurrentConnectionSpeed() < $thresholdSpeed; } function getCurrentConnectionSpeed() { // Implement logic to measure the current connection speed // Misalnya, kita kembalikan nilai konstan sebagai contoh return 1200; // Dalam kilobit per detik } function getLazyLoadImage($productImage) { if ($productImage !== null) { $agent = new Agent(); $isLowQualityConnection = isLowQualityConnection(); $isMobile = $agent->isMobile(); // Pilih gambar berdasarkan kondisi if ($isLowQualityConnection) { // Jika resolusi rendah tersedia, gunakan; jika tidak, fallback ke resolusi tinggi return $isMobile ? ($productImage->image_low_mobile ?: $productImage->image_hd_mobile ?: $productImage->image_hd) : ($productImage->image_low ?: $productImage->image_hd); } else { // Jika resolusi tinggi tersedia, gunakan; jika tidak, fallback ke resolusi rendah return $isMobile ? ($productImage->image_hd_mobile ?: $productImage->image_hd ?: $productImage->image_low_mobile) : ($productImage->image_hd ?: $productImage->image_low); } } } ?>