I have two scripts, one requires my pictures be png, but my uploaders create it as a jpeg. If I try to edit it to make it to where the image is converted into a png, it uploads it as a pure blak file, and it's still a jpeg. Can anyone help me figure out what I did wrong?
Here is a portion of my upload code: (I tried to make them both imagecreatefrompng() and also imagepng(), but still doesn;t work)
$file_name = $pic;
$info = pathinfo($pic);
$img = imagecreatefromjpeg( $pic );
$width = imagesx( $img );
$height = imagesy( $img );
if ($_POST['RadioGroup1'] == 'top') {
$new_width = 400; //New top width
$new_height = 800; //New top height
;} else {
$new_width = 800; //New side width
$new_height = 400; //New side height
;}
$pic = imagecreatetruecolor( $new_width, $new_height );
imagecopyresized( $pic, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
imagejpeg( $pic, "{$resize}{$file_name}" );
OR maybe the answer lies inside my zend upload file.
if (isset($_POST['upload'])) {
require_once('scripts/library.php');
//try {
$destination = '----';
$uploader = new Zend_File_Transfer_Adapter_Http();
$uploader->setDestination($destination);
$filename = $uploader->getFileName(NULL, FALSE);
$uploader->addValidator('Size', FALSE, '10000kB');
$uploader->addValidator('ImageSize', FALSE, array('minheight' => 100, 'minwidth' => 100));
//$pic = $filename;
if (!$uploader->isValid() || $errors) {
$messages = $uploader->getMessages();
} else {
//$pic = $filename;
$no_spaces = str_replace(' ', '_', $filename, $renamed);
$uploader->addValidator('Extension', FALSE, 'gif, png, jpg');
$recognized = FALSE;
if ($uploader->isValid()) {
$recognized = TRUE;
} else {
$mime = $uploader->getMimeType();
$acceptable = array('jpg' => 'image/jpeg',
'png' => 'image/png',
'gif' => 'image/gif');
$key = array_search($mime, $acceptable);
if (!$key) {
$messages[] = 'Unrecognized image type';
} else {
$no_spaces = "$no_spaces.$key";
$recognized = TRUE;
$renamed = TRUE;
}
}
$uploader->clearValidators();
if ($recognized) {
$existing = scandir($destination);
if (in_array($no_spaces, $existing)) {
$dot = strrpos($no_spaces, '.');
$base = substr($no_spaces, 0, $dot);
$extension = substr($no_spaces, $dot);
$i = 1;
do {
$no_spaces = $base . '_' . $i++ . $extension;
} while (in_array($no_spaces, $existing));
$renamed = TRUE;
}
$uploader->addFilter('Rename', array('target' => $no_spaces));
$success = $uploader->receive();
if (!$success) {
$messages = $uploader->getMessages();
} else {
//$pic = $no_spaces;
$uploaded = "$filename uploaded successfully";
$pic = $filename;
if ($renamed) {
$pic = "pictures/uploads/" . $no_spaces;
$uploaded .= " and renamed $no_spaces";
//$pic = $no_spaces;
//$pic = $uploader->getFileName(NULL, FALSE);
} else {$pic = "pictures/uploads/" . $filename;;}
$messages[] = "$uploaded";
//$pic = $no_spaces;