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

Συζητήσεις για γλώσσες προγραμματισμού και θέματα σχετικά με προγραμματισμό.
Post Reply
User avatar
ARCHON
bit level
bit level
Posts: 30
Joined: Tue Oct 03, 2006 3:09 pm

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

Post by ARCHON » Sun Jan 07, 2007 12:07 am

Το παρακάτω 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: :?:
Q: To be OR to be an Open sourcer..?

A: To be AND to be an Open sourcer..!

That really makes a difference, anyway whenever there is something "wrong" the answer to fix it has to be always logical ;)
User avatar
silegav
Venus Project Founder
Venus Project Founder
Posts: 2098
Joined: Tue Mar 09, 2004 4:03 pm
Academic status: Alumnus/a
Location: The Center of the World -> Piraeus

Post by silegav » Sun Jan 07, 2007 12:19 am

Τι εννοείς να γράφεται πάνω της μια λέξη? Δεν μπορώ να το καταλάβω.
User avatar
ARCHON
bit level
bit level
Posts: 30
Joined: Tue Oct 03, 2006 3:09 pm

Post by ARCHON » Sun Jan 07, 2007 12:26 am

απλά εννοώ στην κάθε εικόνα που κάνουμε 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 .
Q: To be OR to be an Open sourcer..?

A: To be AND to be an Open sourcer..!

That really makes a difference, anyway whenever there is something "wrong" the answer to fix it has to be always logical ;)
User avatar
PaP
Venus Project Founder
Venus Project Founder
Posts: 1077
Joined: Wed Apr 21, 2004 12:06 am
Academic status: Alumnus/a
Location: San Francisco
Contact:

Post by PaP » Sun Jan 07, 2007 7:34 pm

Ψαξε τα ΑΡΙ της PHP ειδικά fopen, fwrite
User avatar
AmmarkoV
Wow! Terabyte level
Wow! Terabyte level
Posts: 2838
Joined: Thu Nov 04, 2004 2:55 pm
Gender:
Location: Reloaded @ Santa Friday
Contact:

Post by AmmarkoV » Mon Jan 08, 2007 1:52 pm

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:
Spoiler: εμφάνιση/απόκρυψη
I would love to change the world, but they won't give me the source code. Οι καθηγητές πληρώνονται από το δημόσιο αρα από όλους τους Έλληνες για να κάνουν τα μαθήματα. Όλοι οι Έλληνες θα έπρεπε να μπορούν να δουν τα μαθήματα τα οποία πληρώνουν! Tο πνευματικό έργο που επιτελείται με τα χρήματα του δημοσίου ΔΕΝ είναι μόνο δικό σας Όποιος δεν δίνει πανελλήνιες έχει δικαίωμα στην γνώση που πληρώνει [url=http://ammar.gr/gddg]gddg blog[/url]
Image
User avatar
ARCHON
bit level
bit level
Posts: 30
Joined: Tue Oct 03, 2006 3:09 pm

Post by ARCHON » Tue Jan 09, 2007 6:15 pm

Καλά απογοητεύτηκα, αν είναι τόσο περίπλοκα τα πράγματα "τας χείρας ουκ είδατε" :razz: :lol: :oops:
Θα ήθελα τότε να ρωτήσω αν γνωρίζετε κάποιο GNU script που να κάνει τη δουλειά που θέλουμε ..? :?: :roll:
Q: To be OR to be an Open sourcer..?

A: To be AND to be an Open sourcer..!

That really makes a difference, anyway whenever there is something "wrong" the answer to fix it has to be always logical ;)
User avatar
AmmarkoV
Wow! Terabyte level
Wow! Terabyte level
Posts: 2838
Joined: Thu Nov 04, 2004 2:55 pm
Gender:
Location: Reloaded @ Santa Friday
Contact:

Post by AmmarkoV » Thu Jan 18, 2007 5:14 pm

Μετά από ψάξιμο ο καλύτερος τρόπος είναι μέσω του PHP GD
http://gr.php.net/gd Njoy ;)
Spoiler: εμφάνιση/απόκρυψη
I would love to change the world, but they won't give me the source code. Οι καθηγητές πληρώνονται από το δημόσιο αρα από όλους τους Έλληνες για να κάνουν τα μαθήματα. Όλοι οι Έλληνες θα έπρεπε να μπορούν να δουν τα μαθήματα τα οποία πληρώνουν! Tο πνευματικό έργο που επιτελείται με τα χρήματα του δημοσίου ΔΕΝ είναι μόνο δικό σας Όποιος δεν δίνει πανελλήνιες έχει δικαίωμα στην γνώση που πληρώνει [url=http://ammar.gr/gddg]gddg blog[/url]
Image
Post Reply

Return to “Προγραμματισμός”