function convert_single_image_to_webp($image_path) {
// Check if the file exists
if (!file_exists($image_path)) {
return "File does not exist: $image_path";
}
// Get the file extension and MIME type
$file_info = getimagesize($image_path);
if (!$file_info) {
return "Invalid image file.";
}
$mime_type = $file_info['mime'];
// Allowed MIME types for conversion
$allowed_mime_types = ['image/jpeg', 'image/png'];
if (!in_array($mime_type, $allowed_mime_types)) {
return "Unsupported file type. Only JPEG and PNG are allowed.";
}
// Load the image based on its MIME type
$image = null;
if ($mime_type === 'image/jpeg') {
$image = imagecreatefromjpeg($image_path);
} elseif ($mime_type === 'image/png') {
$image = imagecreatefrompng($image_path);
}
if (!$image) {
return "Failed to create an image resource.";
}
// Create the WebP file path
$webp_path = $image_path . '.webp';
// Convert to WebP and save the file
if (imagewebp($image, $webp_path)) {
imagedestroy($image); // Free memory
return "Conversion successful. WebP file created at: $webp_path";
} else {
imagedestroy($image); // Free memory
return "Failed to convert the image to WebP.";
}
}
// Example Usage: Replace with the actual file path to test
$image_path = 'https://saskarc.com/en/wp-content/uploads/2024/10/InfraMOD-Banner-2.png'; // Replace with your test image path
$result = convert_single_image_to_webp($image_path);
echo $result;
Georgia Britt accepts a cheque for $10,000 on behalf of South Saskatchewan Flood Aid presented by Kurt Goulden, Fabrication Foreman, Saskarc and Lynne Marr, Director of Manufacturing and Operations, Saskarc.
Saskarc donated a total of $10,000 to the South Saskatchewan Flood Aid on July 23 in support of the communities recently affected by flooding.
These communities are Carnduff, Redvers, Alida, Carievale and Gainsborough.
Proceeds will be evenly distributed among these communities.
The Funds will be given to the EMO of each community to use as needed and this donation will go a long way towards the efforts of these EMOs.
South Sask Flood Aid is formed of a dedicated group of people who came together in support of those in flood affected communities who have lost many possessions and even homes.