Add (ai gen)
This commit is contained in:
@@ -52,15 +52,15 @@ function get_smartproxy_server()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! function_exists('calculate_smartproxy_cost')) {
|
if (! function_exists('calculate_smartproxy_cost')) {
|
||||||
function calculate_smartproxy_cost(float $kb, $amplifier = 1)
|
function calculate_smartproxy_cost(float $kb, $type = 'rotating_global')
|
||||||
{
|
{
|
||||||
$cost_per_gb = config('platform.proxy.smartproxy.rotating_global.cost_per_gb');
|
$cost_per_gb = config("platform.proxy.smartproxy.{$type}.cost_per_gb");
|
||||||
|
|
||||||
// Convert cost per GB to cost per KB
|
// Convert cost per GB to cost per KB
|
||||||
$cost_per_kb = $cost_per_gb / (1024 * 1024);
|
$cost_per_kb = $cost_per_gb / (1024 * 1024);
|
||||||
|
|
||||||
// Calculate total cost for the given $kb
|
// Calculate total cost for the given $kb
|
||||||
$cost = ($cost_per_kb * $kb) * $amplifier;
|
$cost = ($cost_per_kb * $kb);
|
||||||
|
|
||||||
return round($cost, 3);
|
return round($cost, 3);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ private static function filterImages(array $images, string $proxy, string $user_
|
|||||||
];
|
];
|
||||||
$image['color_counts'] = self::isMostlyTextBasedOnUniqueColors($interventionImage);
|
$image['color_counts'] = self::isMostlyTextBasedOnUniqueColors($interventionImage);
|
||||||
//$image['img'] = $interventionImage;
|
//$image['img'] = $interventionImage;
|
||||||
$costs['count-'.$count] = calculate_smartproxy_cost($sizeKb);
|
$costs['count-'.$count] = calculate_smartproxy_cost($sizeKb, 'rotating_global');
|
||||||
|
|
||||||
$filteredImages[] = $image;
|
$filteredImages[] = $image;
|
||||||
|
|
||||||
@@ -240,6 +240,7 @@ private static function filterImages(array $images, string $proxy, string $user_
|
|||||||
$colorCounts[] = $image['color_counts'];
|
$colorCounts[] = $image['color_counts'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! empty($colorCounts)) {
|
||||||
// Compute the median of the color counts
|
// Compute the median of the color counts
|
||||||
sort($colorCounts);
|
sort($colorCounts);
|
||||||
$count = count($colorCounts);
|
$count = count($colorCounts);
|
||||||
@@ -251,6 +252,10 @@ private static function filterImages(array $images, string $proxy, string $user_
|
|||||||
$filteredImages = array_filter($filteredImages, function ($image) use ($threshold) {
|
$filteredImages = array_filter($filteredImages, function ($image) use ($threshold) {
|
||||||
return $image['color_counts'] > $threshold;
|
return $image['color_counts'] > $threshold;
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
// No images found
|
||||||
|
$filteredImages = []; // Clear the array or take any other appropriate action
|
||||||
|
}
|
||||||
|
|
||||||
usort($filteredImages, function ($a, $b) {
|
usort($filteredImages, function ($a, $b) {
|
||||||
return $b['sizeKb'] <=> $a['sizeKb']; // Using the spaceship operator to sort in descending order
|
return $b['sizeKb'] <=> $a['sizeKb']; // Using the spaceship operator to sort in descending order
|
||||||
@@ -296,7 +301,7 @@ private static function getProductImage(array $jsonLdData, string $proxy, string
|
|||||||
$sizeInKb = strlen($interventionImage->encode()) / 1024; // Convert bytes to kilobytes
|
$sizeInKb = strlen($interventionImage->encode()) / 1024; // Convert bytes to kilobytes
|
||||||
|
|
||||||
// Calculate the cost
|
// Calculate the cost
|
||||||
$cost = calculate_smartproxy_cost($sizeInKb);
|
$cost = calculate_smartproxy_cost($sizeInKb, 'rotating_global');
|
||||||
|
|
||||||
$costs['product_image'] = $cost;
|
$costs['product_image'] = $cost;
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ public static function handle(string $url, $directory, $postfix = null, $strip_h
|
|||||||
->get($cached_url);
|
->get($cached_url);
|
||||||
|
|
||||||
if ($response->successful()) {
|
if ($response->successful()) {
|
||||||
|
//$costs['html_proxy'] = calculate_smartproxy_cost()
|
||||||
$raw_html = $response->body();
|
$raw_html = $response->body();
|
||||||
// ... your logic here ...
|
// ... your logic here ...
|
||||||
} else {
|
} else {
|
||||||
@@ -274,7 +275,7 @@ private static function filterImages(array $images, string $proxy, string $user_
|
|||||||
];
|
];
|
||||||
$image['color_counts'] = self::isMostlyTextBasedOnUniqueColors($interventionImage);
|
$image['color_counts'] = self::isMostlyTextBasedOnUniqueColors($interventionImage);
|
||||||
//$image['img'] = $interventionImage;
|
//$image['img'] = $interventionImage;
|
||||||
$costs['count-'.$count] = calculate_smartproxy_cost($sizeKb);
|
$costs['count-'.$count] = calculate_smartproxy_cost($sizeKb, 'rotating_global');
|
||||||
|
|
||||||
$filteredImages[] = $image;
|
$filteredImages[] = $image;
|
||||||
|
|
||||||
@@ -357,7 +358,7 @@ private static function getProductImage(array $jsonLdData, string $proxy, string
|
|||||||
$sizeInKb = strlen($interventionImage->encode()) / 1024; // Convert bytes to kilobytes
|
$sizeInKb = strlen($interventionImage->encode()) / 1024; // Convert bytes to kilobytes
|
||||||
|
|
||||||
// Calculate the cost
|
// Calculate the cost
|
||||||
$cost = calculate_smartproxy_cost($sizeInKb);
|
$cost = calculate_smartproxy_cost($sizeInKb, 'rotating_global');
|
||||||
|
|
||||||
$costs['product_image'] = $cost;
|
$costs['product_image'] = $cost;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user