寄付のパーセンテージに基づいて画像を部分的に色付けしようとしているので、色付きの画像のサブセクションを同等の白黒画像にコピーする方法を見つけたので、任意の画像で小さなプレスメーターを達成できました欲しいです。
<?php
function createPartialGraycaleCopy($post_id, &$image_src_path,&$image_src_filename,&$bw_image_filename,$valor_currente,$objectivo) {
$post_thumbnail_id = get_post_thumbnail_id($post_id);
// Find thumbnail locations
$image_src = wp_get_attachment_image_src($post_thumbnail_id, 'thumbnail');
$image_src_path = dirname($image_src[0]);
$image_src_filename =substr(basename($image_src[0]), 0, strpos(basename($image_src[0]), "?")) ;
// Create greyscale filename
$image_src_extention_loc = (strripos($image_src_filename, '.') - strlen($image_src_filename));
$bw_image_filename = substr($image_src_filename, 0, $image_src_extention_loc) . '_bw' . substr($image_src_filename, $image_src_extention_loc);
// Get the local path of the image
$wpcontent_image_path = dirname(get_attached_file($post_thumbnail_id));
// Create greyscale image
$bw_image = wp_load_image( $wpcontent_image_path . '/' . $image_src_filename);
// Apply greyscale filter
imagefilter($bw_image, IMG_FILTER_GRAYSCALE);
header("Content-Type: image/jpeg");
//Output the newly created image in jpeg format
ImageJpeg($image); // Save the image.
imagejpeg($bw_image,$wpcontent_image_path . '/' . $bw_image_filename, 100);
imagedestroy($bw_image);
partialGrayscale($image_src_path,$image_src_filename,$bw_image_filename,$valor_currente,$objectivo) ;
}
function partialGrayscale ($image_src_path,$image_src_filename,$bw_image_filename,$valor_currente,$objectivo){
// Create image instances
$color = imagecreatefromjpeg($image_src_path . '/' . $image_src_filename);
$saturated = imagecreatefromjpeg($image_src_path . '/' . $bw_image_filename);
$percentagemCompleto=round((100*$valor_currente)/(100-$valor_currente));
$comprimentoSaturado=imagesx($saturated)-(round(imagesx($saturated)*($percentagemCompleto/100)));
$alturaSaturada=imagesy($saturated)-(round(imagesy($saturated)*($percentagemCompleto/100)));
// Greyscale operation
echo imagecopyresampled ($saturated, $color, 0, 0, 0, 0, $comprimentoSaturado, $alturaSaturada,$comprimentoSaturado, $alturaSaturada);
// Save the greyscale image file
header("Content-Type: image/jpeg");
//Output the newly created image in jpeg format
// Save the image.
imagejpeg($saturated,$wpcontent_image_path . '/' . $bw_image_filename, 100);
// Remove original images from memory.
imagedestroy($color);
imagedestroy($saturated);
}
?>
白黒画像はうまく作成できますが、コピー部分はできません。私は何を間違っていますか?これを行うより良い方法はありますか