¡Hola, amigos! I’m Señor FAQ, the mustached maestro of questions and answers! With my trusty glasses and a book of endless wisdom, I turn dudas into solutions. Soy el héroe de los curiosos and the champion of clarity.
JScms_resize_image
The JScms_resize_image
function resizes and optionally crops images while maintaining aspect ratio or applying center cropping. It also supports watermarking.
JScms_resize_image(string $sourcePath, string $targetPath, int $newWidth, int $newHeight, bool $keepRatio = false, ?string $watermarkPath = null, ?int $watermarkPosition = null): bool
$sourcePath
: (string) The path to the source image.$targetPath
: (string) The path to save the resized image.$newWidth
: (int) The desired width of the resized image.$newHeight
: (int) The desired height of the resized image.$keepRatio
: (bool) Optional. Whether to maintain the original aspect ratio. Default is false
.$watermarkPath
: (string|null) Optional. Path to the watermark image. Default is null
.$watermarkPosition
: (int|null) Optional. Position of the watermark based on a 1-9 grid. Default is null
(center).
(bool) Returns true
if the image was resized and saved successfully, or false
otherwise.
<?php
// Resize an image with aspect ratio and watermark
$result = JScms_resize_image(
"/path/to/source.jpg",
"/path/to/target.jpg",
800,
600,
true,
"/path/to/watermark.png",
9
);
if ($result) {
echo "Image resized successfully.";
} else {
echo "Failed to resize image.";
}
?>