/** * Convert some file to an image - places the file in the same place. * Right now just png is supported - other formats could be. * * @param string $orig the path to the file that will be converted * @param string $format the format of the resulting image file * * @return string path of converted file if successful, false if conversion fails */ function convert_to_image($orig, $format = 'png') { if ($format == 'png') { return convert_to_png($orig); } else { trigger_error('Invalid format specificed for convert to image - conversion not performed.'); } return false; }
function draw($pie_id, $base_name, $ext, $args) { if (!in_array($ext, array('png', 'svg'))) { throw new Exception("Selected banner type does not support output extension '{$ext}'"); } // Firstly draw svg. We need it either way $svg_output = draw_svg($pie_id, $base_name, $args); if ($ext == 'svg') { header("Content-type: image/svg+xml;"); readfile($svg_output); exit; } if ($ext == 'png') { $png_output = convert_to_png($svg_output, $base_name); header("Content-type: image/png;"); readfile($png_output); exit; } }
function upload_file($rt_id, $type) { if ($type == 'new_term') { $image_dir = HEURIST_FILESTORE_DIR . 'term-images/'; $dim = 400; } else { $image_dir = HEURIST_ICON_DIR . ($type == 'new_icon' ? '' : 'thumb/th_'); $dim = $type == 'new_icon' ? 16 : 64; } if (!$_FILES[$type]['size']) { return array('', 'Error occurred during upload - file had zero size ' . $type . ' ' . $_FILES[$type]['size']); } $mimeExt = $_FILES[$type]['type']; $filename = $_FILES[$type]['tmp_name']; $origfilename = $_FILES[$type]['name']; $img = null; switch ($mimeExt) { case 'image/jpeg': case 'jpeg': case 'jpg': $img = @imagecreatefromjpeg($filename); break; case 'image/gif': case 'gif': $img = @imagecreatefromgif($filename); break; case 'image/png': case 'png': $img = @imagecreatefrompng($filename); break; default: break; } if (!$img) { return array('', 'Uploaded file is not supported format'); } // check that the image is not mroe than trwice desired size to avoid scaling issues //if (imagesx($img) > ($dim*2) || imagesy($img) > ($dim*2)) return array('','Uploaded file must be no larger than twice '.$dim.' pixels in any direction'); $newfilename = $image_dir . $rt_id . '.png'; // tempnam(sys_get_temp_dir(), 'resized'); $error = convert_to_png($img, $dim, $filename); if ($error) { return array('', $error); } else { if (move_uploaded_file($filename, $newfilename)) { // actually save the file return array('File has been uploaded successfully', ''); } } /* something messed up ... make a note of it and move on */ return array('', "upload file: {$name} couldn't be saved to upload path defined for db = " . HEURIST_DBNAME . " (" . $image_dir . "). Please ask your system administrator to correct the path and/or permissions for this directory"); }
function upload_file($rt_id, $dim) { global $image_dir, $mode; if (!@$_REQUEST['uploading']) { return; } if (!$_FILES['new_icon']['size']) { return array('', 'Error occurred during upload - file had zero size'); } /*****DEBUG****/ //error_log(" file info ".print_r($_FILES,true)); $mimeExt = $_FILES['new_icon']['type']; $filename = $_FILES['new_icon']['tmp_name']; $origfilename = $_FILES['new_icon']['name']; $img = null; switch ($mimeExt) { case 'image/jpeg': case 'jpeg': case 'jpg': $img = @imagecreatefromjpeg($filename); break; case 'image/gif': case 'gif': $img = @imagecreatefromgif($filename); break; case 'image/png': case 'png': $img = @imagecreatefrompng($filename); break; default: break; } if (!$img) { return array('', 'Uploaded file is not supported format'); } // check that the image is not mroe than trwice desired size to avoid scaling issues //if (imagesx($img) > ($dim*2) || imagesy($img) > ($dim*2)) return array('','Uploaded file must be no larger than twice '.$dim.' pixels in any direction'); $newfilename = $image_dir . $rt_id . '.png'; // tempnam('/tmp', 'resized'); $error = convert_to_png($img, $dim, $filename); if ($error) { return array('', $error); } else { if (move_uploaded_file($filename, $newfilename)) { // actually save the file return array('File has been uploaded successfully', ''); } } /* something messed up ... make a note of it and move on */ error_log("upload_file: <{$name}> / <{$tmp_name}> couldn't be saved as <" . $newfilename . ">"); return array('', "upload file: {$name} couldn't be saved to upload path definied for db = " . HEURIST_DBNAME); }
$target_file = "../user_files/user{$ids}/tmp_folder/{$newname}"; $thumbnail = "../user_files/user{$ids}/tmp_folder/{$newname}"; if ($width >= $height) { $wthumb = 680; $hthumb = 680; } else { if ($width <= $height) { $wthumb = 680; $hthumb = 680; } } thumb_img_resize($target_file, $thumbnail, $wthumb, $hthumb, $file_ext); // Convert to PNG $target_file = "../user_files/user{$ids}/tmp_folder/{$newname}"; $newcopy = "../user_files/user{$ids}/tmp_folder/{$newname2}"; convert_to_png($target_file, $newcopy, $file_ext); $image = imagecreatefrompng("../user_files/user{$ids}/tmp_folder/{$newname2}"); ob_start(); imagegif($image); $frames[] = ob_get_contents(); $framed[] = $speed; // Delay in the animation. ob_end_clean(); } } } } } mysql_query("INSERT INTO images (user_id,album_id,upload_date,image_type,ext) VALUES ('{$ids}','{$album_id}',UTC_TIMESTAMP(),'{$type}','gif')"); $image_id = mysql_insert_id(); $mysql_image_array = mysql_query("SELECT id,image_array,album_name FROM albums WHERE id='{$album_id}' LIMIT 1");