Send this to a friend
exercícios sobre pilhas e filas
1 public class exercicio_pilha_fila {
2
3 int topo = 0;
4 int maxPilha = 0;
5 int pilha[] = new int[maxPilha];
6 int comeco = 0;
7 int fim = 0;
8 int total = 0;
9 int maxFila = 0;
10 int[] fila = new int[maxFila];
11
12
13
14
15 public void remove() {
16 if (topo == 0) {
17 System.out.println("Pilha Vazia");
18 } else {
19 int qtde = Leitura.readInteger();
20 if (qtde > topo) {
21 System.out.println("Quantidade: " + (qtde - topo));
22 topo = 0;
23 } else {
24 topo = topo - qtde;
25 }
26 }
27 }
28
29
30
31
32 public void Palavra() {
33 if (topo == 0) {
34 System.out.println("Lista Vazia");
35 } else {
36 int cont = topo - 1;
37 int aux = 0;
38 while ((pilha[aux].equals(pilha[cont])) && (cont > aux)) {
39 cont--;
40 aux++;
41 }
42
43 if (aux > cont) {
44 System.out.println("Palíndroma");
45 } else {
46 System.out.println("Não palíndroma");
47 }
48 }
49 }
50
51
52
53 public void InsereFila() {
54 if (total == maxFila) {
55 System.out.println("fila cheia");
56 } else {
57 if (fim == maxFila) {
58 fim = 0;
59 int tes = Leitura.readInteger(" Digite algo::");
60 fila[fim] = tes;
61 fim++;
62 total++;
63 }
64 }
65 }
66
67
68
69 public void RemovaFila() {
70 if (total == 0) {
71 System.out.println("Fila vazia");
72 } else {
73 if (comeco == maxFila) {
74 comeco = 0;
75 }
76 comeco++;
77 total--;
78 }
79 }
80
81
82
83
84 public void Verifica_Igualdade() {
85 if (total1 != total2) {
86 System.out.println("Tamanhos diferentes");
87 } else {
88 if (com1 != max) {
89 int aux1 = com1;
90 } else {
91 int aux1 = 0;
92 }
93
94 if (com2 != max) {
95 int aux2 = com2;
96 } else {
97 int aux2 = 0;
98 }
99
100 int cont = 0;
101 while ((cont != total1) && (fila1[aux1] == fila2[aux2])) {
102 aux1++;
103 aux2++;
104
105 if (aux1 == max) {
106 aux1 = 0;
107 }
108 if (aux2 == max) {
109 aux2 = 0;
110 }
111 cont++;
112 }
113
114 if (cont == total) {
115 System.out.println("Filas iguais");
116 } else {
117 System.out.println("Filas diferentes");
118 }
119 }
120 }
121
122
123
124
125 public void LocalizaPosicao() {
126 if (total == 0) {
127 System.out.println("Fila vazia");
128 } else {
129 int valor = Leitura.readInteger("Digite valor a ser localizado: ");
130 if (comeco == maxFila) {
131 int aux = 0;
132 } else {
133 int aux = comeco;
134 int cont = 0;
135 while ((cont != total) && (valor != fila[aux])) {
136 aux++;
137 cont++;
138 if (aux == maxFila) {
139 System.out.println("Não encontrado");
140 } else {
141 System.out.println("Encontrado: " + (cont + 1));
142 }
143 }
144 }
145 }
146 }
147
148
149
150
151 public void Multiplica() {
152 int maxFila2 = 0;
153 int comeco2 = 0;
154
155 if (total == 0) {
156 System.out.println("fila vazia");
157 } else {
158 int[] fila3 = new int[total];
159 if (comeco == maxFila) {
160 int aux = 0;
161 } else {
162 int aux = comeco;
163 }
164 if (comeco2 == maxFila2) {
165 int aux2 = 0;
166 } else {
167 int aux2 = comeco2;
168 int cont = 0;
169 while (cont != total) {
170 fila3[fim3] = (fila[aux] * fila2[aux2]);
171 aux++;
172 aux2++;
173 fim3++;
174 total3++;
175 if (aux == maxFila) {
176 aux = 0;
177 }
178 if (aux2 == maxFila) {
179 aux2 = 0;
180 cont++;
181 }
182 }
183 }
184 }
185 }
186
187
188
189 public void Apresenta() {
190 if (total == 0) {
191 System.out.println("Fila vazia");
192 } else {
193 System.out.println("Começo: " + fila[comeco] + " último: " + fila[fim - 1]);
194 }
195 }
196
197
198
199
200 public void RemovePilhaFila() {
201 if ((topo == 0) || (total == 0)) {
202 System.out.println("Fila ou pilha vazias");
203 } else {
204 while ((total > 0) && (topo > 0) && (pilha[topo - 1] == fila[comeco])) {
205 topo--;
206 comeco++;
207 total--;
208
209 if (comeco == maxFila) {
210 comeco = 0;
211 }
212 }
213 }
214 }
215
216
217
218
219
220
221 public void Localiza() {
222 if (comeco1 == max) {
223 int aux1 = 0;
224 } else {
225 int aux1 = comeco1;
226 }
227
228 if (comeco2 == max) {
229 int aux2 = 0;
230 } else {
231 int aux2 = comeco2;
232 }
233
234 int cont1 = 0;
235 int cont2 = 0;
236
237 while (fila1[aux1] != 9783) {
238 cont1++;
239 aux1++;
240 if (aux1 == max) {
241 aux1 = 0;
242 }
243 }
244
245 while (fila2[aux2] != 9783) {
246 cont2++;
247 aux2++;
248 if (aux2 == max) {
249 aux2 = 0;
250 }
251 }
252
253 if (cont1 > cont2) {
254 System.out.println("Fila 1 menor");
255 } else if (cont2 < cont1) {
256 System.out.println ("Fila 2 menor");
257 } else {
258 System.out.println ("Tanto faz");
259 }
260 }
261
262
263
264
265
266 public void PilhaPositiva() {
267 if (topo == 0) {
268 System.out.println("Pilha esta vazia!!");
269 } else {
270 int PilhaN = new Int[(topo/2) + 1];
271 int TopoN = 0;
272
273 while (TopoN > 0) {
274 if (pilha[topo - 1] > 0) {
275 PilhaN[TopoN] = pilha[topo -1];
276 TopoN++;
277 }
278 topo--;
279 }
280 }
281 }
282
283
284
285
286 public void RestaUm() {
287 if (total == 0) {
288 System.out.println("fila vazia");
289 } else {
290 total = 1;
291 comeco = fim - 1;
292 }
293 }
294
295
296
297
298 public void ApresentaTodos() {
299 if (total == 0) {
300 System.out.println("Fila vazia");
301 } else {
302 int aux = comeco;
303 int cont = 0;
304
305 while (cont != total) {
306 if (aux == maxFila) {
307 aux = 0;
308 }
309 System.out.println("Retorno: " + fila[aux]);
310 aux++;
311 cont++;
312 }
313 }
314 }
315
316
317
318
319
320
321
322
323
324
325 public void PreencherPilha() {
326 if (total == maxPilha) {
327 System.out.println("Pilha vazia");
328 } else {
329 int texto = Leitura.readInteger(" Digite algo::");
330
331 while (topo < maxPilha) {
332 pilha[topo] = texto;
333 topo++;
334 }
335 }
336 }
337
338
339
340 public void BackupFilaOutro() {
341 if (total == 0) {
342 System.out.println("Fila vazia");
343 } else {
344 int filaBackup[] = new int[total];
345 int aux = comeco;
346 int totalBackup = 0;
347 int fimBackup = 0;
348
349 while (totalBackup != total) {
350 filaBackup[totalBackup] = fila[aux];
351 totalBackup++;
352 aux++;
353 fimBackup++;
354
355 if (aux == maxFila) {
356 aux = 0;
357 }
358 int comecoBackup = 0;
359 }
360 }
361 }
362
363
364
365
366 public void apresentaFila() {
367 if (total == 0) {
368 System.out.println("Fila vazia");
369 } else {
370 int cont = comeco;
371 int aux = 0;
372
373 while (aux != total) {
374 if (cont == maxFila) {
375 cont = 0;
376 System.out.println("Apresenta Fila" + fila[cont]);
377 cont++;
378 aux++;
379 }
380 }
381 }
382 }
383 }
public class exercicio_pilha_fila {
int topo = 0;
int maxPilha = 0;
int pilha[] = new int[maxPilha];
int comeco = 0;
int fim = 0;
int total = 0;
int maxFila = 0;
int[] fila = new int[maxFila];
public void remove() {
if (topo == 0) {
System.out.println("Pilha Vazia");
} else {
int qtde = Leitura.readInteger();
if (qtde > topo) {
System.out.println("Quantidade: " + (qtde - topo));
topo = 0;
} else {
topo = topo - qtde;
}
}
}
public void Palavra() {
if (topo == 0) {
System.out.println("Lista Vazia");
} else {
int cont = topo - 1;
int aux = 0;
while ((pilha[aux].equals(pilha[cont])) && (cont > aux)) {
cont--;
aux++;
}
if (aux > cont) {
System.out.println("Palíndroma");
} else {
System.out.println("Não palíndroma");
}
}
}
public void InsereFila() {
if (total == maxFila) {
System.out.println("fila cheia");
} else {
if (fim == maxFila) {
fim = 0;
int tes = Leitura.readInteger(" Digite algo::");
fila[fim] = tes;
fim++;
total++;
}
}
}
public void RemovaFila() {
if (total == 0) {
System.out.println("Fila vazia");
} else {
if (comeco == maxFila) {
comeco = 0;
}
comeco++;
total--;
}
}
public void Verifica_Igualdade() {
if (total1 != total2) {
System.out.println("Tamanhos diferentes");
} else {
if (com1 != max) {
int aux1 = com1;
} else {
int aux1 = 0;
}
if (com2 != max) {
int aux2 = com2;
} else {
int aux2 = 0;
}
int cont = 0;
while ((cont != total1) && (fila1[aux1] == fila2[aux2])) {
aux1++;
aux2++;
if (aux1 == max) {
aux1 = 0;
}
if (aux2 == max) {
aux2 = 0;
}
cont++;
}
if (cont == total) {
System.out.println("Filas iguais");
} else {
System.out.println("Filas diferentes");
}
}
}
public void LocalizaPosicao() {
if (total == 0) {
System.out.println("Fila vazia");
} else {
int valor = Leitura.readInteger("Digite valor a ser localizado: ");
if (comeco == maxFila) {
int aux = 0;
} else {
int aux = comeco;
int cont = 0;
while ((cont != total) && (valor != fila[aux])) {
aux++;
cont++;
if (aux == maxFila) {
System.out.println("Não encontrado");
} else {
System.out.println("Encontrado: " + (cont + 1));
}
}
}
}
}
public void Multiplica() {
int maxFila2 = 0;
int comeco2 = 0;
if (total == 0) {
System.out.println("fila vazia");
} else {
int[] fila3 = new int[total];
if (comeco == maxFila) {
int aux = 0;
} else {
int aux = comeco;
}
if (comeco2 == maxFila2) {
int aux2 = 0;
} else {
int aux2 = comeco2;
int cont = 0;
while (cont != total) {
fila3[fim3] = (fila[aux] * fila2[aux2]);
aux++;
aux2++;
fim3++;
total3++;
if (aux == maxFila) {
aux = 0;
}
if (aux2 == maxFila) {
aux2 = 0;
cont++;
}
}
}
}
}
public void Apresenta() {
if (total == 0) {
System.out.println("Fila vazia");
} else {
System.out.println("Começo: " + fila[comeco] + " último: " + fila[fim - 1]);
}
}
public void RemovePilhaFila() {
if ((topo == 0) || (total == 0)) {
System.out.println("Fila ou pilha vazias");
} else {
while ((total > 0) && (topo > 0) && (pilha[topo - 1] == fila[comeco])) {
topo--;
comeco++;
total--;
if (comeco == maxFila) {
comeco = 0;
}
}
}
}
public void Localiza() {
if (comeco1 == max) {
int aux1 = 0;
} else {
int aux1 = comeco1;
}
if (comeco2 == max) {
int aux2 = 0;
} else {
int aux2 = comeco2;
}
int cont1 = 0;
int cont2 = 0;
while (fila1[aux1] != 9783) {
cont1++;
aux1++;
if (aux1 == max) {
aux1 = 0;
}
}
while (fila2[aux2] != 9783) {
cont2++;
aux2++;
if (aux2 == max) {
aux2 = 0;
}
}
if (cont1 > cont2) {
System.out.println("Fila 1 menor");
} else if (cont2 < cont1) {
System.out.println ("Fila 2 menor");
} else {
System.out.println ("Tanto faz");
}
}
public void PilhaPositiva() {
if (topo == 0) {
System.out.println("Pilha esta vazia!!");
} else {
int PilhaN = new Int[(topo/2) + 1];
int TopoN = 0;
while (TopoN > 0) {
if (pilha[topo - 1] > 0) {
PilhaN[TopoN] = pilha[topo -1];
TopoN++;
}
topo--;
}
}
}
public void RestaUm() {
if (total == 0) {
System.out.println("fila vazia");
} else {
total = 1;
comeco = fim - 1;
}
}
public void ApresentaTodos() {
if (total == 0) {
System.out.println("Fila vazia");
} else {
int aux = comeco;
int cont = 0;
while (cont != total) {
if (aux == maxFila) {
aux = 0;
}
System.out.println("Retorno: " + fila[aux]);
aux++;
cont++;
}
}
}
public void PreencherPilha() {
if (total == maxPilha) {
System.out.println("Pilha vazia");
} else {
int texto = Leitura.readInteger(" Digite algo::");
while (topo < maxPilha) {
pilha[topo] = texto;
topo++;
}
}
}
public void BackupFilaOutro() {
if (total == 0) {
System.out.println("Fila vazia");
} else {
int filaBackup[] = new int[total];
int aux = comeco;
int totalBackup = 0;
int fimBackup = 0;
while (totalBackup != total) {
filaBackup[totalBackup] = fila[aux];
totalBackup++;
aux++;
fimBackup++;
if (aux == maxFila) {
aux = 0;
}
int comecoBackup = 0;
}
}
}
public void apresentaFila() {
if (total == 0) {
System.out.println("Fila vazia");
} else {
int cont = comeco;
int aux = 0;
while (aux != total) {
if (cont == maxFila) {
cont = 0;
System.out.println("Apresenta Fila" + fila[cont]);
cont++;
aux++;
}
}
}
}
}
Send this to a friend
1 public class trabalho {
2
3 public static int gerencia_chave(String chave) {
4
5 char[] curinga = chave.toCharArray();
6
7 int min = 256;
8
9 for (int k=0; k<curinga.length; k++) {
10 if ((int) curinga[k] < min) {
11 min = curinga[k];
12 }
13 }
14
15 return min;
16
17 }
18
19 public static String inverte(String string) {
20 int i, len = string.length();
21 StringBuffer dest = new StringBuffer(len);
22
23 for (i = (len - 1); i >= 0; i--){
24 dest.append(string.charAt(i));
25 }
26
27 return dest.toString();
28 }
29
30 public static void criptografa (String string, String chave) {
31
32 char[] lista = string.toCharArray();
33 String holder = "";
34
35 for (int i = 0; i<lista.length; i++){
36
37 int novochar = (int) lista[i] + gerencia_chave(chave) - 65;
38
39 holder += (char) novochar;
40 }
41 System.out.println(string + " = " + inverte(holder));
42 }
43
44 public static void descriptografa (String string, String chave) {
45
46 char[] lista = string.toCharArray();
47 String holder = "";
48
49 for (int i = 0; i<lista.length; i++){
50
51 int novochar = (int) lista[i] - gerencia_chave(chave) + 65;
52
53 holder += (char) novochar;
54 }
55 System.out.println(string + " = " + inverte(holder));
56
57 }
58
59 public static void main(String args[]) {
60
61 criptografa("Computador", "Dinei");
62
63 descriptografa("urgdwxsprF", "Dinei");
64
65 criptografa("Computação", "Dinei");
66
67 descriptografa("ræêdwxsprF", "Dinei");
68
69 criptografa("Programador", "Dinei");
70
71 descriptografa("urgdpdujruS", "Dinei");
72
73 criptografa("Programação", "Dinei");
74
75 descriptografa("ræêdpdujruS", "Dinei");
76
77 criptografa("ABCDEFGHIJKLMNOPQRSTUVWXYZ ÁÉÍÓÚÂÊÃÕ 0123456789 abcdefghijklmnopqrstuvwxyz áéíóúâêãõ", "Dinei");
78 }
79 }
public class trabalho {
public static int gerencia_chave(String chave) {
char[] curinga = chave.toCharArray();
int min = 256;
for (int k=0; k<curinga.length; k++) {
if ((int) curinga[k] < min) {
min = curinga[k];
}
}
return min;
}
public static String inverte(String string) {
int i, len = string.length();
StringBuffer dest = new StringBuffer(len);
for (i = (len - 1); i >= 0; i--){
dest.append(string.charAt(i));
}
return dest.toString();
}
public static void criptografa (String string, String chave) {
char[] lista = string.toCharArray();
String holder = "";
for (int i = 0; i<lista.length; i++){
int novochar = (int) lista[i] + gerencia_chave(chave) - 65;
holder += (char) novochar;
}
System.out.println(string + " = " + inverte(holder));
}
public static void descriptografa (String string, String chave) {
char[] lista = string.toCharArray();
String holder = "";
for (int i = 0; i<lista.length; i++){
int novochar = (int) lista[i] - gerencia_chave(chave) + 65;
holder += (char) novochar;
}
System.out.println(string + " = " + inverte(holder));
}
public static void main(String args[]) {
criptografa("Computador", "Dinei");
descriptografa("urgdwxsprF", "Dinei");
criptografa("Computação", "Dinei");
descriptografa("ræêdwxsprF", "Dinei");
criptografa("Programador", "Dinei");
descriptografa("urgdpdujruS", "Dinei");
criptografa("Programação", "Dinei");
descriptografa("ræêdpdujruS", "Dinei");
criptografa("ABCDEFGHIJKLMNOPQRSTUVWXYZ ÁÉÍÓÚÂÊÃÕ 0123456789 abcdefghijklmnopqrstuvwxyz áéíóúâêãõ", "Dinei");
}
}
Send this to a friend
1 #container {
2 min-height: 500px;
3 }
4 html>body #container {height:auto;height:500px;}
#container {
min-height: 500px;
}
html>body #container {height:auto;height:500px;}
Send this to a friend
1 class Teste
2 def teste
3 "teste"
4 Constant
5 end
6 end
class Teste
def teste
"teste"
Constant
end
end
Send this to a friend
create a link with this:
1 javascript: resizeTo(800,600);
2
3 javascript: resizeTo(1024,768);
javascript: resizeTo(800,600);
javascript: resizeTo(1024,768);
Send this to a friend
1 <?
2
3
4
5
6
7
8
9 function resizeImage( $file, $width = 0, $height = 0, $proportional = false, $output = 'file') {
10 $info = getimagesize($file);
11 $image = '';
12 $final_width = 0;
13 $final_height = 0;
14 list($width_old, $height_old) = $info;
15 if ($proportional) {
16 if ($width == 0) $factor = $height/$height_old;
17 elseif ($height == 0) $factor = $width/$width_old;
18 else $factor = min ( $width / $width_old, $height / $height_old);
19 $final_width = round ($width_old * $factor);
20 $final_height = round ($height_old * $factor);
21 }
22 else {
23 $final_width = ( $width <= 0 ) ? $width_old : $width;
24 $final_height = ( $height <= 0 ) ? $height_old : $height;
25 }
26 switch ( $info[2] ) {
27 case IMAGETYPE_GIF:
28 $image = imagecreatefromgif($file);
29 break;
30 case IMAGETYPE_JPEG:
31 $image = imagecreatefromjpeg($file);
32 break;
33 case IMAGETYPE_PNG:
34 $image = imagecreatefrompng($file);
35 break;
36 default:
37 return false;
38 }
39
40 $image_resized = imagecreatetruecolor( $final_width, $final_height );
41
42 if ( ($info[2] == IMAGETYPE_GIF) || ($info[2] == IMAGETYPE_PNG) ) {
43 $trnprt_indx = imagecolortransparent($image);
44
45 if ($trnprt_indx >= 0) {
46 $trnprt_color = imagecolorsforindex($image, $trnprt_indx);
47 $trnprt_indx = imagecolorallocate($image_resized, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
48 imagefill($image_resized, 0, 0, $trnprt_indx);
49 imagecolortransparent($image_resized, $trnprt_indx);
50 }
51 elseif ($info[2] == IMAGETYPE_PNG) {
52 imagealphablending($image_resized, false);
53 $color = imagecolorallocatealpha($image_resized, 0, 0, 0, 127);
54 imagefill($image_resized, 0, 0, $color);
55 imagesavealpha($image_resized, true);
56 }
57 }
58 imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $final_width, $final_height, $width_old, $height_old);
59
60 switch ( strtolower($output) ) {
61 case 'browser':
62 $mime = image_type_to_mime_type($info[2]);
63 header("Content-type: $mime");
64 $output = NULL;
65 break;
66 case 'file':
67 $output = $file;
68 break;
69 case 'return':
70 return $image_resized;
71 break;
72 default:
73 break;
74 }
75 switch ( $info[2] ) {
76 case IMAGETYPE_GIF:
77 imagegif($image_resized, $output);
78 break;
79 case IMAGETYPE_JPEG:
80 imagejpeg($image_resized, $output);
81 break;
82 case IMAGETYPE_PNG:
83 imagepng($image_resized, $output);
84 break;
85 default:
86 return false;
87 }
88 return true;
89 }
90 ?>
<?
function resizeImage( $file, $width = 0, $height = 0, $proportional = false, $output = 'file') {
$info = getimagesize($file);
$image = '';
$final_width = 0;
$final_height = 0;
list($width_old, $height_old) = $info;
if ($proportional) {
if ($width == 0) $factor = $height/$height_old;
elseif ($height == 0) $factor = $width/$width_old;
else $factor = min ( $width / $width_old, $height / $height_old);
$final_width = round ($width_old * $factor);
$final_height = round ($height_old * $factor);
}
else {
$final_width = ( $width <= 0 ) ? $width_old : $width;
$final_height = ( $height <= 0 ) ? $height_old : $height;
}
switch ( $info[2] ) {
case IMAGETYPE_GIF:
$image = imagecreatefromgif($file);
break;
case IMAGETYPE_JPEG:
$image = imagecreatefromjpeg($file);
break;
case IMAGETYPE_PNG:
$image = imagecreatefrompng($file);
break;
default:
return false;
}
$image_resized = imagecreatetruecolor( $final_width, $final_height );
if ( ($info[2] == IMAGETYPE_GIF) || ($info[2] == IMAGETYPE_PNG) ) {
$trnprt_indx = imagecolortransparent($image);
if ($trnprt_indx >= 0) {
$trnprt_color = imagecolorsforindex($image, $trnprt_indx);
$trnprt_indx = imagecolorallocate($image_resized, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
imagefill($image_resized, 0, 0, $trnprt_indx);
imagecolortransparent($image_resized, $trnprt_indx);
}
elseif ($info[2] == IMAGETYPE_PNG) {
imagealphablending($image_resized, false);
$color = imagecolorallocatealpha($image_resized, 0, 0, 0, 127);
imagefill($image_resized, 0, 0, $color);
imagesavealpha($image_resized, true);
}
}
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $final_width, $final_height, $width_old, $height_old);
switch ( strtolower($output) ) {
case 'browser':
$mime = image_type_to_mime_type($info[2]);
header("Content-type: $mime");
$output = NULL;
break;
case 'file':
$output = $file;
break;
case 'return':
return $image_resized;
break;
default:
break;
}
switch ( $info[2] ) {
case IMAGETYPE_GIF:
imagegif($image_resized, $output);
break;
case IMAGETYPE_JPEG:
imagejpeg($image_resized, $output);
break;
case IMAGETYPE_PNG:
imagepng($image_resized, $output);
break;
default:
return false;
}
return true;
}
?>
Send this to a friend
1 ////////////////////////////////////////////////////////////////////////////////////
2 // generate a croped-image from a picture
3 // source: http://www.seaton-online.com/forum/index.php?showtopic=545
4 // usage: cropImage("300", "225", "test/5.jpg", "jpg", "test/output.jpg");
5 ////////////////////////////////////////////////////////////////////////////////////
6
7 function cropImage($nw, $nh, $source, $stype, $dest) {
8 $size = getimagesize($source);
9 $w = $size[0];
10 $h = $size[1];
11
12 switch($stype) {
13 case 'gif':
14 $simg = imagecreatefromgif($source);
15 break;
16 case 'jpg':
17 $simg = imagecreatefromjpeg($source);
18 break;
19 case 'png':
20 $simg = imagecreatefrompng($source);
21 break;
22 }
23
24 $dimg = imagecreatetruecolor($nw, $nh);
25 $wm = $w/$nw;
26 $hm = $h/$nh;
27 $h_height = $nh/2;
28 $w_height = $nw/2;
29
30 if($w> $h) {
31 $adjusted_width = $w / $hm;
32 $half_width = $adjusted_width / 2;
33 $int_width = $half_width - $w_height;
34 imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
35 } elseif(($w <$h) || ($w == $h)) {
36 $adjusted_height = $h / $wm;
37 $half_height = $adjusted_height / 2;
38 $int_height = $half_height - $h_height;
39 imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h);
40 } else {
41 imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h);
42 }
43
44 imagejpeg($dimg,$dest,80);
45 }
////////////////////////////////////////////////////////////////////////////////////
// generate a croped-image from a picture
// source: http://www.seaton-online.com/forum/index.php?showtopic=545
// usage: cropImage("300", "225", "test/5.jpg", "jpg", "test/output.jpg");
////////////////////////////////////////////////////////////////////////////////////
function cropImage($nw, $nh, $source, $stype, $dest) {
$size = getimagesize($source);
$w = $size[0];
$h = $size[1];
switch($stype) {
case 'gif':
$simg = imagecreatefromgif($source);
break;
case 'jpg':
$simg = imagecreatefromjpeg($source);
break;
case 'png':
$simg = imagecreatefrompng($source);
break;
}
$dimg = imagecreatetruecolor($nw, $nh);
$wm = $w/$nw;
$hm = $h/$nh;
$h_height = $nh/2;
$w_height = $nw/2;
if($w> $h) {
$adjusted_width = $w / $hm;
$half_width = $adjusted_width / 2;
$int_width = $half_width - $w_height;
imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
} elseif(($w <$h) || ($w == $h)) {
$adjusted_height = $h / $wm;
$half_height = $adjusted_height / 2;
$int_height = $half_height - $h_height;
imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h);
} else {
imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h);
}
imagejpeg($dimg,$dest,80);
}
Send this to a friend
1 <?php
2
3 echo "hello kitty";
4
5 ?>
<?php
echo "hello kitty";
?>
Send this to a friend
1 mysqldump --al-databases -u -p > backup.sql
mysqldump --al-databases -u -p > backup.sql
Send this to a friend
by default, dreamhost runs php as cgi.
the follow line switchs from cgi to apache module execution, supporting php_auth.
1 // create a .htaccess with this:
2 AddHandler application/x-httpd-php .php
// create a .htaccess with this:
AddHandler application/x-httpd-php .php