Mr. Print Posted July 23, 2012 Share Posted July 23, 2012 I have an image processing script to upload different types of graphic files. I am able to create an alpha layer png file as well as its thumb for viewing. I can also upload Illustrator and Photoshop files and create a png thumb for viewing, however I have not figured out how to create the Alpha thumb on the Illustrator and Photoshop files, the code below is used to process the thumbs can anyone help with the alpha png thumb from the photoshop and Illustrator files. I'm missing something. Thanks in advance for your time and effort. <?php include_once('classPhpPsdReader.php'); function showUploadError() { echo '<p style="color:red;font-weight:bold;">You have attempted to upload an image that is not a non-progressive JPG, OR the JPG extensions are not enabled in your GD library. You will not be able to use the image that you attempted to upload.</p>'; //non-progressive Jpg now supported } ?> <?php // Finally display the PSD on the screen // Generate thumbnail function makeThumb($file, $thumbnail, $size) { global $message; if(file_exists($file)) { list ($width, $height) = GetImageSize ($file); if ($width > $height) { // Width greater than height $newWidth = $size; $newHeight = ($newWidth * $height) / $width; } else { // Height greater than width $newHeight = $size * .8; $newWidth = ($newHeight * $width) / $height; } // this error suggests that a non JPG was uploaded Progessive JPEG's are now allowed // OR that JPG support is not enabled in PHP, use error to upload PNG file list($width_file, $height_file, $type_file, $attr_file) = getimagesize($file); list($name,$ext_file) = explode('.',$_FILES['image']['name']); $src = @ImageCreateFromJPEG ($file); if ( !$src ) { if($type_file == 3 ){ $src = ImageCreateFromPNG($file); } elseif($type_file == 1 ){ $src = ImageCreateFromGIF($file); }elseif($type_file == 5){ $src = imagecreatefrompsd($file); } $dst = @ImageCreateTrueColor ($newWidth -1, $newHeight -1); imagesavealpha($dst, true); $trans_colour = imagecolorallocatealpha($dst, 0, 0, 0, 127); imagefill($dst, 0, 0, $trans_colour); // needed for transparent thumb in gallery.php $red = imagecolorallocate($dst, 255, 0, 0); imagefilledellipse($dst, 400, 300, 400, 300, $red); // more support is needed for all PNG file types @ImageCopyResized ($dst, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); // and finally, output the result @ImagePNG ($dst, $thumbnail); return true; } else { $dst = @ImageCreateTrueColor ($newWidth -1, $newHeight -1); ImageCopyResized ($dst, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); ImageJPEG ($dst, $thumbnail); return TRUE; } } else { // do something if file doesn't exists //$message= 'Thumbnail could not be created'; return FALSE; } } function addNewImage() { global $message; global $title, $gal_id, $db, $arrUser, $userID, $image_path; $filename = $_FILES['image']['tmp_name']; list($width, $height, $type, $attr) = getimagesize($filename); $filetype = $_FILES['image']['name']; // convert to lowercase for comparison $ext = strtolower(pathinfo($filetype, PATHINFO_EXTENSION)); if ($type == 1){ $type = ".gif"; //$message = "Gif not supported at this time." ; } if ($type == 2){ $type = ".jpg"; } if ($type == 3){ $type = ".png"; } if ($type == 5){ $type = ".psd"; } if ($type == 6){ $type = ".bmp"; $message = "Bitmap images are not supported at this time."; } if ($type == { $type = ".tif"; $message = "Tif Files are not supported at this time."; } if ($type == 13){ $type = ".swf"; $message = "Flash Files are not supported at this time."; } if ($ext == "swf"){ $type = ".".$ext; $message = "Flash Files are not supported at this time."; } if ($ext == "ai"){ $type = ".".$ext; } if ($ext == "eps"){ $type = ".".$ext; $message = "EPS Files are not supported at this time."; } if ($ext == "ait"){ $type = ".".$ext; $message = "Illustrator Template Files are not supported at this time."; } if ($ext == "dwg"){ $message = "AutoCad Drawing Files are not supported at this time."; } if ($ext == "dxf"){ $message = "AutoCad Interchange Files are not supported at this time.";// Have no intentions to support } if ($ext == "emf"){ $message = "Enhance Metafiles are not supported at this time."; } if ($ext == "dwg"){ $message = "AutoCad Drawing Files are not supported at this time.";// Have no intentions to support at this time } if ($ext == "pct"){ $type = ".".$ext; $message = "Macintosh Pic Files are not supported at this time."; } if ($ext == "pdf"){ $type = ".".$ext; $message = "PDF Files are not supported at this time.."; } if ($ext == "svg"){ $type = ".".$ext; $message = "SVG Files are not supported at this time."; } if ($ext == "svgz"){ $type = ".".$ext; $message = "SVG Compressed Files are not supported at this time."; } if ($ext == "tga"){ $message = "Targa Files are not supported at this time."; } if ($ext == "txt"){ $type = ".".$ext; $message = "Text Files are not supported at this time."; } if ($ext == "wmf"){ $message = "Windows Metafiles are not supported at this time."; } if ($type == ""){ // Try and catch all missing file types $message = "You are not permitted to upload this type file."; } if ($message != '') { return; } // create the extension for thumbnails if( $type == ".psd" ) { $type2= ".png"; $typetm="_tm".$type2; $imId = time(); $path = "images/img".$imId.$type2; $path1 = "images/img".$imId.$type; $tm = "images/img".$imId.$typetm; // exec('convert'.$_FILES['image']['tmp_name'].' -flatten '.$path); imagepng(imagecreatefrompsd($_FILES['image']['tmp_name']),$path); move_uploaded_file($_FILES['image']['tmp_name'],$path1); $file = $path; $message = "Your File Successfully Uploaded"; } else if( $type == ".ai" ) { $type2= ".png"; $typetm="_tm".$type2; $imId = time(); $path = "images/img".$imId.$type2; $path1 = "images/img".$imId.$type; $tm = "images/img".$imId.$typetm; exec('convert -density 96 -quality 85 '.$_FILES['image']['tmp_name'].' '.$path); // exec('/usr/bin/convert -density 96 -quality 85 '.$_FILES['image']['tmp_name'].' '.$path); move_uploaded_file($_FILES['image']['tmp_name'],$path1); $file = $path; $message = "Your File Successfully Uploaded"; } else { $typetm="_tm".$type; $imId = time(); $path = "images/img".$imId.$type; $tm = "images/img".$imId.$typetm; $image_path = addslashes($image_path); $title = addslashes($title); $file = $_FILES['image']['tmp_name']; $message = "Your File Successfully Uploaded"; } $fileData = NULL; if ($file) { $fileData = fread(fopen($file, "rb"), filesize($file)); file_put_contents($path, $fileData); $result = makeThumb($file, $tm, 100); if (!$result) { showUploadError(); return FALSE; } } $query = "INSERT INTO ".imageTable." (title, path, thumbnail, gallery_id, user_id, current_path)". " VALUES('$title', '$path', '$tm', $gal_id, $userID, '$image_path')"; $res = $db->query($query); } // END check file types function editImage() { global $title, $im_id, $path, $db, $arrUser, $tm, $userID, $image_path, $_FILES,$_REQUEST; $file = $_FILES['image']['tmp_name']; list($width_file, $height_file, $type_file, $attr_file) = getimagesize($file); //list($name,$ext_file) = explode('.',$_FILES['image']['name']); $src = @ImageCreateFromJPEG ($file); if ( !$src ) { if($type_file == 3 ){ $src = ImageCreateFromPNG($file); } elseif($type_file == 1 ){ $src = ImageCreateFromGIF($file); }elseif($type_file == 5){ $src = imagecreatefrompsd($file); } } $sql = "select * from pcard_image where id ='".$im_id."'"; $result = $db->query($sql); $data2 = $result->fetchRow(DB_FETCHMODE_ASSOC); $image_1 = $data2['path']; //delete this $image_2 = $data2['thumbnail']; //delete this $image_3 = explode("/",$image_1); $image_4 = explode(".",$image_3[1]); $image_5 = $image_4[0]; $psdfile = $image_5.".psd"; $aifile = $image_5.".ai"; @unlink($image_1); @unlink($image_2); if( file_exists("images/".$psdfile)) @unlink("images/".$psdfile); if( file_exists("images/".$aifile)) @unlink("images/".$aifile); $image_path = addslashes($image_path); $title = addslashes($title); $file = $_FILES['image']['tmp_name']; $filename = $_FILES['image']['name']; list($name,$ext_up) = explode('.',$filename); if($ext_up == "psd"){ $type2= ".png"; $typetm="_tm".$type2; $imId = time(); $path5 = "images/img".$imId.$type2; $path1 = "images/img".$imId.$type; $tm = "images/img".$imId.$typetm; $originalfie = "images/img".$imId.".".$ext_up; copy($_FILES['image']['tmp_name'],$originalfie); imagepng(imagecreatefrompsd($_FILES['image']['tmp_name']),$path5); }else if($ext_up == "ai"){ $type2= ".png"; $typetm="_tm".$type2; $imId = time(); $path5 = "images/img".$imId.$type2; $path1 = "images/img".$imId.$type; $tm = "images/img".$imId.$typetm; $originalfie = "images/img".$imId.".".$ext_up; copy($_FILES['image']['tmp_name'],$originalfie); exec('/usr/bin/convert -density 96 -quality 85 '.$_FILES['image']['tmp_name'].' '.$path5); }elseif($file) { if ($file) { $fileData = fread(fopen($file, "rb"), filesize($file)); file_put_contents($path, $fileData); $path5 = $path; //$result = makeThumb($file, $tm, 100); } if (!move_uploaded_file($file, $path)) { die("Some errors occured in uploading image."); } } $result = makeThumb($path5, $tm, 100); if ( !$result ) { showUploadError(); return; } //} // imagejpeg(imagecreatefrompsd($_FILES['image']['tmp_name']),$path); $query = "UPDATE ".imageTable." SET title='$title', path='$path5', thumbnail='$tm', current_path='$image_path'". " WHERE id=$im_id"; $res = $db->query($query); $_SESSION[$im_id] = "Updated Successfully"; } function deleteImage() { global $im_id, $path, $db, $tm; @unlink ($path); @unlink ($tm); $db->query( "DELETE FROM ".imageTable." WHERE id=$im_id" ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/266124-image-processing-photoshopillustrator-to-alpha-png-thumb/ Share on other sites More sharing options...
xyph Posted July 23, 2012 Share Posted July 23, 2012 Try ImageMagick through the CLI convert <filename>.psd -set dispose Background -coalesce <outfilename>.png Quote Link to comment https://forums.phpfreaks.com/topic/266124-image-processing-photoshopillustrator-to-alpha-png-thumb/#findComment-1363782 Share on other sites More sharing options...
Mr. Print Posted July 24, 2012 Author Share Posted July 24, 2012 I'm a little lost here, can you explain a little further. I do have imagemagick installed on the server. Quote Link to comment https://forums.phpfreaks.com/topic/266124-image-processing-photoshopillustrator-to-alpha-png-thumb/#findComment-1363915 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.