После обрезки изображения он черный. Пожалуйста, помогите мне, если сможете. Почему он сохраняет обратный образ? Какая проблема возникла? Может, мне нужна библиотека изображений? Вот то, что я сделал до сих пор:После обрезки изображения, это черный
<?php
if($_POST['frm'] == 'desktop') {
$file_cnt = $_POST['file'];
$file_size = filesize($file_cnt);
$upload_dir = ABSPATH;
$path = $upload_dir.'wp-content/themes/poster/destop_imag';
define('DIRECTORY', $path);
$img = rand().time().'.jpg';
$upload_pt = $path.'/'.$img;
if(empty($_POST['wl']) && empty($_POST['hl'])) {
//move_uploaded_file($file_cnt, $upload_pt);
$content = file_get_contents($_POST['file']);
file_put_contents(DIRECTORY.'/'.$img.'', $content);
} else {
$targ_w = $_POST['wl']; $targ_h = $_POST['hl'];
$jpeg_quality = 100;
$path_parts = pathinfo($img);
$newfilename = $_SERVER['DOCUMENT_ROOT'].'/poster/wp-content/themes/poster/destop_imag/'.$img;
if ($path_parts['extension'] == 'jpg') {
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagecopyresampled($dst_r,$img_r,0,0,$_POST['xl'],$_POST['yl'],$targ_w,$targ_h,$_POST['wl'],$_POST['hl']);
//header('Content-type: image/jpeg');
imagejpeg($dst_r,$newfilename,$jpeg_quality);
//echo '<script>window.location.href="'.get_page_link(27).'?crop_stat=1"</script>';
//exit;
} elseif ($path_parts['extension'] == 'png') {
$img_r = imagecreatefrompng($src);
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagecopyresampled($dst_r,$img_r,0,0,$_POST['xl'],$_POST['yl'],
$targ_w,$targ_h,$_POST['wl'],$_POST['hl']);
//header('Content-type: image/jpeg');
imagepng($dst_r,$newfilename);
echo '<script>window.location.href="'.get_page_link(27).'?crop_stat=1"</script>';
exit;
} elseif ($path_parts['extension'] == 'gif') {
$img_r = imagecreatefromgif($src);
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagecopyresampled($dst_r,$img_r,0,0,$_POST['xl'],$_POST['yl'],
$targ_w,$targ_h,$_POST['wl'],$_POST['hl']);
//header('Content-type: image/jpeg');
imagegif($dst_r,$newfilename);
echo '<script>window.location.href="'.get_page_link(27).'?crop_stat=1"</script>';
exit;
} else {
echo "Source file is not a supported image file type.";
}
}
}
?>
Javascript
<script type="text/javascript">
$(function(){
$('#cropbox').Jcrop({
aspectRatio: 1,
onSelect: updateCoords,
minSize : [329,329]
});
});
function updateCoords(c)
{
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
function checkCoords()
{
if (parseInt($('#w').val())) return true;
alert('Please select a crop region then press submit.');
return false;
};
</script>