Page 1 of 1

PHP - Upload images to folder + write some text !? how to ?

Posted: Sun Jan 07, 2007 12:07 am
by ARCHON
Το παρακάτω script ανεβάζει (uploading) εικόνες σε έναν φάκελο μας .
Λειτουργεί μια χαρά, μήπως όμως μπορείτε να με βοηθήσετε να το μετατρέψουμε λίγο έτσι ώστε κάθε φορά που μια εικόνα ανεβαίνει να γράφεται πάνω της μια λέξη, κάποιο κείμενο ..;

Code: Select all

<?
$idir = "images/"; // Path To Images Directory
$tdir = "images/thumbs/"; // Path To Thumbnails Directory
$twidth = "125"; // Maximum Width For Thumbnail Images
$theight = "100"; // Maximum Height For Thumbnail Images

if (!isset($_GET['subpage'])) { // Image Upload Form Below ?>
<form method="post" action="upit.php?subpage=upload" enctype="multipart/form-data">
File:<br />
<input type="file" name="imagefile" class="form">
<br /><br />
<input name="submit" type="submit" value="Sumbit" class="form"> <input type="reset" value="Clear" class="form">
</form>
<? } else if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') { // Uploading/Resizing Script
$filename = $_FILES['imagefile']['name']; // Set $url To Equal The Filename For Later Use
if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {
$file_ext = strrchr($_FILES['imagefile']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php




$copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']); // Move Image From Temporary Location To Permanent Location
if ($copy) { // If The Script Was Able To Copy The Image To It's Permanent Location

print 'Image uploaded successfully.<br />'; // Was Able To Successfully Upload Image

}
} else {
print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is '; // Error Message If Filetype Is Wrong
print $file_ext; // Show The Invalid File's Extention
print '.</font>';
}
} ?>

Περιμένω τις απαντήσεις , ιδεές σας παίδες ! :roll: :?:

Posted: Sun Jan 07, 2007 12:19 am
by silegav
Τι εννοείς να γράφεται πάνω της μια λέξη? Δεν μπορώ να το καταλάβω.

Posted: Sun Jan 07, 2007 12:26 am
by ARCHON
απλά εννοώ στην κάθε εικόνα που κάνουμε upload να προσθέτουμε πάνω της (γράφουμε) μία λέξη !
Π.χ
δές ένα script με χρήση GD,

Code: Select all

<?

// make it or break it
error_reporting(E_ALL);

// the image filename
$filename = '.Image00051.jpg';

// a string to write
$string = "kevin@phpro.org";

// if the image file does exist and we do have GD support we can
// we can write on it.
if(file_exists($filename) && function_exists('imagecreatefromjpeg'))
{
// a string to write
$string = "This is a line of text";
// the font size
$font = 12;
// create the image from the jpeg file
$image = imagecreatefromjpeg($filename);
// set the text color to black
$text_color = imagecolorallocate ($image, 0, 0,0);
// write the text to the image
imagestring ($image, $font, 0, 0, $string, $text_color);
// send the appropriate headers
header('Content-type: image/jpeg');
header('Content-transfer-encoding: binary');
header('Content-length: '.filesize($filename));
// display the image
imagejpeg($image);
// destroy the image
imagedestroy($image);
}
// if the image file does NOT exist and we do have GD support
// we can create the image on the fly
elseif(!file_exists($filename) && function_exists('imagecreatefromjpeg'))
{
// set the appropriate headers
header("Content-type: image/jpg");
// size of the font
$font = 4;
// width of the image
$width = ImageFontWidth($font) * strlen($string);
// height of the image
$height = ImageFontHeight($font);
// create the image
$im = @imagecreate ($width,$height);
// Make the background white
$background_color = imagecolorallocate($im, 255, 255, 255);
// And the text black
$text_color = imagecolorallocate ($im, 0, 0,0);
// write the text on the image
imagestring ($im, $font, 0, 0, $string, $text_color);
// display the image
imagejpeg ($im);

}
else
{
// if we cannot find the image file or we cannot
// create the image on the fly, we simply echo the text
echo $string;
}
?>
'Αν μπορεί κάποιος να "μετατρέψει" λοιπόν κάπως έτσι (ή αλλιώς όπως ξέρει) το 1ο script που αναφέρω πάνω, ώστε να πετυχένουμε και την πρόσθεση κειμένου στην εικόνα που γίνεται upload .

Posted: Sun Jan 07, 2007 7:34 pm
by PaP
Ψαξε τα ΑΡΙ της PHP ειδικά fopen, fwrite

Posted: Mon Jan 08, 2007 1:52 pm
by AmmarkoV
ARCHON δεν είναι όσο απλό μπορεί να νομίζεις..
Να σου πώ αναλυτικά δηλαδή για να καταλάβεις

Θα πρέπει να αποκωδικοποιείς την εικόνα (είτε είναι BMP , GIF , PNG , TIFF , JPG , να συνεχίσω?? ) να κάνεις Set τα Pixels σε κάποιο κομμάτι της έτσι ωστε να φαίνονται σαν γράμματα κάποιου font και μετά να την ξανααποθηκεύεις.. Μετά βάλε και τους 4-5 διαφορετικούς τρόπους για να ανοίξεις την κάθε εικόνα , ανάλογα με την συμπίεση , το βάθος χρώματος αν είναι little ή big endian , αν είναι αποθηκευμένη με τον παραδοσιακό ή όχι τρόπο , μπλά μπλά μπλά , βάλε οτι για κάθε τύπο εικόνας το fileformat έιναι εντελώς διαφορετικό , βάλε και την αποθήκευση που θα χρειαστεί στο τέλος.. Και πήρες μια ιδέα..

Πρέπει να βρείς κάποια έτοιμη βιβλιοθήκη ή κάποιο έτοιμο prog γιατί αλλιώς θα σου πάρει αιώνες (εγγυημένα)..
Ο κώδικας που έδειξες από ότι τον είδα απλά γράφει κάτι πάνω από την φωτογραφία όπως αυτή φαίνεται (όχι στο αρχείο της)..
Και μάλλον δεν θα χρειαστείς κώδικα σκέτο αλλά κώδικα για μια βιβλιοθήκη που θα όλη την χαμαλοδουλεία που έγραψα παραπάνω..

Εγώ μετά από πολύ κούραση έχω φτιάξει BMP /RLE in/out , ICO in/out , PNG in το οποίο δουλεύει μερικές φορές! JPEG in μέσω ενός DLL.. Και για τα υπόλοιπα απλά τα παράτησα..
Καλή τύχη λοιπόν..! :cool:

Posted: Tue Jan 09, 2007 6:15 pm
by ARCHON
Καλά απογοητεύτηκα, αν είναι τόσο περίπλοκα τα πράγματα "τας χείρας ουκ είδατε" :razz: :lol: :oops:
Θα ήθελα τότε να ρωτήσω αν γνωρίζετε κάποιο GNU script που να κάνει τη δουλειά που θέλουμε ..? :?: :roll:

Posted: Thu Jan 18, 2007 5:14 pm
by AmmarkoV
Μετά από ψάξιμο ο καλύτερος τρόπος είναι μέσω του PHP GD
http://gr.php.net/gd Njoy ;)