From 236baed80dd2ab67be07cbf4a2bb127b2a0e0dc0 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Mon, 29 Jun 2026 12:26:13 -0500 Subject: [PATCH 1/2] refactor: consolidate ImageHelper resize paths, drop unused validate() (#104) - resize() is now a thin wrapper over resizeToSize() (added a $quality param), removing ~80 lines of duplicated crop/resample/encode logic. resize(path) and resizeToSize(path, 1200, 630, '') produce identical output paths/files, so behavior is unchanged. - Removed the unused ImageHelper::validate() method (no callers). Net: -130/+11 lines. Closes the remaining #104 consolidation items. --- .../src/Helper/ImageHelper.php | 141 ++---------------- 1 file changed, 11 insertions(+), 130 deletions(-) diff --git a/source/packages/plg_system_mokoog/src/Helper/ImageHelper.php b/source/packages/plg_system_mokoog/src/Helper/ImageHelper.php index c8f4e65..a443318 100644 --- a/source/packages/plg_system_mokoog/src/Helper/ImageHelper.php +++ b/source/packages/plg_system_mokoog/src/Helper/ImageHelper.php @@ -57,96 +57,8 @@ class ImageHelper int $targetHeight = self::TARGET_HEIGHT, int $quality = self::JPEG_QUALITY ): string { - // Resolve absolute path - $absPath = JPATH_ROOT . '/' . ltrim($imagePath, '/'); - - if (!is_file($absPath)) { - return $imagePath; - } - - $imageInfo = getimagesize($absPath); - - if (!$imageInfo) { - Log::add('MokoOG ImageHelper: Cannot read image dimensions: ' . basename($absPath), Log::WARNING, 'mokoog'); - - return $imagePath; - } - - [$origWidth, $origHeight, $type] = $imageInfo; - - // Skip if already at or below target size - if ($origWidth <= $targetWidth && $origHeight <= $targetHeight) { - return $imagePath; - } - - // Ensure output directory exists - $outputDir = JPATH_ROOT . '/' . self::OUTPUT_DIR; - - if (!is_dir($outputDir) && !Folder::create($outputDir)) { - Log::add('MokoOG ImageHelper: Cannot create output directory: ' . self::OUTPUT_DIR, Log::WARNING, 'mokoog'); - - return $imagePath; - } - - // Generate output filename based on source hash + dimensions - $hash = md5($imagePath . $targetWidth . $targetHeight); - $outputName = $hash . '.jpg'; - $outputPath = $outputDir . '/' . $outputName; - $outputRel = self::OUTPUT_DIR . '/' . $outputName; - - // Skip if already generated - if (is_file($outputPath) && filemtime($outputPath) >= filemtime($absPath)) { - return $outputRel; - } - - // Load source image - $source = self::loadImage($absPath, $type); - - if (!$source) { - return $imagePath; - } - - // Calculate crop dimensions (center crop to target aspect ratio) - $targetRatio = $targetWidth / $targetHeight; - $sourceRatio = $origWidth / $origHeight; - - if ($sourceRatio > $targetRatio) { - // Source is wider — crop sides - $cropHeight = $origHeight; - $cropWidth = (int) round($origHeight * $targetRatio); - $cropX = (int) round(($origWidth - $cropWidth) / 2); - $cropY = 0; - } else { - // Source is taller — crop top/bottom - $cropWidth = $origWidth; - $cropHeight = (int) round($origWidth / $targetRatio); - $cropX = 0; - $cropY = (int) round(($origHeight - $cropHeight) / 2); - } - - // Create output canvas and resample - $output = imagecreatetruecolor($targetWidth, $targetHeight); - - imagecopyresampled( - $output, - $source, - 0, - 0, - $cropX, - $cropY, - $targetWidth, - $targetHeight, - $cropWidth, - $cropHeight - ); - - // Save as JPEG - imagejpeg($output, $outputPath, $quality); - - imagedestroy($source); - imagedestroy($output); - - return $outputRel; + // Thin wrapper over the shared implementation (no subdirectory). + return self::resizeToSize($imagePath, $targetWidth, $targetHeight, '', $quality); } /** @@ -182,11 +94,17 @@ class ImageHelper * @param int $width Target width * @param int $height Target height * @param string $subdir Subdirectory name for output (e.g. platform name) + * @param int $quality JPEG quality 1-100 * * @return string Path to the output image (relative to JPATH_ROOT) */ - private static function resizeToSize(string $imagePath, int $width, int $height, string $subdir = ''): string - { + private static function resizeToSize( + string $imagePath, + int $width, + int $height, + string $subdir = '', + int $quality = self::JPEG_QUALITY + ): string { // Resolve absolute path $absPath = JPATH_ROOT . '/' . ltrim($imagePath, '/'); @@ -272,7 +190,7 @@ class ImageHelper ); // Save as JPEG - imagejpeg($output, $outputPath, self::JPEG_QUALITY); + imagejpeg($output, $outputPath, $quality); imagedestroy($source); imagedestroy($output); @@ -333,43 +251,6 @@ class ImageHelper } } - /** - * Check if an image meets minimum OG size requirements. - * - * @param string $imagePath Image path relative to JPATH_ROOT - * - * @return array{valid: bool, width: int, height: int, message: string} - */ - public static function validate(string $imagePath): array - { - $absPath = JPATH_ROOT . '/' . ltrim($imagePath, '/'); - - if (!is_file($absPath)) { - return ['valid' => false, 'width' => 0, 'height' => 0, 'message' => 'File not found']; - } - - $imageInfo = getimagesize($absPath); - - if (!$imageInfo) { - return ['valid' => false, 'width' => 0, 'height' => 0, 'message' => 'Not a valid image']; - } - - [$width, $height] = $imageInfo; - - // Facebook minimum: 200x200, recommended: 1200x630 - // WhatsApp minimum: 300x200 - if ($width < 200 || $height < 200) { - return [ - 'valid' => false, - 'width' => $width, - 'height' => $height, - 'message' => "Image too small ({$width}x{$height}). Minimum: 200x200px.", - ]; - } - - return ['valid' => true, 'width' => $width, 'height' => $height, 'message' => 'OK']; - } - /** * Load an image resource from a file. * From 3e6c8d685b4f7fe022df178282a0d4f7ede073c4 Mon Sep 17 00:00:00 2001 From: "gitea-actions[bot]" Date: Mon, 29 Jun 2026 17:26:29 +0000 Subject: [PATCH 2/2] chore(version): pre-release bump to 01.07.02-dev [skip ci] --- .mokogitea/workflows/issue-branch.yml | 2 +- CHANGELOG.md | 2 +- CODE_OF_CONDUCT.md | 2 +- GOVERNANCE.md | 2 +- README.md | 2 +- SECURITY.md | 2 +- source/packages/com_mokoog/mokoog.xml | 2 +- source/packages/com_mokoog/sql/updates/mysql/01.07.02.sql | 1 + source/packages/plg_content_mokoog/mokoog.xml | 2 +- source/packages/plg_system_mokoog/mokoog.xml | 2 +- source/packages/plg_webservices_mokoog/mokoog.xml | 2 +- source/pkg_mokoog.xml | 2 +- 12 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 source/packages/com_mokoog/sql/updates/mysql/01.07.02.sql diff --git a/.mokogitea/workflows/issue-branch.yml b/.mokogitea/workflows/issue-branch.yml index 2088785..87e9013 100644 --- a/.mokogitea/workflows/issue-branch.yml +++ b/.mokogitea/workflows/issue-branch.yml @@ -5,7 +5,7 @@ # FILE INFORMATION # DEFGROUP: Gitea.Workflow # INGROUP: mokocli.Automation -# VERSION: 01.07.01 +# VERSION: 01.07.02 # BRIEF: Auto-create feature branch when an issue is opened name: "Universal: Issue Branch" diff --git a/CHANGELOG.md b/CHANGELOG.md index 1516c38..0900035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to MokoSuiteOpenGraph will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - + ## [Unreleased] diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index fa8534a..c93a931 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -14,7 +14,7 @@ DEFGROUP: Template-Joomla INGROUP: Template-Joomla.Documentation REPO: https://github.com/mokoconsulting-tech/Template-Joomla/ - VERSION: 01.07.01 + VERSION: 01.07.02 PATH: ./CODE_OF_CONDUCT.md BRIEF: Community expectations and enforcement guidelines NOTE: Adapted with attribution from the Contributor Covenant v2.1 diff --git a/GOVERNANCE.md b/GOVERNANCE.md index 3ced84f..df0f5ae 100644 --- a/GOVERNANCE.md +++ b/GOVERNANCE.md @@ -19,7 +19,7 @@ DEFGROUP: mokoconsulting-tech.Template-Joomla INGROUP: MokoStandards.Governance REPO: https://github.com/mokoconsulting-tech/Template-Joomla - VERSION: 01.07.01 + VERSION: 01.07.02 PATH: /GOVERNANCE.md BRIEF: Project governance rules, roles, and decision process for Template-Joomla --> diff --git a/README.md b/README.md index 5cfcc4b..b62cb0b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MokoSuiteOpenGraph - + Open Graph, Twitter Card, and social sharing meta tag management for Joomla 6 and higher. diff --git a/SECURITY.md b/SECURITY.md index 69e100d..8b68236 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -23,7 +23,7 @@ DEFGROUP: Template-Joomla INGROUP: Template-Joomla.Documentation REPO: https://git.mokoconsulting.tech/MokoConsulting/Template-Joomla PATH: /SECURITY.md -VERSION: 01.07.01 +VERSION: 01.07.02 BRIEF: Security vulnerability reporting and handling policy --> diff --git a/source/packages/com_mokoog/mokoog.xml b/source/packages/com_mokoog/mokoog.xml index 77c8a14..5f1e114 100644 --- a/source/packages/com_mokoog/mokoog.xml +++ b/source/packages/com_mokoog/mokoog.xml @@ -8,7 +8,7 @@ --> com_mokoog - 01.07.01 + 01.07.02 2026-05-23 Moko Consulting hello@mokoconsulting.tech diff --git a/source/packages/com_mokoog/sql/updates/mysql/01.07.02.sql b/source/packages/com_mokoog/sql/updates/mysql/01.07.02.sql new file mode 100644 index 0000000..393d9b9 --- /dev/null +++ b/source/packages/com_mokoog/sql/updates/mysql/01.07.02.sql @@ -0,0 +1 @@ +/* 01.07.02 — no schema changes */ diff --git a/source/packages/plg_content_mokoog/mokoog.xml b/source/packages/plg_content_mokoog/mokoog.xml index 31db221..26afaa1 100644 --- a/source/packages/plg_content_mokoog/mokoog.xml +++ b/source/packages/plg_content_mokoog/mokoog.xml @@ -8,7 +8,7 @@ --> Content - MokoSuiteOpenGraph - 01.07.01 + 01.07.02 2026-05-23 Moko Consulting hello@mokoconsulting.tech diff --git a/source/packages/plg_system_mokoog/mokoog.xml b/source/packages/plg_system_mokoog/mokoog.xml index 76a7cee..535c625 100644 --- a/source/packages/plg_system_mokoog/mokoog.xml +++ b/source/packages/plg_system_mokoog/mokoog.xml @@ -8,7 +8,7 @@ --> System - MokoSuiteOpenGraph - 01.07.01 + 01.07.02 2026-05-23 Moko Consulting hello@mokoconsulting.tech diff --git a/source/packages/plg_webservices_mokoog/mokoog.xml b/source/packages/plg_webservices_mokoog/mokoog.xml index 970d8c2..333dbd1 100644 --- a/source/packages/plg_webservices_mokoog/mokoog.xml +++ b/source/packages/plg_webservices_mokoog/mokoog.xml @@ -8,7 +8,7 @@ --> Web Services - MokoSuiteOpenGraph - 01.07.01 + 01.07.02 2026-05-23 Moko Consulting hello@mokoconsulting.tech diff --git a/source/pkg_mokoog.xml b/source/pkg_mokoog.xml index 29101eb..6746daf 100644 --- a/source/pkg_mokoog.xml +++ b/source/pkg_mokoog.xml @@ -8,7 +8,7 @@ Package - MokoSuiteOpenGraph mokoog - 01.07.01 + 01.07.02 2026-05-23 Moko Consulting hello@mokoconsulting.tech