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;
On May 30, Saskarc donated $5,000 to Bow Valley Villa Senior’s Assisted Living in Oxbow. Bow Valley Villa provides housing for senior citizens who require assisted living.
In addition to providing housing, Bow Valley Villa also provides activities and entertainment for its residents.
“We need Saskarc, because they help the community out a lot,” said Ron Rossow, Chairman of the Bow Valley Villa Board.
Saskarc is proud to support community organizations like Bow Valley Villa that help improve the life of community members.