Last active
November 25, 2022 10:35
-
-
Save 98percentoats/93dd56b9e167dff5093b4a2525ae40ca to your computer and use it in GitHub Desktop.
Product Configurator - 300 DPI image output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // DO NOT INCLUDE THIS LINE! | |
// Replace the generate_image function in class-ajax.php with this modified function. | |
/** | |
* Generate final image. | |
*/ | |
public static function generate_image() { | |
global $jckpc; | |
$params = self::ajax_img_get_params(); | |
// Set up image space. | |
$canvas_width = $params['images']['background']['full'][1]; | |
$canvas_height = $params['images']['background']['full'][2]; | |
$bg = imagecreatetruecolor( $canvas_width, $canvas_height ); | |
// BEGIN MODIFICATION. | |
// Note: PHP 7.2 or higher must be installed for this to work. | |
if ( function_exists( 'imageresolution' ) ) { | |
imageresolution( $bg, 300, 300 ); | |
} | |
// END MODIFICATION. | |
imagesavealpha( $bg, true ); | |
$trans_colour = imagecolorallocatealpha( $bg, 0, 0, 0, 127 ); | |
imagefill( $bg, 0, 0, $trans_colour ); | |
if ( is_array( $params['images'] ) ) { | |
foreach ( $params['images'] as $index => $image_data ) { | |
if ( empty( $image_data['path'] ) ) { | |
continue; | |
} | |
$img = imagecreatefrompng( $image_data['path'] ); | |
if ( ! $img ) { | |
continue; | |
} | |
imagecopyresized( $bg, $img, 0, 0, 0, 0, $canvas_width, $canvas_height, $canvas_width, $canvas_height ); | |
imagedestroy( $img ); | |
} | |
} | |
// BEGIN MODIFICATION. | |
header( 'Content-Type: image/png; filename="Product_Image-output-merged-.png"' ); | |
// END MODIFICATION. | |
$final_image = imagepng( $bg, $params['imgData']['finalImgPath'] ); | |
if ( $final_image ) { | |
set_transient( $params['imgData']['imgName'], $params['imgData']['finalImgUrl'], $jckpc->settings['general_cache_duration'] * HOUR_IN_SECONDS ); | |
imagepng( $bg ); | |
} | |
die; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment