plaatje veranderen
Ik heb een script dat van een pixel van een plaatje van een externe site de kleur van opneemt in red, green, blue (die in de array colortbl staan).
ik wil dat in mijn image, elke pixel die een bepaalde kleur heeft, de kleur krijgt van die ene pixel.
In plaats daarvan maakt hij hele rare dingen.
Hier is een deel code, hier gaat het fout:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
$start = imagecreatefromgif('head-container.gif');
list($widthhc, $heighthc) = getimagesize("head-container.gif");
$w = 1;
$h = 1;
while($w <= $widthc){
while($h <= $heighthc){
$pixel = imagecolorat($start, $w, $h);
$kleur = imagecolorsforindex($start, $pixel);
if($kleur['red'] == 203 AND $kleur['blue'] == 190 AND $kleur['green'] == 151){
$nieuwe_kleur = imagecolorallocate($start, $colortbl['red'], $colortbl['green'], $colortbl['blue']);
imagesetpixel($start, $w, $h, $nieuwe_kleur);
}
$h++;
}
$w++;
}
?>
$start = imagecreatefromgif('head-container.gif');
list($widthhc, $heighthc) = getimagesize("head-container.gif");
$w = 1;
$h = 1;
while($w <= $widthc){
while($h <= $heighthc){
$pixel = imagecolorat($start, $w, $h);
$kleur = imagecolorsforindex($start, $pixel);
if($kleur['red'] == 203 AND $kleur['blue'] == 190 AND $kleur['green'] == 151){
$nieuwe_kleur = imagecolorallocate($start, $colortbl['red'], $colortbl['green'], $colortbl['blue']);
imagesetpixel($start, $w, $h, $nieuwe_kleur);
}
$h++;
}
$w++;
}
?>
Wat doe ik verkeerd? Ik werk nog niet zo lang met images in php namelijk ;)
Gewijzigd op 21/01/2011 15:18:01 door Maestro Roboroads
1.
bij de list heet het: $widthhc
en bij de while loop heet het $widthc
2.
zoals ik nu zie zal de 2de while loop het maar 1 keer doen, dit komt, omdat als de $h eenmaal hoger is dan $heighthc dan, hij ook hoger zal blijven, omdat je de $h niet reset
je moet na:
waarscheinlijk dit neer zetten:
Ik hoop dat het werkt ;)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
002 include('upload_class.php');
003 include('imageresizer.class.php');
004
005 if(isset($_REQUEST['Action']) && $_REQUEST['Action'] == 'UploadNew')
006 {
007
008 mysql_connect("localhost","root","") or die(mysql_error());
009 mysql_select_db("test") or die(mysql_error());
010
011
012
013 for($i = 0; $i < count($_FILES['Comic']['name']); $i++)
014 {
015 //create object that will upload and resize image
016 $UF_obj = new Upload();
017
018 //save image information in db
019 mysql_query("insert into image(ImageName, ImagePath)
020 values(
021 '".$_FILES['Comic']['name'][$i]."',
022 'pictures/')");
023
024 $UF_obj -> File = $_FILES['Comic'];
025 $UF_obj -> SavePath = 'pictures'; // PLACE where you want to save images.
026 $UF_obj -> ThumbPath = 'pictures/thumb'; //if not specify will not create thumbnil
027 $UF_obj -> NewName = $_FILES['Comic']['name'][$i];
028
029 //width and height of large image which will save in "pictures/" folder
030 $UF_obj -> NewWidth = 300;
031 $UF_obj -> NewHeight = 300;
032 ////width and height of thumb image which will save in "pictures/thumb/" folder
033 $UF_obj -> TWidth = 50;
034 $UF_obj -> THeight = 50;
035
036 /*
037 * if you want to name image something other then upload image name then use bellow formate
038 * for example you upload two images then
039 *
040 * $UF_obj -> NewName = array('NewName1.jpg', 'NewName2.jpg');
041 */
042
043 $UF_obj -> NameCase = 'lower'; //default no change. upper for upper case
044 $UF_obj -> OverWrite = true; //default = true. replace existing image
045
046 //UploadFile() function upload and resize image.
047 //function return error message if any.
048 //error variable is in array form. so you can get more then one error/warning messages.
049 // or you can also access error message by class object varialbe like $UF_obj -> Error
050 $Error = $UF_obj -> UploadFile();
051 print_r($Error);
052 if(count($Error) > 0 and is_array($Error))
053 {
054 foreach($Error as $key=>$val)
055 {
056 echo $val . '<br>';
057 }
058 }
059 }//end of for loop
060 }
061
062 ?>
002 include('upload_class.php');
003 include('imageresizer.class.php');
004
005 if(isset($_REQUEST['Action']) && $_REQUEST['Action'] == 'UploadNew')
006 {
007
008 mysql_connect("localhost","root","") or die(mysql_error());
009 mysql_select_db("test") or die(mysql_error());
010
011
012
013 for($i = 0; $i < count($_FILES['Comic']['name']); $i++)
014 {
015 //create object that will upload and resize image
016 $UF_obj = new Upload();
017
018 //save image information in db
019 mysql_query("insert into image(ImageName, ImagePath)
020 values(
021 '".$_FILES['Comic']['name'][$i]."',
022 'pictures/')");
023
024 $UF_obj -> File = $_FILES['Comic'];
025 $UF_obj -> SavePath = 'pictures'; // PLACE where you want to save images.
026 $UF_obj -> ThumbPath = 'pictures/thumb'; //if not specify will not create thumbnil
027 $UF_obj -> NewName = $_FILES['Comic']['name'][$i];
028
029 //width and height of large image which will save in "pictures/" folder
030 $UF_obj -> NewWidth = 300;
031 $UF_obj -> NewHeight = 300;
032 ////width and height of thumb image which will save in "pictures/thumb/" folder
033 $UF_obj -> TWidth = 50;
034 $UF_obj -> THeight = 50;
035
036 /*
037 * if you want to name image something other then upload image name then use bellow formate
038 * for example you upload two images then
039 *
040 * $UF_obj -> NewName = array('NewName1.jpg', 'NewName2.jpg');
041 */
042
043 $UF_obj -> NameCase = 'lower'; //default no change. upper for upper case
044 $UF_obj -> OverWrite = true; //default = true. replace existing image
045
046 //UploadFile() function upload and resize image.
047 //function return error message if any.
048 //error variable is in array form. so you can get more then one error/warning messages.
049 // or you can also access error message by class object varialbe like $UF_obj -> Error
050 $Error = $UF_obj -> UploadFile();
051 print_r($Error);
052 if(count($Error) > 0 and is_array($Error))
053 {
054 foreach($Error as $key=>$val)
055 {
056 echo $val . '<br>';
057 }
058 }
059 }//end of for loop
060 }
061
062 ?>
063 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
064 <html xmlns="http://www.w3.org/1999/xhtml">
065 <head>
066 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
067 <title>Untitled Document</title>
068 </head>
069
070 <body>
071 <form action="" target="_self" method="post" enctype="multipart/form-data">
072 <table border="0" cellpadding="4" cellspacing="0" width="100%">
073 <tr>
074 <td></td>
075 <td></td>
076 </tr>
077 <tr>
078 <td> First Image: </td>
079 <td><input type="file" name="Comic[]" id="Comic" /> </td>
080 </tr>
081 <tr>
082 <td> </td>
083 <td> </td>
084 </tr>
085 <tr>
086 <td> Second Image: </td>
087 <td><input type="file" name="Comic[]" id="Comic" /> </td>
088 </tr>
089 <tr>
090 <td> </td>
091 <td> </td>
092 </tr>
093 <tr>
094 <td colspan="2"><input type="hidden" name="Action" value="UploadNew" />
095 <input type="submit" name="submit" value="Upload" /> </td>
096 </tr>
097 </table>
098 </form>
099 </body>
100 </html>
php script beeldverwerking at sourceforge.com ,PHPKode.com
Gewijzigd op 22/01/2011 10:11:13 door anny php