Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compress tool #6

Merged
merged 2 commits into from
Jan 17, 2024
Merged

Compress tool #6

merged 2 commits into from
Jan 17, 2024

Conversation

Hsnmsri
Copy link
Owner

@Hsnmsri Hsnmsri commented Jan 17, 2024

Pull Request Description

Changes Made

  • Added a new function compressImage for compressing and reducing the file size of JPEG and PNG images without significantly lowering the quality.
  • Enhanced the Pixel PHP library to support lossless compression.

Function Details

  • Function Name: compressImage
  • Parameters:
    • imagePath (string): Path or URL to the original image.
    • compressedImagePath (string): Path to save the compressed image.
    • compressionLevel (int): Image compression level (0-100) for JPEG format, compression level (0-9) for PNG format. Default is 9 for PNG.
    • createPathIfNotExists (bool): Optional. Whether to create the directory if it doesn't exist. Default is false.
  • Supported Formats:
    • JPEG (jpg, jpeg)
    • PNG (png)

Usage Example

require_once 'vendor/autoload.php';

use hsnmsri\Pixel;

try {
    // Example: Compress an image and save it to a new file
    Pixel::compressImage('path/to/your/original/image.jpg', 'path/to/your/compressed/image.jpg', 9, true);
    echo 'Image compressed successfully!';
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

@Hsnmsri Hsnmsri merged commit 4363f50 into main Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant