����JFIFXX�����    $.' ",#(7),01444'9=82<.342  2!!22222222222222222222222222222222222222222222222222����"��4�� ���,�PG"Z_�4�˷����kjز�Z�,F+��_z�,�© �����zh6�٨�ic�fu���#ډb���_�N�?��wQ���5-�~�I���8����TK<5o�Iv-�����k�_U_�����~b�M��d����Ӝ�U�Hh��?]��E�w��Q���k�{��_}qFW7HTՑ��Y��F�?_�'ϔ��_�Ջt��=||I ��6�έ"�����D���/[�k�9���Y�8ds|\���Ҿp6�Ҵ���]��.����6�z<�v��@]�i%��$j��~�g��J>��no����pM[me�i$[����s�o�ᘨ�˸ nɜG-�ĨU�ycP�3.DB�li�;��hj���x7Z^�N�h������N3u{�:j�x�힞��#M&��jL P@_���� P��&��o8������9�����@Sz6�t7#O�ߋ �s}Yf�T���lmr����Z)'N��k�۞p����w\�Tȯ?�8`�O��i{wﭹW�[�r�� ��Q4F�׊���3m&L�=��h3����z~��#�\�l :�F,j@�� ʱ�wQT����8�"kJO���6�֚l����}���R�>ډK���]��y����&����p�}b��;N�1�m�r$�|��7�>e�@B�TM*-iH��g�D�)� E�m�|�ؘbҗ�a��Ҿ����t4���o���G��*oCN�rP���Q��@z,|?W[0�����:�n,jWiE��W��$~/�hp\��?��{(�0���+�Y8rΟ�+����>S-S����VN;�}�s?.����� w�9��˟<���Mq4�Wv'��{)0�1mB��V����W[�����8�/<� �%���wT^�5���b��)iM� pg�N�&ݝ��VO~�q���u���9� ����!��J27����$O-���! �:�%H��� ـ����y�ΠM=t{!S�� oK8������t<����è:a������[�����ա�H���~��w��Qz`�po�^ ����Q��n� �,uu�C�$ ^���,������8�#��:�6��e�|~���!�3�3.�\0��q��o�4`.|� ����y�Q�`~;�d�ׯ,��O�Zw�������`73�v�܋�<���Ȏ�� ـ4k��5�K�a�u�=9Yd��$>x�A�&�� j0� ���vF��� Y�|�y��� ~�6�@c��1vOp�Ig����4��l�OD���L����� R���c���j�_�uX6��3?nk��Wy�f;^*B� ��@�~a�`��Eu������+���6�L��.ü>��}y���}_�O�6�͐�:�YrG�X��kG�����l^w���~㒶sy��Iu�!� W ��X��N�7BV��O��!X�2����wvG�R�f�T#�����t�/?���%8�^�W�aT��G�cL�M���I��(J����1~�8�?aT ���]����AS�E��(��*E}� 2��#I/�׍qz��^t�̔���b�Yz4x���t�){ OH��+(E��A&�N�������XT��o��"�XC��'���)}�J�z�p� ��~5�}�^����+�6����w��c��Q�|Lp�d�H��}�(�.|����k��c4^�"�����Z?ȕ ��a<�L�!039C� �Eu�C�F�Ew�ç ;�n?�*o���B�8�bʝ���'#Rqf���M}7����]����s2tcS{�\icTx;�\��7K���P���ʇ Z O-��~��c>"��?�������P��E��O�8��@�8��G��Q�g�a�Վ���󁶠�䧘��_%#r�>�1�z�a��eb��qcPѵ��n���#L��� =��׀t� L�7�`��V���A{�C:�g���e@�w1 Xp3�c3�ġ����p��M"'-�@n4���fG��B3�DJ�8[Jo�ߐ���gK)ƛ��$���� ���8�3�����+���� �����6�ʻ���� ���S�kI�*KZlT _`���?��K����QK�d����B`�s}�>���`��*�>��,*@J�d�oF*����弝��O}�k��s��]��y�ߘ��c1G�V���<=�7��7����6�q�PT��tXԀ�!9*4�4Tހ3XΛex�46���Y��D ����� �BdemDa����\�_l,��G�/���֌7���Y�](�xTt^%�GE�����4�}bT���ڹ�����;Y)���B�Q��u��>J/J �⮶.�XԄ��j�ݳ�+E��d ��r�5�_D�1 ��o�� �B�x�΢�#���<��W�����8���R6�@g�M�.��� dr�D��>(otU��@x=��~v���2� ӣ�d�oBd��3�eO�6�㣷�����ݜ6��6Y��Qz`��S��{���\P�~z m5{J/L��1������<�e�ͅPu�b�]�ϔ���'������f�b� Zpw��c`"��i���BD@:)ִ�:�]��hv�E�w���T�l��P���"Ju�}��وV J��G6��. J/�Qgl߭�e�����@�z�Zev2u�)]կ�����7x���s�M�-<ɯ�c��r�v�����@��$�ޮ}lk���a���'����>x��O\�ZFu>�����ck#��&:��`�$�ai�>2Δ����l���oF[h��lE�ܺ�Πk:)���`�� $[6�����9�����kOw�\|���8}������ބ:��񶐕��I�A1/�=�2[�,�!��.}gN#�u����b��� ~��݊��}34q����d�E��Lc��$��"�[q�U�硬g^��%B �z���r�pJ�ru%v\h1Y�ne`ǥ:g���pQM~�^�Xi� ��`S�:V29.�P���V�?B�k�� AEvw%�_�9C�Q����wKekPؠ�\�;Io d�{ ߞo�c1eP����\� `����E=���@K<�Y���eڼ�J���w����{av�F�'�M�@/J��+9p���|]�����Iw &`��8���&M�hg��[�{��Xj��%��Ӓ�$��(����ʹN���<>�I���RY���K2�NPlL�ɀ)��&e����B+ь����( � �JTx���_?EZ� }@ 6�U���뙢ط�z��dWI�n` D����噥�[��uV��"�G&Ú����2g�}&m��?ċ�"����Om#��������� ��{�ON��"S�X��Ne��ysQ���@Fn��Vg���dX�~nj�]J�<�K]:��FW��b�������62�=��5f����JKw��bf�X�55��~J �%^����:�-�QIE��P��v�nZum� z � ~ə ���� ���ة����;�f��\v���g�8�1��f24;�V���ǔ�)����9���1\��c��v�/'Ƞ�w�������$�4�R-��t���� e�6�/�ġ �̕Ecy�J���u�B���<�W�ַ~�w[B1L۲�-JS΂�{���΃������A��20�c#��@ 0!1@AP"#2Q`$3V�%45a6�FRUq��� ����^7ׅ,$n�������+��F�`��2X'��0vM��p�L=������5��8������u�p~���.�`r�����\���O��,ư�0oS ��_�M�����l���4�kv\JSd���x���SW�<��Ae�IX����������$I���w�:S���y���›R��9�Q[���,�5�;�@]�%���u�@ *ro�lbI �� ��+���%m:�͇ZV�����u�̉����θau<�fc�.����{�4Ա� �Q����*�Sm��8\ujqs]{kN���)qO�y�_*dJ�b�7���yQqI&9�ԌK!�M}�R�;������S�T���1���i[U�ɵz�]��U)V�S6���3$K{�ߊ<�(� E]Զ[ǼENg�����'�\?#)Dkf��J���o��v���'�%ƞ�&K�u�!��b�35LX�Ϸ��63$K�a�;�9>,R��W��3�3� d�JeTYE.Mϧ��-�o�j3+y��y^�c�������VO�9NV\nd�1 ��!͕_)a�v;����թ�M�lWR1��)El��P;��yوÏ�u 3�k�5Pr6<�⒲l�!˞*��u־�n�!�l:����UNW ��%��Chx8vL'��X�@��*��)���̮��ˍ��� ���D-M�+J�U�kvK����+�x8��cY������?�Ԡ��~3mo��|�u@[XeY�C�\Kp�x8�oC�C�&����N�~3-H���� ��MX�s�u<`���~"WL��$8ξ��3���a�)|:@�m�\���^�`�@ҷ)�5p+��6���p�%i)P M���ngc�����#0Aruz���RL+xSS?���ʮ}()#�t��mˇ!��0}}y����<�e� �-ή�Ԩ��X������ MF���ԙ~l L.3���}�V뽺�v�����멬��Nl�)�2����^�Iq��a��M��qG��T�����c3#������3U�Ǎ���}��לS�|qa��ڃ�+���-��2�f����/��bz��ڐ�� �ݼ[2�ç����k�X�2�* �Z�d���J�G����M*9W���s{��w���T��x��y,�in�O�v��]���n����P�$�JB@=4�OTI�n��e�22a\����q�d���%�$��(���:���: /*�K[PR�fr\nڙdN���F�n�$�4�[�� U�zƶ����� �mʋ���,�ao�u 3�z� �x��Kn����\[��VFmbE;�_U��&V�Gg�]L�۪&#n%�$ɯ�dG���D�TI=�%+AB�Ru#��b4�1�»x�cs�YzڙJG��f��Il��d�eF'T� iA��T���uC�$����Y��H?����[!G`}���ͪ� �纤Hv\������j�Ex�K���!���OiƸ�Yj�+u-<���'q����uN�*�r\��+�]���<�wOZ.fp�ێ��,-*)V?j-kÊ#�`�r��dV����(�ݽBk�����G�ƛk�QmUڗe��Z���f}|����8�8��a���i��3'J�����~G_�^���d�8w������ R�`(�~�.��u���l�s+g�bv���W���lGc}��u���afE~1�Ue������Z�0�8�=e�� f@/�jqEKQQ�J��oN��J���W5~M>$6�Lt�;$ʳ{���^��6�{����v6���ķܰg�V�cnn �~z�x�«�,2�u�?cE+Ș�H؎�%�Za�)���X>uW�Tz�Nyo����s���FQƤ��$��*�&�LLXL)�1�" L��eO��ɟ�9=���:t��Z���c��Ž���Y?�ӭV�wv�~,Y��r�ۗ�|�y��GaF�����C�����.�+� ���v1���fήJ�����]�S��T��B��n5sW}y�$��~z�'�c ��8 ��� ,! �p��VN�S��N�N�q��y8z˱�A��4��*��'������2n<�s���^ǧ˭P�Jޮɏ�U�G�L�J�*#��<�V��t7�8����TĜ>��i}K%,���)[��z�21z ?�N�i�n1?T�I�R#��m-�����������������1����lA�`��fT5+��ܐ�c�q՝��ʐ��,���3�f2U�եmab��#ŠdQ�y>\��)�SLY����w#��.���ʑ�f��� ,"+�w�~�N�'�c�O�3F�������N<���)j��&��,-� �љ���֊�_�zS���TǦ����w�>��?�������n��U仆�V���e�����0���$�C�d���rP �m�׈e�Xm�Vu� �L��.�bֹ��� �[Դaզ���*��\y�8�Է:�Ez\�0�Kq�C b��̘��cө���Q��=0Y��s�N��S.���3.���O�o:���#���v7�[#߫ ��5�܎�L���Er4���9n��COWlG�^��0k�%<���ZB���aB_���������'=��{i�v�l�$�uC���mƎҝ{�c㱼�y]���W�i ��ߧc��m�H� m�"�"�����;Y�ߝ�Z�Ǔ�����:S#��|}�y�,/k�Ld� TA�(�AI$+I3��;Y*���Z��}|��ӧO��d�v��..#:n��f>�>���ȶI�TX��� 8��y����"d�R�|�)0���=���n4��6ⲑ�+��r<�O�܂~zh�z����7ܓ�HH�Ga롏���nCo�>������a ���~]���R���̲c?�6(�q�;5%� |�uj�~z8R=X��I�V=�|{v�Gj\gc��q����z�؋%M�ߍ����1y��#��@f^���^�>N�����#x#۹��6�Y~�?�dfPO��{��P�4��V��u1E1J �*|���%���JN��`eWu�zk M6���q t[�� ��g�G���v��WIG��u_ft����5�j�"�Y�:T��ɐ���*�;� e5���4����q$C��2d�}���� _S�L#m�Yp��O�.�C�;��c����Hi#֩%+) �Ӎ��ƲV���SYź��g |���tj��3�8���r|���V��1#;.SQ�A[���S������#���`n�+���$��$I �P\[�@�s��(�ED�z���P��])8�G#��0B��[ى��X�II�q<��9�~[Z멜�Z�⊔IWU&A>�P~�#��dp<�?����7���c��'~���5 ��+$���lx@�M�dm��n<=e�dyX��?{�|Aef ,|n3�<~z�ƃ�uۧ�����P��Y,�ӥQ�*g�#먙R�\���;T��i,��[9Qi歉����c>]9�� ��"�c��P�� �Md?٥��If�ت�u��k��/����F��9�c*9��Ǎ:�ØF���z�n*�@|I�ށ9����N3{'��[�'ͬ�Ҳ4��#}��!�V� Fu��,�,mTIk���v C�7v���B�6k�T9��1�*l� '~��ƞF��lU��'�M ����][ΩũJ_�{�i�I�n��$���L�� j��O�dx�����kza۪��#�E��Cl����x˘�o�����V���ɞ�ljr��)�/,�߬h�L��#��^��L�ф�,íMƁe�̩�NB�L�����iL����q�}��(��q��6IçJ$�W�E$��:������=#����(�K�B����zђ <��K(�N�۫K�w��^O{!����)�H���>x�������lx�?>Պ�+�>�W���,Ly!_�D���Ō�l���Q�!�[ �S����J��1��Ɛ�Y}��b,+�Lo�x�ɓ)����=�y�oh�@�꥟/��I��ѭ=��P�y9��� �ۍYӘ�e+�p�Jnϱ?V\SO%�(�t� ���=?MR�[Ș�����d�/ ��n�l��B�7j� ��!�;ӥ�/�[-���A�>�dN�sLj ��,ɪv��=1c�.SQ�O3�U���ƀ�ܽ�E����������̻��9G�ϷD�7(�}��Ävӌ\�y�_0[w ���<΍>����a_��[0+�L��F.�޺��f�>oN�T����q;���y\��bՃ��y�jH�<|q-eɏ�_?_9+P���Hp$�����[ux�K w�Mw��N�ی'$Y2�=��q���KB��P��~������Yul:�[<����F1�2�O���5=d����]Y�sw:���Ϯ���E��j,_Q��X��z`H1,#II ��d�wr��P˂@�ZJV����y$�\y�{}��^~���[:N����ߌ�U�������O��d�����ؾe��${p>G��3c���Ė�lʌ�� ת��[��`ϱ�-W����dg�I��ig2��� ��}s ��ؤ(%#sS@���~���3�X�nRG�~\jc3�v��ӍL��M[JB�T��s3}��j�Nʖ��W����;7��ç?=X�F=-�=����q�ߚ���#���='�c��7���ڑW�I(O+=:uxq�������������e2�zi+�kuG�R��������0�&e�n���iT^J����~\jy���p'dtG��s����O��3����9* �b#Ɋ�� p������[Bws�T�>d4�ۧs���nv�n���U���_�~,�v����ƜJ1��s�� �QIz��)�(lv8M���U=�;����56��G���s#�K���MP�=��LvyGd��}�VwWBF�'�à �?MH�U�g2�� ����!�p�7Q��j��ڴ����=��j�u��� Jn�A s���uM������e��Ɔ�Ҕ�!)'��8Ϣ�ٔ��ޝ(��Vp���צ֖d=�IC�J�Ǡ{q������kԭ�߸���i��@K����u�|�p=..�*+����x�����z[Aqġ#s2a�Ɗ���RR�)*HRsi�~�a &f��M��P����-K�L@��Z��Xy�'x�{}��Zm+���:�)�) IJ�-i�u���� ���ܒH��'�L(7�y�GӜq���� j��� 6ߌg1�g�o���,kر���tY�?W,���p���e���f�OQS��!K�۟cҒA�|ս�j�>��=⬒��˧L[�� �߿2JaB~R��u�:��Q�] �0H~���]�7��Ƽ�I���(}��cq '�ήET���q�?f�ab���ӥvr� �)o��-Q��_'����ᴎo��K������;��V���o��%���~OK ����*��b�f:���-ťIR��`B�5!RB@���ï�� �u �̯e\�_U�_������� g�ES��3�������QT��a����x����U<~�c?�*�#]�MW,[8O�a�x��]�1bC|踤�P��lw5V%�)�{t�<��d��5���0i�XSU��m:��Z�┵�i�"��1�^B�-��P�hJ��&)O��*�D��c�W��vM��)����}���P��ܗ-q����\mmζZ-l@�}��a��E�6��F�@��&Sg@���ݚ�M����� ȹ 4����#p�\H����dYDo�H���"��\��..R�B�H�z_�/5˘����6��KhJR��P�mƶi�m���3�,#c�co��q�a)*Pt����R�m�k�7x�D�E�\Y�閣_X�<���~�)���c[[�BP����6�Yq���S��0����%_����;��Àv�~�| VS؇ ��'O0��F0��\���U�-�d@�����7�SJ*z��3n��y��P����O���������m�~�P�3|Y��ʉr#�C�<�G~�.,! ���bqx���h~0=��!ǫ�jy����l�O,�[B��~��|9��ٱ����Xly�#�i�B��g%�S��������tˋ���e���ې��\[d�t)��.+u�|1 ������#�~Oj����hS�%��i.�~X���I�H�m��0n���c�1uE�q��cF�RF�o���7� �O�ꮧ� ���ۛ{��ʛi5�rw?׌#Qn�TW��~?y$��m\�\o����%W� ?=>S�N@�� �Ʈ���R����N�)�r"C�:��:����� �����#��qb��Y�. �6[��2K����2u�Ǧ�HYR��Q�MV��� �G�$��Q+.>�����nNH��q�^��� ����q��mM��V��D�+�-�#*�U�̒ ���p욳��u:�������IB���m���PV@O���r[b= �� ��1U�E��_Nm�yKbN�O���U�}�the�`�|6֮P>�\2�P�V���I�D�i�P�O;�9�r�mAHG�W�S]��J*�_�G��+kP�2����Ka�Z���H�'K�x�W�MZ%�O�YD�Rc+o��?�q��Ghm��d�S�oh�\�D�|:W������UA�Qc yT�q������~^�H��/��#p�CZ���T�I�1�ӏT����4��"�ČZ�����}��`w�#�*,ʹ�� ��0�i��課�Om�*�da��^gJ݅{���l�e9uF#T�ֲ��̲�ٞC"�q���ߍ ոޑ�o#�XZTp����@ o�8��(jd��xw�]�,f���`~�|,s��^����f�1���t��|��m�򸄭/ctr��5s��7�9Q�4�H1꠲BB@l9@���C�����+�wp�xu�£Yc�9��?`@#�o�mH�s2��)�=��2�.�l����jg�9$�Y�S�%*L������R�Y������7Z���,*=�䷘$�������arm�o�ϰ���UW.|�r�uf����IGw�t����Zwo��~5 ��YյhO+=8fF�)�W�7�L9lM�̘·Y���֘YLf�큹�pRF���99.A �"wz��=E\Z���'a� 2��Ǚ�#;�'}�G���*��l��^"q��+2FQ� hj��kŦ��${���ޮ-�T�٭cf�|�3#~�RJ����t��$b�(R��(����r���dx� >U b�&9,>���%E\� Ά�e�$��'�q't��*�א���ެ�b��-|d���SB�O�O��$�R+�H�)�܎�K��1m`;�J�2�Y~9��O�g8=vqD`K[�F)k�[���1m޼c��n���]s�k�z$@��)!I �x՝"v��9=�ZA=`Ɠi �:�E��)`7��vI��}d�YI�_ �o�:ob���o ���3Q��&D&�2=�� �Ά��;>�h����y.*ⅥS������Ӭ�+q&����j|UƧ����}���J0��WW< ۋS�)jQR�j���Ư��rN)�Gű�4Ѷ(�S)Ǣ�8��i��W52���No˓� ۍ%�5brOn�L�;�n��\G����=�^U�dI���8$�&���h��'���+�(������cȁ߫k�l��S^���cƗjԌE�ꭔ��gF���Ȓ��@���}O���*;e�v�WV���YJ\�]X'5��ղ�k�F��b 6R�o՜m��i N�i����>J����?��lPm�U��}>_Z&�KK��q�r��I�D�Չ~�q�3fL�:S�e>���E���-G���{L�6p�e,8��������QI��h��a�Xa��U�A'���ʂ���s�+טIjP�-��y�8ۈZ?J$��W�P� ��R�s�]��|�l(�ԓ��sƊi��o(��S0��Y� 8�T97.�����WiL��c�~�dxc�E|�2!�X�K�Ƙਫ਼�$((�6�~|d9u+�qd�^3�89��Y�6L�.I�����?���iI�q���9�)O/뚅����O���X��X�V��ZF[�یgQ�L��K1���RҖr@v�#��X�l��F���Нy�S�8�7�kF!A��sM���^rkp�jP�DyS$N���q��nxҍ!U�f�!eh�i�2�m���`�Y�I�9r�6� �TF���C}/�y�^���Η���5d�'��9A-��J��>{�_l+�`��A���[�'��յ�ϛ#w:݅�%��X�}�&�PSt�Q�"�-��\縵�/����$Ɨh�Xb�*�y��BS����;W�ջ_mc�����vt?2}1�;qS�d�d~u:2k5�2�R�~�z+|HE!)�Ǟl��7`��0�<�,�2*���Hl-��x�^����'_TV�gZA�'j� ^�2Ϊ��N7t�����?w�� �x1��f��Iz�C-Ȗ��K�^q�;���-W�DvT�7��8�Z�������� hK�(P:��Q- �8�n�Z���܃e貾�<�1�YT<�,�����"�6{/ �?�͟��|1�:�#g��W�>$����d��J��d�B��=��jf[��%rE^��il:��B���x���Sּ�1հ��,�=��*�7 fcG��#q� �eh?��2�7�����,�!7x��6�n�LC�4x��},Geǝ�tC.��vS �F�43��zz\��;QYC,6����~;RYS/6���|2���5���v��T��i����������mlv��������&� �nRh^ejR�LG�f���? �ۉҬܦƩ��|��Ȱ����>3����!v��i�ʯ�>�v��オ�X3e���_1z�Kȗ\<������!�8���V��]��?b�k41�Re��T�q��mz��TiOʦ�Z��Xq���L������q"+���2ۨ��8}�&N7XU7Ap�d�X��~�׿��&4e�o�F��� �H����O���č�c�� 懴�6���͉��+)��v;j��ݷ�� �UV�� i��� j���Y9GdÒJ1��詞�����V?h��l����l�cGs�ځ�������y�Ac�����\V3�? �� ܙg�>qH�S,�E�W�[�㺨�uch�⍸�O�}���a��>�q�6�n6����N6�q������N ! 1AQaq�0@����"2BRb�#Pr���3C`��Scst���$4D���%Td�� ?���N����a��3��m���C���w��������xA�m�q�m���m������$����4n淿t'��C"w��zU=D�\R+w�p+Y�T�&�պ@��ƃ��3ޯ?�Aﶂ��aŘ���@-�����Q�=���9D��ռ�ѻ@��M�V��P��܅�G5�f�Y<�u=,EC)�<�Fy'�"�&�չ�X~f��l�KԆV��?�� �W�N����=(� �;���{�r����ٌ�Y���h{�١������jW����P���Tc�����X�K�r��}���w�R��%��?���E��m�� �Y�q|����\lEE4���r���}�lsI�Y������f�$�=�d�yO����p�����yBj8jU�o�/�S��?�U��*������ˍ�0������u�q�m [�?f����a�� )Q�>����6#������� ?����0UQ����,IX���(6ڵ[�DI�MNލ�c&���υ�j\��X�R|,4��� j������T�hA�e��^���d���b<����n�� �즇�=!���3�^�`j�h�ȓr��jẕ�c�,ٞX����-����a�ﶔ���#�$��]w�O��Ӫ�1y%��L�Y<�wg#�ǝ�̗`�x�xa�t�w��»1���o7o5��>�m뭛C���Uƃߜ}�C���y1Xνm�F8�jI���]����H���ۺиE@I�i;r�8ӭ����V�F�Շ| ��&?�3|x�B�MuS�Ge�=Ӕ�#BE5G�����Y!z��_e��q�р/W>|-�Ci߇�t�1ޯќd�R3�u��g�=0 5��[?�#͏��q�cf���H��{ ?u�=?�?ǯ���}Z��z���hmΔ�BFTW�����<�q�(v� ��!��z���iW]*�J�V�z��gX֧A�q�&��/w���u�gYӘa���; �i=����g:��?2�dž6�ى�k�4�>�Pxs����}������G�9��3 ���)gG�R<>r h�$��'nc�h�P��Bj��J�ҧH� -��N1���N��?��~��}-q!=��_2hc�M��l�vY%UE�@|�v����M2�.Y[|y�"Eï��K�ZF,�ɯ?,q�?v�M 80jx�"�;�9vk�����+ ֧�� �ȺU��?�%�vcV��mA�6��Qg^M����A}�3�nl� QRN�l8�kkn�'�����(��M�7m9و�q���%ޟ���*h$Zk"��$�9��: �?U8�Sl��,,|ɒ��xH(ѷ����Gn�/Q�4�P��G�%��Ա8�N��!� �&�7�;���eKM7�4��9R/%����l�c>�x;������>��C�:�����t��h?aKX�bhe�ᜋ^�$�Iհ �hr7%F$�E��Fd���t��5���+�(M6�t����Ü�UU|zW�=a�Ts�Tg������dqP�Q����b'�m���1{|Y����X�N��b �P~��F^F:����k6�"�j!�� �I�r�`��1&�-$�Bevk:y���#yw��I0��x��=D�4��tU���P�ZH��ڠ底taP��6����b>�xa����Q�#� WeF��ŮNj�p�J* mQ�N����*I�-*�ȩ�F�g�3 �5��V�ʊ�ɮ�a��5F���O@{���NX��?����H�]3��1�Ri_u��������ѕ�� ����0��� F��~��:60�p�͈�S��qX#a�5>���`�o&+�<2�D����: �������ڝ�$�nP���*)�N�|y�Ej�F�5ټ�e���ihy�Z �>���k�bH�a�v��h�-#���!�Po=@k̆IEN��@��}Ll?j�O������߭�ʞ���Q|A07x���wt!xf���I2?Z��<ץ�T���cU�j��]��陎Ltl �}5�ϓ��$�,��O�mˊ�;�@O��jE��j(�ا,��LX���LO���Ц�90�O �.����a��nA���7������j4 ��W��_ٓ���zW�jcB������y՗+EM�)d���N�g6�y1_x��p�$Lv:��9�"z��p���ʙ$��^��JԼ*�ϭ����o���=x�Lj�6�J��u82�A�H�3$�ٕ@�=Vv�]�'�qEz�;I˼��)��=��ɯ���x �/�W(V���p�����$ �m�������u�����񶤑Oqˎ�T����r��㠚x�sr�GC��byp�G��1ߠ�w e�8�$⿄����/�M{*}��W�]˷.�CK\�ުx���/$�WPw���r� |i���&�}�{�X� �>��$-��l���?-z���g����lΆ���(F���h�vS*���b���߲ڡn,|)mrH[���a�3�ר�[1��3o_�U�3�TC�$��(�=�)0�kgP���� ��u�^=��4 �WYCҸ:��vQ�ר�X�à��tk�m,�t*��^�,�}D*� �"(�I��9R����>`�`��[~Q]�#af��i6l��8���6�:,s�s�N6�j"�A4���IuQ��6E,�GnH��zS�HO�uk�5$�I�4��ؤ�Q9�@��C����wp�BGv[]�u�Ov���0I4���\��y�����Q�Ѹ��~>Z��8�T��a��q�ޣ;z��a���/��S��I:�ܫ_�|������>=Z����8:�S��U�I�J��"IY���8%b8���H��:�QO�6�;7�I�S��J��ҌAά3��>c���E+&jf$eC+�z�;��V����� �r���ʺ������my�e���aQ�f&��6�ND��.:��NT�vm�<- u���ǝ\MvZY�N�NT��-A�>jr!S��n�O 1�3�Ns�%�3D@���`������ܟ 1�^c<���� �a�ɽ�̲�Xë#�w�|y�cW�=�9I*H8�p�^(4���՗�k��arOcW�tO�\�ƍR��8����'�K���I�Q�����?5�>[�}��yU�ײ -h��=��% q�ThG�2�)���"ו3]�!kB��*p�FDl�A���,�eEi�H�f�Ps�����5�H:�Փ~�H�0Dت�D�I����h�F3�������c��2���E��9�H��5�zԑ�ʚ�i�X�=:m�xg�hd(�v����׊�9iS��O��d@0ڽ���:�p�5�h-��t�&���X�q�ӕ,��ie�|���7A�2���O%P��E��htj��Y1��w�Ѓ!����  ���� ࢽ��My�7�\�a�@�ţ�J �4�Ȼ�F�@o�̒?4�wx��)��]�P��~�����u�����5�����7X ��9��^ܩ�U;Iꭆ 5 �������eK2�7(�{|��Y׎ �V��\"���Z�1� Z�����}��(�Ǝ"�1S���_�vE30>���p;� ΝD��%x�W�?W?v����o�^V�i�d��r[��/&>�~`�9Wh��y�;���R��� ;;ɮT��?����r$�g1�K����A��C��c��K��l:�'��3 c�ﳯ*"t8�~l��)���m��+U,z��`(�>yJ�?����h>��]��v��ЍG*�{`��;y]��I�T� ;c��NU�fo¾h���/$���|NS���1�S�"�H��V���T���4��uhǜ�]�v;���5�͠x��'C\�SBpl���h}�N����� A�Bx���%��ޭ�l��/����T��w�ʽ]D�=����K���ž�r㻠l4�S�O?=�k �M:� ��c�C�a�#ha���)�ѐxc�s���gP�iG��{+���x���Q���I= �� z��ԫ+ �8"�k�ñ�j=|����c ��y��CF��/��*9ж�h{ �?4�o� ��k�m�Q�N�x��;�Y��4膚�a�w?�6�>e]�����Q�r�:����g�,i"�����ԩA�*M�<�G��b�if��l^M��5� �Ҩ�{����6J��ZJ�����P�*�����Y���ݛu�_4�9�I8�7���������,^ToR���m4�H��?�N�S�ѕw��/S��甍�@�9H�S�T��t�ƻ���ʒU��*{Xs�@����f�����֒Li�K{H�w^���������Ϥm�tq���s� ���ք��f:��o~s��g�r��ט� �S�ѱC�e]�x���a��) ���(b-$(�j>�7q�B?ӕ�F��hV25r[7 Y� }L�R��}����*sg+��x�r�2�U=�*'WS��ZDW]�WǞ�<��叓���{�$�9Ou4��y�90-�1�'*D`�c�^o?(�9��u���ݐ��'PI&� f�Jݮ�������:wS����jfP1F:X �H�9dԯ���˝[�_54 �}*;@�ܨ�� ð�yn�T���?�ןd�#���4rG�ͨ��H�1�|-#���Mr�S3��G�3�����)�.᧏3v�z֑��r����$G"�`j �1t��x0<Ɔ�Wh6�y�6��,œ�Ga��gA����y��b��)��h�D��ß�_�m��ü �gG;��e�v��ݝ�nQ� ��C����-�*��o���y�a��M��I�>�<���]obD��"�:���G�A��-\%LT�8���c�)��+y76���o�Q�#*{�(F�⽕�y����=���rW�\p���۩�c���A���^e6��K������ʐ�cVf5$�'->���ՉN"���F�"�UQ@�f��Gb~��#�&�M=��8�ט�JNu9��D��[̤�s�o�~������ G��9T�tW^g5y$b��Y'��س�Ǵ�=��U-2 #�MC�t(�i� �lj�@Q 5�̣i�*�O����s�x�K�f��}\��M{E�V�{�υ��Ƈ�����);�H����I��fe�Lȣr�2��>��W�I�Ȃ6������i��k�� �5�YOxȺ����>��Y�f5'��|��H+��98pj�n�.O�y�������jY��~��i�w'������l�;�s�2��Y��:'lg�ꥴ)o#'Sa�a�K��Z� �m��}�`169�n���"���x��I ��*+� }F<��cГ���F�P�������ֹ*�PqX�x۩��,� ��N�� �4<-����%����:��7����W���u�`����� $�?�I��&����o��o��`v�>��P��"��l���4��5'�Z�gE���8���?��[�X�7(��.Q�-��*���ތL@̲����v��.5���[��=�t\+�CNܛ��,g�SQnH����}*F�G16���&:�t��4ُ"A��̣��$�b �|����#rs��a�����T�� ]�<�j��BS�('$�ɻ� �wP;�/�n��?�ݜ��x�F��yUn�~mL*-�������Xf�wd^�a�}��f�,=t�׵i�.2/wpN�Ep8�OР���•��R�FJ� 55TZ��T �ɭ�<��]��/�0�r�@�f��V��V����Nz�G��^���7hZi����k��3�,kN�e|�vg�1{9]_i��X5y7� 8e]�U����'�-2,���e"����]ot�I��Y_��n�(JҼ��1�O ]bXc���Nu�No��pS���Q_���_�?i�~�x h5d'�(qw52] ��'ޤ�q��o1�R!���`ywy�A4u���h<קy���\[~�4�\ X�Wt/� 6�����n�F�a8��f���z �3$�t(���q��q�x��^�XWeN'p<-v�!�{�(>ӽDP7��ո0�y)�e$ٕv�Ih'Q�EA�m*�H��RI��=:��� ���4牢) �%_iN�ݧ�l]� �Nt���G��H�L��� ɱ�g<���1V�,�J~�ٹ�"K��Q�� 9�HS�9�?@��k����r�;we݁�]I�!{ �@�G�[�"��`���J:�n]�{�cA�E����V��ʆ���#��U9�6����j�#Y�m\��q�e4h�B�7��C�������d<�?J����1g:ٳ���=Y���D�p�ц� ׈ǔ��1�]26؜oS�'��9�V�FVu�P�h�9�xc�oq�X��p�o�5��Ա5$�9W�V(�[Ak�aY錎qf;�'�[�|���b�6�Ck��)��#a#a˙��8���=äh�4��2��C��4tm^ �n'c���]GQ$[Wҿ��i���vN�{Fu ��1�gx��1┷���N�m��{j-,��x�� Ūm�ЧS�[�s���Gna���䑴�� x�p 8<������97�Q���ϴ�v�aϚG��Rt�Һ׈�f^\r��WH�JU�7Z���y)�vg=����n��4�_)y��D'y�6�]�c�5̪�\� �PF�k����&�c;��cq�$~T�7j ���nç]�<�g ":�to�t}�159�<�/�8������m�b�K#g'I'.W�����6��I/��>v��\�MN��g���m�A�yQL�4u�Lj�j9��#44�t��l^�}L����n��R��!��t��±]��r��h6ٍ>�yҏ�N��fU�� ���� Fm@�8}�/u��jb9������he:A�y�ծw��GpΧh�5����l}�3p468��)U��d��c����;Us/�֔�YX�1�O2��uq�s��`hwg�r~�{ R��mhN��؎*q 42�*th��>�#���E����#��Hv�O����q�}�����6�e��\�,Wk�#���X��b>��p}�դ��3���T5��†��6��[��@�P�y*n��|'f�֧>�lư΂�̺����SU�'*�q�p�_S�����M�� '��c�6�����m�� ySʨ;M��r���Ƌ�m�Kxo,���Gm�P��A�G�:��i��w�9�}M(�^�V��$ǒ�ѽ�9���|���� �a����J�SQ�a���r�B;����}���ٻ֢�2�%U���c�#�g���N�a�ݕ�'�v�[�OY'��3L�3�;,p�]@�S��{ls��X�'���c�jw�k'a�.��}�}&�� �dP�*�bK=ɍ!����;3n�gΊU�ߴmt�'*{,=SzfD� A��ko~�G�aoq�_mi}#�m�������P�Xhύ����mxǍ�΂���巿zf��Q���c���|kc�����?���W��Y�$���_Lv����l߶��c���`?����l�j�ݲˏ!V��6����U�Ђ(A���4y)H���p�Z_�x��>���e��R��$�/�`^'3qˏ�-&Q�=?��CFVR �D�fV�9��{�8g�������n�h�(P"��6�[�D���< E�����~0<@�`�G�6����Hг�cc�� �c�K.5��D��d�B���`?�XQ��2��ٿyqo&+�1^� DW�0�ꊩ���G�#��Q�nL3��c���������/��x ��1�1[y�x�პCW��C�c�UĨ80�m�e�4.{�m��u���I=��f�����0QRls9���f���������9���~f�����Ǩ��a�"@�8���ȁ�Q����#c�ic������G��$���G���r/$W�(��W���V�"��m�7�[m�A�m����bo��D� j����۳� l���^�k�h׽����� ��#� iXn�v��eT�k�a�^Y�4�BN��ĕ��0 !01@Q"2AaPq3BR������?���@4�Q�����T3,���㺠�W�[=JK�Ϟ���2�r^7��vc�:�9 �E�ߴ�w�S#d���Ix��u��:��Hp��9E!�� V 2;73|F��9Y���*ʬ�F��D����u&���y؟��^EA��A��(ɩ���^��GV:ݜDy�`��Jr29ܾ�㝉��[���E;Fzx��YG��U�e�Y�C���� ����v-tx����I�sם�Ę�q��Eb�+P\ :>�i�C'�;�����k|z�رn�y]�#ǿb��Q��������w�����(�r|ӹs��[�D��2v-%��@;�8<a���[\o[ϧw��I!��*0�krs)�[�J9^��ʜ��p1)� "��/_>��o��<1����A�E�y^�C��`�x1'ܣn�p��s`l���fQ��):�l����b>�Me�jH^?�kl3(�z:���1ŠK&?Q�~�{�ٺ�h�y���/�[��V�|6��}�KbX����mn[-��7�5q�94�������dm���c^���h� X��5��<�eޘ>G���-�}�دB�ޟ� ��|�rt�M��V+�]�c?�-#ڛ��^ǂ}���Lkr���O��u�>�-D�ry� D?:ޞ�U��ǜ�7�V��?瓮�"�#���r��չģVR;�n���/_� ؉v�ݶe5d�b9��/O��009�G���5n�W����JpA�*�r9�>�1��.[t���s�F���nQ� V 77R�]�ɫ8����_0<՜�IF�u(v��4��F�k�3��E)��N:��yڮe��P�`�1}�$WS��J�SQ�N�j�ٺ��޵�#l���ј(�5=��5�lǏmoW�v-�1����v,W�mn��߀$x�<����v�j(����c]��@#��1������Ǔ���o'��u+����;G�#�޸��v-lη��/(`i⣍Pm^���ԯ̾9Z��F��������n��1��� ��]�[��)�'������:�֪�W��FC����� �B9،!?���]��V��A�Վ�M��b�w��G F>_DȬ0¤�#�QR�[V��kz���m�w�"��9ZG�7'[��=�Q����j8R?�zf�\a�=��O�U����*oB�A�|G���2�54 �p��.w7� �� ��&������ξxGHp� B%��$g�����t�Џ򤵍z���HN�u�Я�-�'4��0��;_��3 !01"@AQa2Pq#3BR������?��ʩca��en��^��8���<�u#��m*08r��y�N"�<�Ѳ0��@\�p��� �����Kv�D��J8�Fҽ� �f�Y��-m�ybX�NP����}�!*8t(�OqѢ��Q�wW�K��ZD��Δ^e��!� ��B�K��p~�����e*l}z#9ң�k���q#�Ft�o��S�R����-�w�!�S���Ӥß|M�l޶V��!eˈ�8Y���c�ЮM2��tk���� ������J�fS����Ö*i/2�����n]�k�\���|4yX�8��U�P.���Ы[���l��@"�t�<������5�lF���vU�����W��W��;�b�cД^6[#7@vU�xgZv��F�6��Q,K�v��� �+Ъ��n��Ǣ��Ft���8��0��c�@�!�Zq s�v�t�;#](B��-�nῃ~���3g������5�J�%���O������n�kB�ĺ�.r��+���#�N$?�q�/�s�6��p��a����a��J/��M�8��6�ܰ"�*������ɗud"\w���aT(����[��F��U՛����RT�b���n�*��6���O��SJ�.�ij<�v�MT��R\c��5l�sZB>F��<7�;EA��{��E���Ö��1U/�#��d1�a�n.1ě����0�ʾR�h��|�R��Ao�3�m3 ��%�� ���28Q� ��y��φ���H�To�7�lW>����#i`�q���c����a��� �m,B�-j����݋�'mR1Ήt�>��V��p���s�0IbI�C.���1R�ea�����]H�6����������4B>��o��](��$B���m�����a�!=��?�B� K�Ǿ+�Ծ"�n���K��*��+��[T#�{E�J�S����Q�����s�5�:�U�\wĐ�f�3����܆&�)����I���Ԇw��E T�lrTf6Q|R�h:��[K�� �z��c֧�G�C��%\��_�a�84��HcO�bi��ؖV��7H �)*ģK~Xhչ0��4?�0��� �E<���}3���#���u�?�� ��|g�S�6ꊤ�|�I#Hڛ� �ա��w�X��9��7���Ŀ%�SL��y6č��|�F�a 8���b��$�sק�h���b9RAu7�˨p�Č�_\*w��묦��F ����4D~�f����|(�"m���NK��i�S�>�$d7SlA��/�²����SL��|6N�}���S�˯���g��]6��; �#�.��<���q'Q�1|KQ$�����񛩶"�$r�b:���N8�w@��8$�� �AjfG|~�9F ���Y��ʺ��Bwؒ������M:I岎�G��`s�YV5����6��A �b:�W���G�q%l�����F��H���7�������Fsv7��k�� 403WebShell
403Webshell
Server IP : 87.98.231.18  /  Your IP : 216.73.216.50
Web Server : Apache
System : Linux webm007.cluster007.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64
User : amuparnazs ( 799321)
PHP Version : 7.3.33
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/amuparnazs/www/filemanager/include/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/amuparnazs/www/filemanager/include/php_image_magician.php
<?php
# ========================================================================#
#
#  This work is licensed under the Creative Commons Attribution 3.0 Unported
#  License. To view a copy of this license,
#  visit http://creativecommons.org/licenses/by/3.0/ or send a letter to
#  Creative Commons, 444 Castro Street, Suite 900, Mountain View, California,
#  94041, USA.
#
#  All rights reserved.
#
#  Author:    Jarrod Oberto
#  Version:   1.5.1
#  Date:      10-05-11
#  Purpose:   Provide tools for image manipulation using GD
#  Param In:  See functions.
#  Param Out: Produces a resized image
#  Requires : Requires PHP GD library.
#  Usage Example:
#                     include("lib/php_image_magician.php");
#                     $magicianObj = new resize('images/car.jpg');
#                     $magicianObj -> resizeImage(150, 100, 0);
#                     $magicianObj -> saveImage('images/car_small.jpg', 100);
#
#        - See end of doc for more examples -
#
#  Supported file types include: jpg, png, gif, bmp, psd (read)
#
#
#
#  The following functions are taken from phpThumb() [available from
#    http://phpthumb.sourceforge.net], and are used with written permission
#  from James Heinrich.
#    - GD2BMPstring
#      - GetPixelColor
#      - LittleEndian2String
#
#  The following functions are from Marc Hibbins and are used with written
#  permission (are also under the Attribution-ShareAlike
#  [http://creativecommons.org/licenses/by-sa/3.0/] license.
#    -
#
#  PhpPsdReader is used with written permission from Tim de Koning.
#  [http://www.kingsquare.nl/phppsdreader]
#
#
#
#  Modificatoin history
#  Date      Initials  Ver Description
#  10-05-11  J.C.O   0.0 Initial build
#  01-06-11  J.C.O   0.1.1   * Added reflections
#              * Added Rounded corners
#              * You can now use PNG interlacing
#              * Added shadow
#              * Added caption box
#              * Added vintage filter
#              * Added dynamic image resizing (resize on the fly)
#              * minor bug fixes
#  05-06-11  J.C.O   0.1.1.1 * Fixed undefined variables
#  17-06-11  J.C.O   0.1.2   * Added image_batch_class.php class
#              * Minor bug fixes
#  26-07-11  J.C.O   0.1.4 * Added support for external images
#              * Can now set the crop poisition
#  03-08-11  J.C.O   0.1.5 * Added reset() method to reset resource to
#                original input file.
#              * Added method addTextToCaptionBox() to
#                simplify adding text to a caption box.
#              * Added experimental writeIPTC. (not finished)
#              * Added experimental readIPTC. (not finished)
#  11-08-11  J.C.O     * Added initial border presets.
#  30-08-11  J.C.O     * Added 'auto' crop option to crop portrait
#                images near the top.
#  08-09-11  J.C.O     * Added cropImage() method to allow standalone
#                cropping.
#  17-09-11  J.C.O     * Added setCropFromTop() set method - set the
#                percentage to crop from the top when using
#                crop 'auto' option.
#              * Added setTransparency() set method - allows you
#                to turn transparency off (like when saving
#                as a jpg).
#              * Added setFillColor() set method - set the
#                background color to use instead of transparency.
#  05-11-11  J.C.O   0.1.5.1 * Fixed interlacing option
#  0-07-12  J.C.O   1.0
#
#  Known issues & Limitations:
# -------------------------------
#  Not so much an issue, the image is destroyed on the deconstruct rather than
#  when we have finished with it. The reason for this is that we don't know
#  when we're finished with it as you can both save the image and display
#  it directly to the screen (imagedestroy($this->imageResized))
#
#  Opening BMP files is slow. A test with 884 bmp files processed in a loop
#  takes forever - over 5 min. This test inlcuded opening the file, then
#  getting and displaying its width and height.
#
#  $forceStretch:
# -------------------------------
#  On by default.
#  $forceStretch can be disabled by calling method setForceStretch with false
#  parameter. If disabled, if an images original size is smaller than the size
#  specified by the user, the original size will be used. This is useful when
#  dealing with small images.
#
#  If enabled, images smaller than the size specified will be stretched to
#  that size.
#
#  Tips:
# -------------------------------
#  * If you're resizing a transparent png and saving it as a jpg, set
#  $keepTransparency to false with: $magicianObj->setTransparency(false);
#
#  FEATURES:
#    * EASY TO USE
#    * BMP SUPPORT (read & write)
#    * PSD (photoshop) support (read)
#    * RESIZE IMAGES
#      - Preserve transparency (png, gif)
#      - Apply sharpening (jpg) (requires PHP >= 5.1.0)
#      - Set image quality (jpg, png)
#      - Resize modes:
#        - exact size
#        - resize by width (auto height)
#        - resize by height (auto width)
#        - auto (automatically determine the best of the above modes to use)
#        - crop - resize as best as it can then crop the rest
#      - Force stretching of smaller images (upscale)
#    * APPLY FILTERS
#      - Convert to grey scale
#      - Convert to black and white
#      - Convert to sepia
#      - Convert to negative
#    * ROTATE IMAGES
#      - Rotate using predefined "left", "right", or "180"; or any custom degree amount
#    * EXTRACT EXIF DATA (requires exif module)
#      - make
#      - model
#      - date
#      - exposure
#      - aperture
#      - f-stop
#      - iso
#      - focal length
#      - exposure program
#      - metering mode
#      - flash status
#      - creator
#      - copyright
#    * ADD WATERMARK
#      - Specify exact x, y placement
#      - Or, specify using one of the 9 pre-defined placements such as "tl"
#        (for top left), "m" (for middle), "br" (for bottom right)
#        - also specify padding from edge amount (optional).
#      - Set opacity of watermark (png).
#    * ADD BORDER
#    * USE HEX WHEN SPECIFYING COLORS (eg: #ffffff)
#    * SAVE IMAGE OR OUTPUT TO SCREEN
#
#
# ========================================================================#


class imageLib {

	private   $fileName;
	private   $image;
	protected $imageResized;
	private   $widthOriginal;     # Always be the original width
	private   $heightOriginal;
	private   $width;         # Current width (width after resize)
	private   $height;
	private   $imageSize;
	private   $fileExtension;

	private $debug      = true;
	private $errorArray = array();

	private $forceStretch        = true;
	private $aggresiveSharpening = false;

	private $transparentArray = array( '.png', '.gif' );
	private $keepTransparency = true;
	private $fillColorArray   = array( 'r' => 255, 'g' => 255, 'b' => 255 );

	private $sharpenArray = array( 'jpg' );

	private $psdReaderPath;
	private $filterOverlayPath;

	private $isInterlace;

	private $captionBoxPositionArray = array();

	private $fontDir = 'fonts';

	private $cropFromTopPercent = 10;


## --------------------------------------------------------

	function __construct($fileName)
		# Author:     Jarrod Oberto
		# Date:     27-02-08
		# Purpose:    Constructor
		# Param in:   $fileName: File name and path.
		# Param out:  n/a
		# Reference:
		# Notes:
		#
	{
		if ( ! $this->testGDInstalled())
		{
			if ($this->debug)
			{
				throw new Exception('The GD Library is not installed.');
			}
			else
			{
				throw new Exception();
			}
		};

		$this->initialise();

		// *** Save the image file name. Only store this incase you want to display it
		$this->fileName = $fileName;
		$this->fileExtension = fix_strtolower(strrchr($fileName, '.'));

		// *** Open up the file
		$this->image = $this->openImage($fileName);


		// *** Assign here so we don't modify the original
		$this->imageResized = $this->image;

		// *** If file is an image
		if ($this->testIsImage($this->image))
		{
			// *** Get width and height
			$this->width = imagesx($this->image);
			$this->widthOriginal = imagesx($this->image);
			$this->height = imagesy($this->image);
			$this->heightOriginal = imagesy($this->image);


			/*  Added 15-09-08
         *  Get the filesize using this build in method.
         *  Stores an array of size
         *
         *  $this->imageSize[1] = width
         *  $this->imageSize[2] = height
         *  $this->imageSize[3] = width x height
         *
         */
			$this->imageSize = getimagesize($this->fileName);

		}
		else
		{
			$this->errorArray[] = 'File is not an image';
		}
	}

## --------------------------------------------------------

	private function initialise()
	{

		$this->psdReaderPath = dirname(__FILE__) . '/classPhpPsdReader.php';
		$this->filterOverlayPath = dirname(__FILE__) . '/filters';

		// *** Set if image should be interlaced or not.
		$this->isInterlace = false;
	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Resize
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/


	public function resizeImage($newWidth, $newHeight, $option = 0, $sharpen = false, $autoRotate = false)
		# Author:     Jarrod Oberto
		# Date:       27-02-08
		# Purpose:    Resizes the image
		# Param in:   $newWidth:
		#             $newHeight:
		#             $option:     0 / exact = defined size;
		#                          1 / portrait = keep aspect set height;
		#                          2 / landscape = keep aspect set width;
		#                          3 / auto = auto;
		#                          4 / crop= resize and crop;
		#
		#         $option can also be an array containing options for
		#         cropping. E.G., array('crop', 'r')
		#
		#         This array only applies to 'crop' and the 'r' refers to
		#         "crop right". Other value include; tl, t, tr, l, m (default),
		#         r, bl, b, br, or you can specify your own co-ords (which
		#         isn't recommended.
		#
		#       $sharpen:    true: sharpen (jpg only);
		#                false: don't sharpen
		# Param out:  n/a
		# Reference:
		# Notes:      To clarify the $option input:
		#               0 = The exact height and width dimensions you set.
		#               1 = Whatever height is passed in will be the height that
		#                   is set. The width will be calculated and set automatically
		#                   to a the value that keeps the original aspect ratio.
		#               2 = The same but based on the width. We try make the image the
		#                  biggest size we can while stil fitting inside the box size
		#               3 = Depending whether the image is landscape or portrait, this
		#                   will automatically determine whether to resize via
		#                   dimension 1,2 or 0
		#               4 = Will resize and then crop the image for best fit
		#
		#       forceStretch can be applied to options 1,2,3 and 4
		#
	{

		// *** We can pass in an array of options to change the crop position
		$cropPos = 'm';
		if (is_array($option) && fix_strtolower($option[0]) == 'crop')
		{
			$cropPos = $option[1];         # get the crop option
		}
		else
		{
			if (strpos($option, '-') !== false)
			{
				// *** Or pass in a hyphen seperated option
				$optionPiecesArray = explode('-', $option);
				$cropPos = end($optionPiecesArray);
			}
		}

		// *** Check the option is valid
		$option = $this->prepOption($option);

		// *** Make sure the file passed in is valid
		if ( ! $this->image)
		{
			if ($this->debug)
			{
				throw new Exception('file ' . $this->getFileName() . ' is missing or invalid');
			}
			else
			{
				throw new Exception();
			}
		};

		// *** Get optimal width and height - based on $option
		$dimensionsArray = $this->getDimensions($newWidth, $newHeight, $option);

		$optimalWidth = $dimensionsArray['optimalWidth'];
		$optimalHeight = $dimensionsArray['optimalHeight'];

		// *** Resample - create image canvas of x, y size
		$this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight);
		$this->keepTransparancy($optimalWidth, $optimalHeight, $this->imageResized);
		imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);


		// *** If '4', then crop too
		if ($option == 4 || $option == 'crop')
		{

			if (($optimalWidth >= $newWidth && $optimalHeight >= $newHeight))
			{
				$this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight, $cropPos);
			}
		}

		// *** If Rotate.
		if ($autoRotate)
		{

			$exifData = $this->getExif(false);
			if (count($exifData) > 0)
			{

				switch ($exifData['orientation'])
				{
					case 8:
						$this->imageResized = imagerotate($this->imageResized, 90, 0);
						break;
					case 3:
						$this->imageResized = imagerotate($this->imageResized, 180, 0);
						break;
					case 6:
						$this->imageResized = imagerotate($this->imageResized, -90, 0);
						break;
				}
			}
		}

		// *** Sharpen image (if jpg and the user wishes to do so)
		if ($sharpen && in_array($this->fileExtension, $this->sharpenArray))
		{

			// *** Sharpen
			$this->sharpen();
		}
	}

## --------------------------------------------------------

	public function cropImage($newWidth, $newHeight, $cropPos = 'm')
		# Author:     Jarrod Oberto
		# Date:       08-09-11
		# Purpose:    Crops the image
		# Param in:   $newWidth: crop with
		#             $newHeight: crop height
		#       $cropPos: Can be any of the following:
		#             tl, t, tr, l, m, r, bl, b, br, auto
		#           Or:
		#             a custom position such as '30x50'
		# Param out:  n/a
		# Reference:
		# Notes:
		#
	{

		// *** Make sure the file passed in is valid
		if ( ! $this->image)
		{
			if ($this->debug)
			{
				throw new Exception('file ' . $this->getFileName() . ' is missing or invalid');
			}
			else
			{
				throw new Exception();
			}
		};

		$this->imageResized = $this->image;
		$this->crop($this->width, $this->height, $newWidth, $newHeight, $cropPos);

	}

## --------------------------------------------------------

	private function keepTransparancy($width, $height, $im)
		# Author:     Jarrod Oberto
		# Date:       08-04-11
		# Purpose:    Keep transparency for png and gif image
		# Param in:
		# Param out:  n/a
		# Reference:
		# Notes:
		#
	{
		// *** If PNG, perform some transparency retention actions (gif untested)
		if (in_array($this->fileExtension, $this->transparentArray) && $this->keepTransparency)
		{
			imagealphablending($im, false);
			imagesavealpha($im, true);
			$transparent = imagecolorallocatealpha($im, 255, 255, 255, 127);
			imagefilledrectangle($im, 0, 0, $width, $height, $transparent);
		}
		else
		{
			$color = imagecolorallocate($im, $this->fillColorArray['r'], $this->fillColorArray['g'], $this->fillColorArray['b']);
			imagefilledrectangle($im, 0, 0, $width, $height, $color);
		}
	}

## --------------------------------------------------------

	private function crop($optimalWidth, $optimalHeight, $newWidth, $newHeight, $cropPos)
		# Author:     Jarrod Oberto
		# Date:       15-09-08
		# Purpose:    Crops the image
		# Param in:   $newWidth:
		#             $newHeight:
		# Param out:  n/a
		# Reference:
		# Notes:
		#
	{

		// *** Get cropping co-ordinates
		$cropArray = $this->getCropPlacing($optimalWidth, $optimalHeight, $newWidth, $newHeight, $cropPos);
		$cropStartX = $cropArray['x'];
		$cropStartY = $cropArray['y'];

		// *** Crop this bad boy
		$crop = imagecreatetruecolor($newWidth, $newHeight);
		$this->keepTransparancy($optimalWidth, $optimalHeight, $crop);
		imagecopyresampled($crop, $this->imageResized, 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight, $newWidth, $newHeight);

		$this->imageResized = $crop;

		// *** Set new width and height to our variables
		$this->width = $newWidth;
		$this->height = $newHeight;

	}

## --------------------------------------------------------

	private function getCropPlacing($optimalWidth, $optimalHeight, $newWidth, $newHeight, $pos = 'm')
		#
		# Author:   Jarrod Oberto
		# Date:   July 11
		# Purpose:  Set the cropping area.
		# Params in:
		# Params out: (array) the crop x and y co-ordinates.
		# Notes:    When specifying the exact pixel crop position (eg 10x15), be
		#       very careful as it's easy to crop out of the image leaving
		#       black borders.
		#
	{
		$pos = fix_strtolower($pos);

		// *** If co-ords have been entered
		if (strstr($pos, 'x'))
		{
			$pos = str_replace(' ', '', $pos);

			$xyArray = explode('x', $pos);
			list($cropStartX, $cropStartY) = $xyArray;

		}
		else
		{

			switch ($pos)
			{
				case 'tl':
					$cropStartX = 0;
					$cropStartY = 0;
					break;

				case 't':
					$cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
					$cropStartY = 0;
					break;

				case 'tr':
					$cropStartX = $optimalWidth - $newWidth;
					$cropStartY = 0;
					break;

				case 'l':
					$cropStartX = 0;
					$cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
					break;

				case 'm':
					$cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
					$cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
					break;

				case 'r':
					$cropStartX = $optimalWidth - $newWidth;
					$cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
					break;

				case 'bl':
					$cropStartX = 0;
					$cropStartY = $optimalHeight - $newHeight;
					break;

				case 'b':
					$cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
					$cropStartY = $optimalHeight - $newHeight;
					break;

				case 'br':
					$cropStartX = $optimalWidth - $newWidth;
					$cropStartY = $optimalHeight - $newHeight;
					break;

				case 'auto':
					// *** If image is a portrait crop from top, not center. v1.5
					if ($optimalHeight > $optimalWidth)
					{
						$cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
						$cropStartY = ($this->cropFromTopPercent / 100) * $optimalHeight;
					}
					else
					{

						// *** Else crop from the center
						$cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
						$cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
					}
					break;

				default:
					// *** Default to center
					$cropStartX = ($optimalWidth / 2) - ($newWidth / 2);
					$cropStartY = ($optimalHeight / 2) - ($newHeight / 2);
					break;
			}
		}

		return array( 'x' => $cropStartX, 'y' => $cropStartY );
	}

## --------------------------------------------------------

	private function getDimensions($newWidth, $newHeight, $option)
		# Author:     Jarrod Oberto
		# Date:       17-11-09
		# Purpose:    Get new image dimensions based on user specificaions
		# Param in:   $newWidth:
		#             $newHeight:
		# Param out:  Array of new width and height values
		# Reference:
		# Notes:    If $option = 3 then this function is call recursivly
		#
		#       To clarify the $option input:
		#               0 = The exact height and width dimensions you set.
		#               1 = Whatever height is passed in will be the height that
		#                   is set. The width will be calculated and set automatically
		#                   to a the value that keeps the original aspect ratio.
		#               2 = The same but based on the width.
		#               3 = Depending whether the image is landscape or portrait, this
		#                   will automatically determine whether to resize via
		#                   dimension 1,2 or 0.
		#               4 = Resize the image as much as possible, then crop the
		#         remainder.
	{

		switch (strval($option))
		{
			case '0':
			case 'exact':
				$optimalWidth = $newWidth;
				$optimalHeight = $newHeight;
				break;
			case '1':
			case 'portrait':
				$dimensionsArray = $this->getSizeByFixedHeight($newWidth, $newHeight);
				$optimalWidth = $dimensionsArray['optimalWidth'];
				$optimalHeight = $dimensionsArray['optimalHeight'];
				break;
			case '2':
			case 'landscape':
				$dimensionsArray = $this->getSizeByFixedWidth($newWidth, $newHeight);
				$optimalWidth = $dimensionsArray['optimalWidth'];
				$optimalHeight = $dimensionsArray['optimalHeight'];
				break;
			case '3':
			case 'auto':
				$dimensionsArray = $this->getSizeByAuto($newWidth, $newHeight);
				$optimalWidth = $dimensionsArray['optimalWidth'];
				$optimalHeight = $dimensionsArray['optimalHeight'];
				break;
			case '4':
			case 'crop':
				$dimensionsArray = $this->getOptimalCrop($newWidth, $newHeight);
				$optimalWidth = $dimensionsArray['optimalWidth'];
				$optimalHeight = $dimensionsArray['optimalHeight'];
				break;
		}

		return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight );
	}

## --------------------------------------------------------

	private function getSizeByFixedHeight($newWidth, $newHeight)
	{
		// *** If forcing is off...
		if ( ! $this->forceStretch)
		{

			// *** ...check if actual height is less than target height
			if ($this->height < $newHeight)
			{
				return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height );
			}
		}

		$ratio = $this->width / $this->height;

		$newWidth = $newHeight * $ratio;

		//return $newWidth;
		return array( 'optimalWidth' => $newWidth, 'optimalHeight' => $newHeight );
	}

## --------------------------------------------------------

	private function getSizeByFixedWidth($newWidth, $newHeight)
	{
		// *** If forcing is off...
		if ( ! $this->forceStretch)
		{

			// *** ...check if actual width is less than target width
			if ($this->width < $newWidth)
			{
				return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height );
			}
		}

		$ratio = $this->height / $this->width;

		$newHeight = $newWidth * $ratio;

		//return $newHeight;
		return array( 'optimalWidth' => $newWidth, 'optimalHeight' => $newHeight );
	}

## --------------------------------------------------------

	private function getSizeByAuto($newWidth, $newHeight)
		# Author:     Jarrod Oberto
		# Date:       19-08-08
		# Purpose:    Depending on the height, choose to resize by 0, 1, or 2
		# Param in:   The new height and new width
		# Notes:
		#
	{
		// *** If forcing is off...
		if ( ! $this->forceStretch)
		{

			// *** ...check if actual size is less than target size
			if ($this->width < $newWidth && $this->height < $newHeight)
			{
				return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height );
			}
		}

		if ($this->height < $this->width)
			// *** Image to be resized is wider (landscape)
		{
			//$optimalWidth = $newWidth;
			//$optimalHeight= $this->getSizeByFixedWidth($newWidth);

			$dimensionsArray = $this->getSizeByFixedWidth($newWidth, $newHeight);
			$optimalWidth = $dimensionsArray['optimalWidth'];
			$optimalHeight = $dimensionsArray['optimalHeight'];
		}
		elseif ($this->height > $this->width)
			// *** Image to be resized is taller (portrait)
		{
			//$optimalWidth = $this->getSizeByFixedHeight($newHeight);
			//$optimalHeight= $newHeight;

			$dimensionsArray = $this->getSizeByFixedHeight($newWidth, $newHeight);
			$optimalWidth = $dimensionsArray['optimalWidth'];
			$optimalHeight = $dimensionsArray['optimalHeight'];
		}
		else
			// *** Image to be resizerd is a square
		{

			if ($newHeight < $newWidth)
			{
				//$optimalWidth = $newWidth;
				//$optimalHeight= $this->getSizeByFixedWidth($newWidth);
				$dimensionsArray = $this->getSizeByFixedWidth($newWidth, $newHeight);
				$optimalWidth = $dimensionsArray['optimalWidth'];
				$optimalHeight = $dimensionsArray['optimalHeight'];
			}
			else
			{
				if ($newHeight > $newWidth)
				{
					//$optimalWidth = $this->getSizeByFixedHeight($newHeight);
					//$optimalHeight= $newHeight;
					$dimensionsArray = $this->getSizeByFixedHeight($newWidth, $newHeight);
					$optimalWidth = $dimensionsArray['optimalWidth'];
					$optimalHeight = $dimensionsArray['optimalHeight'];
				}
				else
				{
					// *** Sqaure being resized to a square
					$optimalWidth = $newWidth;
					$optimalHeight = $newHeight;
				}
			}
		}

		return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight );
	}

## --------------------------------------------------------

	private function getOptimalCrop($newWidth, $newHeight)
		# Author:     Jarrod Oberto
		# Date:       17-11-09
		# Purpose:    Get optimal crop dimensions
		# Param in:   width and height as requested by user (fig 3)
		# Param out:  Array of optimal width and height (fig 2)
		# Reference:
		# Notes:      The optimal width and height return are not the same as the
		#       same as the width and height passed in. For example:
		#
		#
		#   |-----------------|     |------------|       |-------|
		#   |             |   =>  |**|      |**|   =>  |       |
		#   |             |     |**|      |**|       |       |
		#   |           |       |------------|       |-------|
		#   |-----------------|
		#        original                optimal             crop
		#              size                   size               size
		#  Fig          1                      2                  3
		#
		#       300 x 250           150 x 125          150 x 100
		#
		#    The optimal size is the smallest size (that is closest to the crop size)
		#    while retaining proportion/ratio.
		#
		#  The crop size is the optimal size that has been cropped on one axis to
		#  make the image the exact size specified by the user.
		#
		#               * represent cropped area
		#
	{

		// *** If forcing is off...
		if ( ! $this->forceStretch)
		{

			// *** ...check if actual size is less than target size
			if ($this->width < $newWidth && $this->height < $newHeight)
			{
				return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height );
			}
		}

		$heightRatio = $this->height / $newHeight;
		$widthRatio = $this->width / $newWidth;

		if ($heightRatio < $widthRatio)
		{
			$optimalRatio = $heightRatio;
		}
		else
		{
			$optimalRatio = $widthRatio;
		}

		$optimalHeight = round($this->height / $optimalRatio);
		$optimalWidth = round($this->width / $optimalRatio);

		return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight );
	}

## --------------------------------------------------------

	private function sharpen()
		# Author:     Jarrod Oberto
		# Date:       08 04 2011
		# Purpose:    Sharpen image
		# Param in:   n/a
		# Param out:  n/a
		# Reference:
		# Notes:
		# Credit:   Incorporates Joe Lencioni (August 6, 2008) code
	{

		if (version_compare(PHP_VERSION, '5.1.0') >= 0)
		{

			// ***
			if ($this->aggresiveSharpening)
			{ # A more aggressive sharpening solution

				$sharpenMatrix = array( array( -1, -1, -1 ),
										array( -1, 16, -1 ),
										array( -1, -1, -1 ) );
				$divisor = 8;
				$offset = 0;

				imageconvolution($this->imageResized, $sharpenMatrix, $divisor, $offset);
			}
			else # More subtle and personally more desirable
			{
				$sharpness = $this->findSharp($this->widthOriginal, $this->width);

				$sharpenMatrix = array(
					array( -1, -2, -1 ),
					array( -2, $sharpness + 12, -2 ), //Lessen the effect of a filter by increasing the value in the center cell
					array( -1, -2, -1 )
				);
				$divisor = $sharpness; // adjusts brightness
				$offset = 0;
				imageconvolution($this->imageResized, $sharpenMatrix, $divisor, $offset);
			}
		}
		else
		{
			if ($this->debug)
			{
				throw new Exception('Sharpening required PHP 5.1.0 or greater.');
			}
		}
	}

	## --------------------------------------------------------

	private function sharpen2($level)
	{
		$sharpenMatrix = array(
			array( $level, $level, $level ),
			array( $level, (8 * $level) + 1, $level ), //Lessen the effect of a filter by increasing the value in the center cell
			array( $level, $level, $level )
		);

	}

## --------------------------------------------------------

	private function findSharp($orig, $final)
		# Author:     Ryan Rud (http://adryrun.com)
		# Purpose:    Find optimal sharpness
		# Param in:   n/a
		# Param out:  n/a
		# Reference:
		# Notes:
		#
	{
		$final = $final * (750.0 / $orig);
		$a = 52;
		$b = -0.27810650887573124;
		$c = .00047337278106508946;

		$result = $a + $b * $final + $c * $final * $final;

		return max(round($result), 0);
	}

## --------------------------------------------------------

	private function prepOption($option)
		# Author:     Jarrod Oberto
		# Purpose:    Prep option like change the passed in option to lowercase
		# Param in:   (str/int) $option: eg. 'exact', 'crop'. 0, 4
		# Param out:  lowercase string
		# Reference:
		# Notes:
		#
	{
		if (is_array($option))
		{
			if (fix_strtolower($option[0]) == 'crop' && count($option) == 2)
			{
				return 'crop';
			}
			else
			{
				throw new Exception('Crop resize option array is badly formatted.');
			}
		}
		else
		{
			if (strpos($option, 'crop') !== false)
			{
				return 'crop';
			}
		}

		if (is_string($option))
		{
			return fix_strtolower($option);
		}

		return $option;
	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Presets
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

#
# Preset are pre-defined templates you can apply to your image.
#
# These are inteded to be applied to thumbnail images.
#


	public function borderPreset($preset)
	{
		switch ($preset)
		{

			case 'simple':
				$this->addBorder(7, '#fff');
				$this->addBorder(6, '#f2f1f0');
				$this->addBorder(2, '#fff');
				$this->addBorder(1, '#ccc');
				break;
			default:
				break;
		}

	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Draw border
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function addBorder($thickness = 1, $rgbArray = array( 255, 255, 255 ))
		# Author:     Jarrod Oberto
		# Date:       05-05-11
		# Purpose:    Add a border to the image
		# Param in:
		# Param out:
		# Reference:
		# Notes:    This border is added to the INSIDE of the image
		#
	{
		if ($this->imageResized)
		{

			$rgbArray = $this->formatColor($rgbArray);
			$r = $rgbArray['r'];
			$g = $rgbArray['g'];
			$b = $rgbArray['b'];


			$x1 = 0;
			$y1 = 0;
			$x2 = ImageSX($this->imageResized) - 1;
			$y2 = ImageSY($this->imageResized) - 1;

			$rgbArray = ImageColorAllocate($this->imageResized, $r, $g, $b);


			for ($i = 0; $i < $thickness; $i++)
			{
				ImageRectangle($this->imageResized, $x1++, $y1++, $x2--, $y2--, $rgbArray);
			}
		}
	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Gray Scale
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function greyScale()
		# Author:     Jarrod Oberto
		# Date:       07-05-2011
		# Purpose:    Make image greyscale
		# Param in:   n/a
		# Param out:
		# Reference:
		# Notes:
		#
	{
		if ($this->imageResized)
		{
			imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
		}

	}

	## --------------------------------------------------------

	public function greyScaleEnhanced()
		# Author:     Jarrod Oberto
		# Date:       07-05-2011
		# Purpose:    Make image greyscale
		# Param in:   n/a
		# Param out:
		# Reference:
		# Notes:
		#
	{
		if ($this->imageResized)
		{
			imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
			imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -15);
			imagefilter($this->imageResized, IMG_FILTER_BRIGHTNESS, 2);
			$this->sharpen($this->width);
		}
	}

	## --------------------------------------------------------

	public function greyScaleDramatic()
		# Alias of gd_filter_monopin
	{
		$this->gd_filter_monopin();
	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Black 'n White
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function blackAndWhite()
		# Author:     Jarrod Oberto
		# Date:       07-05-2011
		# Purpose:    Make image black and white
		# Param in:   n/a
		# Param out:
		# Reference:
		# Notes:
		#
	{
		if ($this->imageResized)
		{

			imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
			imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -1000);
		}

	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Negative
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function negative()
		# Author:     Jarrod Oberto
		# Date:       07-05-2011
		# Purpose:    Make image negative
		# Param in:   n/a
		# Param out:
		# Reference:
		# Notes:
		#
	{
		if ($this->imageResized)
		{

			imagefilter($this->imageResized, IMG_FILTER_NEGATE);
		}

	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Sepia
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function sepia()
		# Author:     Jarrod Oberto
		# Date:       07-05-2011
		# Purpose:    Make image sepia
		# Param in:   n/a
		# Param out:
		# Reference:
		# Notes:
		#
	{
		if ($this->imageResized)
		{
			imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
			imagefilter($this->imageResized, IMG_FILTER_BRIGHTNESS, -10);
			imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -20);
			imagefilter($this->imageResized, IMG_FILTER_COLORIZE, 60, 30, -15);
		}
	}

	## --------------------------------------------------------

	public function sepia2()

	{
		if ($this->imageResized)
		{

			$total = imagecolorstotal($this->imageResized);
			for ($i = 0; $i < $total; $i++)
			{
				$index = imagecolorsforindex($this->imageResized, $i);
				$red = ($index["red"] * 0.393 + $index["green"] * 0.769 + $index["blue"] * 0.189) / 1.351;
				$green = ($index["red"] * 0.349 + $index["green"] * 0.686 + $index["blue"] * 0.168) / 1.203;
				$blue = ($index["red"] * 0.272 + $index["green"] * 0.534 + $index["blue"] * 0.131) / 2.140;
				imagecolorset($this->imageResized, $i, $red, $green, $blue);
			}


		}
	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Vintage
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function vintage()
		# Alias of gd_filter_monopin
	{
		$this->gd_filter_vintage();
	}

	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Presets By Marc Hibbins
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/


	/** Apply 'Monopin' preset */
	public function gd_filter_monopin()
	{

		if ($this->imageResized)
		{
			imagefilter($this->imageResized, IMG_FILTER_GRAYSCALE);
			imagefilter($this->imageResized, IMG_FILTER_BRIGHTNESS, -15);
			imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -15);
			$this->imageResized = $this->gd_apply_overlay($this->imageResized, 'vignette', 100);
		}
	}

	## --------------------------------------------------------

	public function gd_filter_vintage()
	{
		if ($this->imageResized)
		{
			$this->imageResized = $this->gd_apply_overlay($this->imageResized, 'vignette', 45);
			imagefilter($this->imageResized, IMG_FILTER_BRIGHTNESS, 20);
			imagefilter($this->imageResized, IMG_FILTER_CONTRAST, -35);
			imagefilter($this->imageResized, IMG_FILTER_COLORIZE, 60, -10, 35);
			imagefilter($this->imageResized, IMG_FILTER_SMOOTH, 7);
			$this->imageResized = $this->gd_apply_overlay($this->imageResized, 'scratch', 10);
		}
	}

	## --------------------------------------------------------

	/** Apply a PNG overlay */
	private function gd_apply_overlay($im, $type, $amount)
		#
		# Original Author:    Marc Hibbins
		# License:  Attribution-ShareAlike 3.0
		# Purpose:
		# Params in:
		# Params out:
		# Notes:
		#
	{
		$width = imagesx($im);
		$height = imagesy($im);
		$filter = imagecreatetruecolor($width, $height);

		imagealphablending($filter, false);
		imagesavealpha($filter, true);

		$transparent = imagecolorallocatealpha($filter, 255, 255, 255, 127);
		imagefilledrectangle($filter, 0, 0, $width, $height, $transparent);

		// *** Resize overlay
		$overlay = $this->filterOverlayPath . '/' . $type . '.png';
		$png = imagecreatefrompng($overlay);
		imagecopyresampled($filter, $png, 0, 0, 0, 0, $width, $height, imagesx($png), imagesy($png));

		$comp = imagecreatetruecolor($width, $height);
		imagecopy($comp, $im, 0, 0, 0, 0, $width, $height);
		imagecopy($comp, $filter, 0, 0, 0, 0, $width, $height);
		imagecopymerge($im, $comp, 0, 0, 0, 0, $width, $height, $amount);

		imagedestroy($comp);

		return $im;
	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Colorise
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function image_colorize($rgb)
	{
		imageTrueColorToPalette($this->imageResized, true, 256);
		$numColors = imageColorsTotal($this->imageResized);

		for ($x = 0; $x < $numColors; $x++)
		{
			list($r, $g, $b) = array_values(imageColorsForIndex($this->imageResized, $x));

			// calculate grayscale in percent
			$grayscale = ($r + $g + $b) / 3 / 0xff;

			imageColorSet($this->imageResized, $x,
				$grayscale * $rgb[0],
				$grayscale * $rgb[1],
				$grayscale * $rgb[2]
			);

		}

		return true;
	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Reflection
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function addReflection($reflectionHeight = 50, $startingTransparency = 30, $inside = false, $bgColor = '#fff', $stretch = false, $divider = 0)
	{

		// *** Convert color
		$rgbArray = $this->formatColor($bgColor);
		$r = $rgbArray['r'];
		$g = $rgbArray['g'];
		$b = $rgbArray['b'];

		$im = $this->imageResized;
		$li = imagecreatetruecolor($this->width, 1);

		$bgc = imagecolorallocate($li, $r, $g, $b);
		imagefilledrectangle($li, 0, 0, $this->width, 1, $bgc);

		$bg = imagecreatetruecolor($this->width, $reflectionHeight);
		$wh = imagecolorallocate($im, 255, 255, 255);

		$im = imagerotate($im, -180, $wh);
		imagecopyresampled($bg, $im, 0, 0, 0, 0, $this->width, $this->height, $this->width, $this->height);

		$im = $bg;

		$bg = imagecreatetruecolor($this->width, $reflectionHeight);

		for ($x = 0; $x < $this->width; $x++)
		{
			imagecopy($bg, $im, $x, 0, $this->width - $x - 1, 0, 1, $reflectionHeight);
		}
		$im = $bg;

		$transaprencyAmount = $this->invertTransparency($startingTransparency, 100);


		// *** Fade
		if ($stretch)
		{
			$step = 100 / ($reflectionHeight + $startingTransparency);
		}
		else
		{
			$step = 100 / $reflectionHeight;
		}
		for ($i = 0; $i <= $reflectionHeight; $i++)
		{

			if ($startingTransparency > 100)
			{
				$startingTransparency = 100;
			}
			if ($startingTransparency < 1)
			{
				$startingTransparency = 1;
			}
			imagecopymerge($bg, $li, 0, $i, 0, 0, $this->width, 1, $startingTransparency);
			$startingTransparency += $step;
		}

		// *** Apply fade
		imagecopymerge($im, $li, 0, 0, 0, 0, $this->width, $divider, 100); // Divider


		// *** width, height of reflection.
		$x = imagesx($im);
		$y = imagesy($im);


		// *** Determines if the reflection should be displayed inside or outside the image
		if ($inside)
		{

			// Create new blank image with sizes.
			$final = imagecreatetruecolor($this->width, $this->height);

			imagecopymerge($final, $this->imageResized, 0, 0, 0, $reflectionHeight, $this->width, $this->height - $reflectionHeight, 100);
			imagecopymerge($final, $im, 0, $this->height - $reflectionHeight, 0, 0, $x, $y, 100);

		}
		else
		{

			// Create new blank image with sizes.
			$final = imagecreatetruecolor($this->width, $this->height + $y);

			imagecopymerge($final, $this->imageResized, 0, 0, 0, 0, $this->width, $this->height, 100);
			imagecopymerge($final, $im, 0, $this->height, 0, 0, $x, $y, 100);
		}

		$this->imageResized = $final;

		imagedestroy($li);
		imagedestroy($im);
	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Rotate
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function rotate($value = 90, $bgColor = 'transparent')
		# Author:     Jarrod Oberto
		# Date:       07-05-2011
		# Purpose:    Rotate image
		# Param in:   (mixed) $degrees: (int) number of degress to rotate image
		#               (str) param "left": rotate left
		#               (str) param "right": rotate right
		#               (str) param "upside": upside-down image
		# Param out:
		# Reference:
		# Notes:    The default direction of imageRotate() is counter clockwise.
		#
	{
		if ($this->imageResized)
		{

			if (is_integer($value))
			{
				$degrees = $value;
			}

			// *** Convert color
			$rgbArray = $this->formatColor($bgColor);
			$r = $rgbArray['r'];
			$g = $rgbArray['g'];
			$b = $rgbArray['b'];
			if (isset($rgbArray['a']))
			{
				$a = $rgbArray['a'];
			}

			if (is_string($value))
			{

				$value = fix_strtolower($value);

				switch ($value)
				{
					case 'left':
						$degrees = 90;
						break;
					case 'right':
						$degrees = 270;
						break;
					case 'upside':
						$degrees = 180;
						break;
					default:
						break;
				}

			}

			// *** The default direction of imageRotate() is counter clockwise
			//   * This makes it clockwise
			$degrees = 360 - $degrees;

			// *** Create background color
			$bg = ImageColorAllocateAlpha($this->imageResized, $r, $g, $b, $a);

			// *** Fill with background
			ImageFill($this->imageResized, 0, 0, $bg);

			// *** Rotate
			$this->imageResized = imagerotate($this->imageResized, $degrees, $bg); // Rotate 45 degrees and allocated the transparent colour as the one to make transparent (obviously)

			// Ensure alpha transparency
			ImageSaveAlpha($this->imageResized, true);

		}
	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Round corners
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function roundCorners($radius = 5, $bgColor = 'transparent')
		# Author:     Jarrod Oberto
		# Date:       19-05-2011
		# Purpose:    Create rounded corners on your image
		# Param in:   (int) radius = the amount of curvature
		#       (mixed) $bgColor = the corner background color
		# Param out:  n/a
		# Reference:
		# Notes:
		#
	{

		// *** Check if the user wants transparency
		$isTransparent = false;
		if ( ! is_array($bgColor))
		{
			if (fix_strtolower($bgColor) == 'transparent')
			{
				$isTransparent = true;
			}
		}


		// *** If we use transparency, we need to color our curved mask with a unique color
		if ($isTransparent)
		{
			$bgColor = $this->findUnusedGreen();
		}

		// *** Convert color
		$rgbArray = $this->formatColor($bgColor);
		$r = $rgbArray['r'];
		$g = $rgbArray['g'];
		$b = $rgbArray['b'];
		if (isset($rgbArray['a']))
		{
			$a = $rgbArray['a'];
		}


		// *** Create top-left corner mask (square)
		$cornerImg = imagecreatetruecolor($radius, $radius);
		//$cornerImg = imagecreate($radius, $radius);

		//imagealphablending($cornerImg, true);
		//imagesavealpha($cornerImg, true);

		//imagealphablending($this->imageResized, false);
		//imagesavealpha($this->imageResized, true);

		// *** Give it a color
		$maskColor = imagecolorallocate($cornerImg, 0, 0, 0);


		// *** Replace the mask color (black) to transparent
		imagecolortransparent($cornerImg, $maskColor);


		// *** Create the image background color
		$imagebgColor = imagecolorallocate($cornerImg, $r, $g, $b);


		// *** Fill the corner area to the user defined color
		imagefill($cornerImg, 0, 0, $imagebgColor);


		imagefilledellipse($cornerImg, $radius, $radius, $radius * 2, $radius * 2, $maskColor);


		// *** Map to top left corner
		imagecopymerge($this->imageResized, $cornerImg, 0, 0, 0, 0, $radius, $radius, 100); #tl

		// *** Map rounded corner to other corners by rotating and applying the mask
		$cornerImg = imagerotate($cornerImg, 90, 0);
		imagecopymerge($this->imageResized, $cornerImg, 0, $this->height - $radius, 0, 0, $radius, $radius, 100); #bl

		$cornerImg = imagerotate($cornerImg, 90, 0);
		imagecopymerge($this->imageResized, $cornerImg, $this->width - $radius, $this->height - $radius, 0, 0, $radius, $radius, 100); #br

		$cornerImg = imagerotate($cornerImg, 90, 0);
		imagecopymerge($this->imageResized, $cornerImg, $this->width - $radius, 0, 0, 0, $radius, $radius, 100); #tr


		// *** If corners are to be transparent, we fill our chromakey color as transparent.
		if ($isTransparent)
		{
			//imagecolortransparent($this->imageResized, $imagebgColor);
			$this->imageResized = $this->transparentImage($this->imageResized);
			imagesavealpha($this->imageResized, true);
		}

	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Shadow
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function addShadow($shadowAngle = 45, $blur = 15, $bgColor = 'transparent')
		#
		# Author:   Jarrod Oberto (Adapted from Pascal Naidon)
		# Ref:    http://www.les-stooges.org/pascal/webdesign/vignettes/index.php?la=en
		# Purpose:  Add a drop shadow to your image
		# Params in:  (int) $angle: the angle of the shadow
		#       (int) $blur: the blur distance
		#       (mixed) $bgColor: the color of the background
		# Params out:
		# Notes:
		#
	{
		// *** A higher number results in a smoother shadow
		define('STEPS', $blur * 2);

		// *** Set the shadow distance
		$shadowDistance = $blur * 0.25;

		// *** Set blur width and height
		$blurWidth = $blurHeight = $blur;


		if ($shadowAngle == 0)
		{
			$distWidth = 0;
			$distHeight = 0;
		}
		else
		{
			$distWidth = $shadowDistance * cos(deg2rad($shadowAngle));
			$distHeight = $shadowDistance * sin(deg2rad($shadowAngle));
		}


		// *** Convert color
		if (fix_strtolower($bgColor) != 'transparent')
		{
			$rgbArray = $this->formatColor($bgColor);
			$r0 = $rgbArray['r'];
			$g0 = $rgbArray['g'];
			$b0 = $rgbArray['b'];
		}


		$image = $this->imageResized;
		$width = $this->width;
		$height = $this->height;


		$newImage = imagecreatetruecolor($width, $height);
		imagecopyresampled($newImage, $image, 0, 0, 0, 0, $width, $height, $width, $height);


		// *** RGB
		$rgb = imagecreatetruecolor($width + $blurWidth, $height + $blurHeight);
		$colour = imagecolorallocate($rgb, 0, 0, 0);
		imagefilledrectangle($rgb, 0, 0, $width + $blurWidth, $height + $blurHeight, $colour);
		$colour = imagecolorallocate($rgb, 255, 255, 255);
		//imagefilledrectangle($rgb, $blurWidth*0.5-$distWidth, $blurHeight*0.5-$distHeight, $width+$blurWidth*0.5-$distWidth, $height+$blurWidth*0.5-$distHeight, $colour);
		imagefilledrectangle($rgb, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, $width + $blurWidth * 0.5 - $distWidth, $height + $blurWidth * 0.5 - $distHeight, $colour);
		//imagecopymerge($rgb, $newImage, 1+$blurWidth*0.5-$distWidth, 1+$blurHeight*0.5-$distHeight, 0,0, $width, $height, 100);
		imagecopymerge($rgb, $newImage, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, 0, 0, $width + $blurWidth, $height + $blurHeight, 100);


		// *** Shadow (alpha)
		$shadow = imagecreatetruecolor($width + $blurWidth, $height + $blurHeight);
		imagealphablending($shadow, false);
		$colour = imagecolorallocate($shadow, 0, 0, 0);
		imagefilledrectangle($shadow, 0, 0, $width + $blurWidth, $height + $blurHeight, $colour);


		for ($i = 0; $i <= STEPS; $i++)
		{

			$t = ((1.0 * $i) / STEPS);
			$intensity = 255 * $t * $t;

			$colour = imagecolorallocate($shadow, $intensity, $intensity, $intensity);
			$points = array(
				$blurWidth * $t, $blurHeight,     // Point 1 (x, y)
				$blurWidth, $blurHeight * $t,  // Point 2 (x, y)
				$width, $blurHeight * $t,  // Point 3 (x, y)
				$width + $blurWidth * (1 - $t), $blurHeight,     // Point 4 (x, y)
				$width + $blurWidth * (1 - $t), $height,     // Point 5 (x, y)
				$width, $height + $blurHeight * (1 - $t),  // Point 6 (x, y)
				$blurWidth, $height + $blurHeight * (1 - $t),  // Point 7 (x, y)
				$blurWidth * $t, $height      // Point 8 (x, y)
			);
			imagepolygon($shadow, $points, 8, $colour);
		}

		for ($i = 0; $i <= STEPS; $i++)
		{

			$t = ((1.0 * $i) / STEPS);
			$intensity = 255 * $t * $t;

			$colour = imagecolorallocate($shadow, $intensity, $intensity, $intensity);
			imagefilledarc($shadow, $blurWidth - 1, $blurHeight - 1, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 180, 268, $colour, IMG_ARC_PIE);
			imagefilledarc($shadow, $width, $blurHeight - 1, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 270, 358, $colour, IMG_ARC_PIE);
			imagefilledarc($shadow, $width, $height, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 0, 90, $colour, IMG_ARC_PIE);
			imagefilledarc($shadow, $blurWidth - 1, $height, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 90, 180, $colour, IMG_ARC_PIE);
		}


		$colour = imagecolorallocate($shadow, 255, 255, 255);
		imagefilledrectangle($shadow, $blurWidth, $blurHeight, $width, $height, $colour);
		imagefilledrectangle($shadow, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, $width + $blurWidth * 0.5 - 1 - $distWidth, $height + $blurHeight * 0.5 - 1 - $distHeight, $colour);


		// *** The magic
		imagealphablending($rgb, false);

		for ($theX = 0; $theX < imagesx($rgb); $theX++)
		{
			for ($theY = 0; $theY < imagesy($rgb); $theY++)
			{

				// *** Get the RGB values for every pixel of the RGB image
				$colArray = imagecolorat($rgb, $theX, $theY);
				$r = ($colArray >> 16) & 0xFF;
				$g = ($colArray >> 8) & 0xFF;
				$b = $colArray & 0xFF;

				// *** Get the alpha value for every pixel of the shadow image
				$colArray = imagecolorat($shadow, $theX, $theY);
				$a = $colArray & 0xFF;
				$a = 127 - floor($a / 2);
				$t = $a / 128.0;

				// *** Create color
				if (fix_strtolower($bgColor) == 'transparent')
				{
					$myColour = imagecolorallocatealpha($rgb, $r, $g, $b, $a);
				}
				else
				{
					$myColour = imagecolorallocate($rgb, $r * (1.0 - $t) + $r0 * $t, $g * (1.0 - $t) + $g0 * $t, $b * (1.0 - $t) + $b0 * $t);
				}

				// *** Add color to new rgb image
				imagesetpixel($rgb, $theX, $theY, $myColour);
			}
		}

		imagealphablending($rgb, true);
		imagesavealpha($rgb, true);

		$this->imageResized = $rgb;

		imagedestroy($image);
		imagedestroy($newImage);
		imagedestroy($shadow);
	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Add Caption Box
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function addCaptionBox($side = 'b', $thickness = 50, $padding = 0, $bgColor = '#000', $transaprencyAmount = 30)
		#
		# Author:   Jarrod Oberto
		# Date:   26 May 2011
		# Purpose:  Add a caption box
		# Params in:  (str) $side: the side to add the caption box (t, r, b, or l).
		#       (int) $thickness: how thick you want the caption box to be.
		#       (mixed) $bgColor: The color of the caption box.
		#       (int) $transaprencyAmount: The amount of transparency to be
		#       applied.
		# Params out: n/a
		# Notes:
		#
	{
		$side = fix_strtolower($side);

		// *** Convert color
		$rgbArray = $this->formatColor($bgColor);
		$r = $rgbArray['r'];
		$g = $rgbArray['g'];
		$b = $rgbArray['b'];

		$positionArray = $this->calculateCaptionBoxPosition($side, $thickness, $padding);

		// *** Store incase we want to use method addTextToCaptionBox()
		$this->captionBoxPositionArray = $positionArray;


		$transaprencyAmount = $this->invertTransparency($transaprencyAmount, 127, false);
		$transparent = imagecolorallocatealpha($this->imageResized, $r, $g, $b, $transaprencyAmount);
		imagefilledrectangle($this->imageResized, $positionArray['x1'], $positionArray['y1'], $positionArray['x2'], $positionArray['y2'], $transparent);
	}

	## --------------------------------------------------------

	public function addTextToCaptionBox($text, $fontColor = '#fff', $fontSize = 12, $angle = 0, $font = null)
		#
		# Author:   Jarrod Oberto
		# Date:   03 Aug 11
		# Purpose:  Simplify adding text to a caption box by automatically
		#       locating the center of the caption box
		# Params in:  The usually text paams (less a couple)
		# Params out: n/a
		# Notes:
		#
	{

		// *** Get the caption box measurements
		if (count($this->captionBoxPositionArray) == 4)
		{
			$x1 = $this->captionBoxPositionArray['x1'];
			$x2 = $this->captionBoxPositionArray['x2'];
			$y1 = $this->captionBoxPositionArray['y1'];
			$y2 = $this->captionBoxPositionArray['y2'];
		}
		else
		{
			if ($this->debug)
			{
				throw new Exception('No caption box found.');
			}
			else
			{
				return false;
			}
		}


		// *** Get text font
		$font = $this->getTextFont($font);

		// *** Get text size
		$textSizeArray = $this->getTextSize($fontSize, $angle, $font, $text);
		$textWidth = $textSizeArray['width'];
		$textHeight = $textSizeArray['height'];

		// *** Find the width/height middle points
		$boxXMiddle = (($x2 - $x1) / 2);
		$boxYMiddle = (($y2 - $y1) / 2);

		// *** Box middle - half the text width/height
		$xPos = ($x1 + $boxXMiddle) - ($textWidth / 2);
		$yPos = ($y1 + $boxYMiddle) - ($textHeight / 2);

		$pos = $xPos . 'x' . $yPos;

		$this->addText($text, $pos, $padding = 0, $fontColor, $fontSize, $angle, $font);

	}

	## --------------------------------------------------------

	private function calculateCaptionBoxPosition($side, $thickness, $padding)
	{
		$positionArray = array();

		switch ($side)
		{
			case 't':
				$positionArray['x1'] = 0;
				$positionArray['y1'] = $padding;
				$positionArray['x2'] = $this->width;
				$positionArray['y2'] = $thickness + $padding;
				break;
			case 'r':
				$positionArray['x1'] = $this->width - $thickness - $padding;
				$positionArray['y1'] = 0;
				$positionArray['x2'] = $this->width - $padding;
				$positionArray['y2'] = $this->height;
				break;
			case 'b':
				$positionArray['x1'] = 0;
				$positionArray['y1'] = $this->height - $thickness - $padding;
				$positionArray['x2'] = $this->width;
				$positionArray['y2'] = $this->height - $padding;
				break;
			case 'l':
				$positionArray['x1'] = $padding;
				$positionArray['y1'] = 0;
				$positionArray['x2'] = $thickness + $padding;
				$positionArray['y2'] = $this->height;
				break;

			default:
				break;
		}

		return $positionArray;

	}

	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Get EXIF Data
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function getExif($debug = false)
		# Author:     Jarrod Oberto
		# Date:       07-05-2011
		# Purpose:    Get image EXIF data
		# Param in:   n/a
		# Param out:  An associate array of EXIF data
		# Reference:
		# Notes:
		# 23 May 13 : added orientation flag -jco
		#
	{

		if ( ! $this->debug || ! $debug)
		{
			$debug = false;
		}

		// *** Check all is good - check the EXIF library exists and the file exists, too.
		if ( ! $this->testEXIFInstalled())
		{
			if ($debug)
			{
				throw new Exception('The EXIF Library is not installed.');
			}
			else
			{
				return array();
			}
		};
		if ( ! file_exists($this->fileName))
		{
			if ($debug)
			{
				throw new Exception('Image not found.');
			}
			else
			{
				return array();
			}
		};
		if ($this->fileExtension != '.jpg')
		{
			if ($debug)
			{
				throw new Exception('Metadata not supported for this image type.');
			}
			else
			{
				return array();
			}
		};
		$exifData = exif_read_data($this->fileName, 'IFD0');

		// *** Format the apperture value
		$ev = $exifData['ApertureValue'];
		$apPeicesArray = explode('/', $ev);
		if (count($apPeicesArray) == 2)
		{
			$apertureValue = round($apPeicesArray[0] / $apPeicesArray[1], 2, PHP_ROUND_HALF_DOWN) . ' EV';
		}
		else
		{
			$apertureValue = '';
		}

		// *** Format the focal length
		$focalLength = $exifData['FocalLength'];
		$flPeicesArray = explode('/', $focalLength);
		if (count($flPeicesArray) == 2)
		{
			$focalLength = $flPeicesArray[0] / $flPeicesArray[1] . '.0 mm';
		}
		else
		{
			$focalLength = '';
		}

		// *** Format fNumber
		$fNumber = $exifData['FNumber'];
		$fnPeicesArray = explode('/', $fNumber);
		if (count($fnPeicesArray) == 2)
		{
			$fNumber = $fnPeicesArray[0] / $fnPeicesArray[1];
		}
		else
		{
			$fNumber = '';
		}

		// *** Resolve ExposureProgram
		if (isset($exifData['ExposureProgram']))
		{
			$ep = $exifData['ExposureProgram'];
		}
		if (isset($ep))
		{
			$ep = $this->resolveExposureProgram($ep);
		}


		// *** Resolve MeteringMode
		$mm = $exifData['MeteringMode'];
		$mm = $this->resolveMeteringMode($mm);

		// *** Resolve Flash
		$flash = $exifData['Flash'];
		$flash = $this->resolveFlash($flash);


		if (isset($exifData['Make']))
		{
			$exifDataArray['make'] = $exifData['Make'];
		}
		else
		{
			$exifDataArray['make'] = '';
		}

		if (isset($exifData['Model']))
		{
			$exifDataArray['model'] = $exifData['Model'];
		}
		else
		{
			$exifDataArray['model'] = '';
		}

		if (isset($exifData['DateTime']))
		{
			$exifDataArray['date'] = $exifData['DateTime'];
		}
		else
		{
			$exifDataArray['date'] = '';
		}

		if (isset($exifData['ExposureTime']))
		{
			$exifDataArray['exposure time'] = $exifData['ExposureTime'] . ' sec.';
		}
		else
		{
			$exifDataArray['exposure time'] = '';
		}

		if ($apertureValue != '')
		{
			$exifDataArray['aperture value'] = $apertureValue;
		}
		else
		{
			$exifDataArray['aperture value'] = '';
		}

		if (isset($exifData['COMPUTED']['ApertureFNumber']))
		{
			$exifDataArray['f-stop'] = $exifData['COMPUTED']['ApertureFNumber'];
		}
		else
		{
			$exifDataArray['f-stop'] = '';
		}

		if (isset($exifData['FNumber']))
		{
			$exifDataArray['fnumber'] = $exifData['FNumber'];
		}
		else
		{
			$exifDataArray['fnumber'] = '';
		}

		if ($fNumber != '')
		{
			$exifDataArray['fnumber value'] = $fNumber;
		}
		else
		{
			$exifDataArray['fnumber value'] = '';
		}

		if (isset($exifData['ISOSpeedRatings']))
		{
			$exifDataArray['iso'] = $exifData['ISOSpeedRatings'];
		}
		else
		{
			$exifDataArray['iso'] = '';
		}

		if ($focalLength != '')
		{
			$exifDataArray['focal length'] = $focalLength;
		}
		else
		{
			$exifDataArray['focal length'] = '';
		}

		if (isset($ep))
		{
			$exifDataArray['exposure program'] = $ep;
		}
		else
		{
			$exifDataArray['exposure program'] = '';
		}

		if ($mm != '')
		{
			$exifDataArray['metering mode'] = $mm;
		}
		else
		{
			$exifDataArray['metering mode'] = '';
		}

		if ($flash != '')
		{
			$exifDataArray['flash status'] = $flash;
		}
		else
		{
			$exifDataArray['flash status'] = '';
		}

		if (isset($exifData['Artist']))
		{
			$exifDataArray['creator'] = $exifData['Artist'];
		}
		else
		{
			$exifDataArray['creator'] = '';
		}

		if (isset($exifData['Copyright']))
		{
			$exifDataArray['copyright'] = $exifData['Copyright'];
		}
		else
		{
			$exifDataArray['copyright'] = '';
		}

		// *** Orientation
		if (isset($exifData['Orientation']))
		{
			$exifDataArray['orientation'] = $exifData['Orientation'];
		}
		else
		{
			$exifDataArray['orientation'] = '';
		}

		return $exifDataArray;
	}

	## --------------------------------------------------------

	private function resolveExposureProgram($ep)
	{
		switch ($ep)
		{
			case 0:
				$ep = '';
				break;
			case 1:
				$ep = 'manual';
				break;
			case 2:
				$ep = 'normal program';
				break;
			case 3:
				$ep = 'aperture priority';
				break;
			case 4:
				$ep = 'shutter priority';
				break;
			case 5:
				$ep = 'creative program';
				break;
			case 6:
				$ep = 'action program';
				break;
			case 7:
				$ep = 'portrait mode';
				break;
			case 8:
				$ep = 'landscape mode';
				break;

			default:
				break;
		}

		return $ep;
	}

	## --------------------------------------------------------

	private function resolveMeteringMode($mm)
	{
		switch ($mm)
		{
			case 0:
				$mm = 'unknown';
				break;
			case 1:
				$mm = 'average';
				break;
			case 2:
				$mm = 'center weighted average';
				break;
			case 3:
				$mm = 'spot';
				break;
			case 4:
				$mm = 'multi spot';
				break;
			case 5:
				$mm = 'pattern';
				break;
			case 6:
				$mm = 'partial';
				break;
			case 255:
				$mm = 'other';
				break;

			default:
				break;
		}

		return $mm;
	}

	## --------------------------------------------------------

	private function resolveFlash($flash)
	{
		switch ($flash)
		{
			case 0:
				$flash = 'flash did not fire';
				break;
			case 1:
				$flash = 'flash fired';
				break;
			case 5:
				$flash = 'strobe return light not detected';
				break;
			case 7:
				$flash = 'strobe return light detected';
				break;
			case 9:
				$flash = 'flash fired, compulsory flash mode';
				break;
			case 13:
				$flash = 'flash fired, compulsory flash mode, return light not detected';
				break;
			case 15:
				$flash = 'flash fired, compulsory flash mode, return light detected';
				break;
			case 16:
				$flash = 'flash did not fire, compulsory flash mode';
				break;
			case 24:
				$flash = 'flash did not fire, auto mode';
				break;
			case 25:
				$flash = 'flash fired, auto mode';
				break;
			case 29:
				$flash = 'flash fired, auto mode, return light not detected';
				break;
			case 31:
				$flash = 'flash fired, auto mode, return light detected';
				break;
			case 32:
				$flash = 'no flash function';
				break;
			case 65:
				$flash = 'flash fired, red-eye reduction mode';
				break;
			case 69:
				$flash = 'flash fired, red-eye reduction mode, return light not detected';
				break;
			case 71:
				$flash = 'flash fired, red-eye reduction mode, return light detected';
				break;
			case 73:
				$flash = 'flash fired, compulsory flash mode, red-eye reduction mode';
				break;
			case 77:
				$flash = 'flash fired, compulsory flash mode, red-eye reduction mode, return light not detected';
				break;
			case 79:
				$flash = 'flash fired, compulsory flash mode, red-eye reduction mode, return light detected';
				break;
			case 89:
				$flash = 'flash fired, auto mode, red-eye reduction mode';
				break;
			case 93:
				$flash = 'flash fired, auto mode, return light not detected, red-eye reduction mode';
				break;
			case 95:
				$flash = 'flash fired, auto mode, return light detected, red-eye reduction mode';
				break;

			default:
				break;
		}

		return $flash;

	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Get IPTC Data
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Write IPTC Data
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function writeIPTCcaption($value)
		# Caption
	{
		$this->writeIPTC(120, $value);
	}

	## --------------------------------------------------------

	public function writeIPTCwriter($value)
	{
		//$this->writeIPTC(65, $value);
	}

	## --------------------------------------------------------

	private function writeIPTC($dat, $value)
	{

		# LIMIT TO JPG

		$caption_block = $this->iptc_maketag(2, $dat, $value);
		$image_string = iptcembed($caption_block, $this->fileName);
		file_put_contents('iptc.jpg', $image_string);
	}

## --------------------------------------------------------

	private function iptc_maketag($rec, $dat, $val)
		# Author:   Thies C. Arntzen
		# Purpose:    Function to format the new IPTC text
		# Param in:   $rec: Application record. (We’re working with #2)
		#       $dat: Index. (120 for caption, 118 for contact. See the IPTC IIM
		#         specification:
		#         http://www.iptc.org/std/IIM/4.1/specification/IIMV4.1.pdf
		#       $val: Value/data/text. Make sure this is within the length
		#         constraints of the IPTC IIM specification
		# Ref:      http://blog.peterhaza.no/working-with-image-meta-data-in-exif-and-iptc-headers-from-php/
		#       http://php.net/manual/en/function.iptcembed.php
		#
	{
		$len = strlen($val);
		if ($len < 0x8000)
		{
			return chr(0x1c) . chr($rec) . chr($dat) .
			chr($len >> 8) .
			chr($len & 0xff) .
			$val;
		}
		else
		{
			return chr(0x1c) . chr($rec) . chr($dat) .
			chr(0x80) . chr(0x04) .
			chr(($len >> 24) & 0xff) .
			chr(($len >> 16) & 0xff) .
			chr(($len >> 8) & 0xff) .
			chr(($len) & 0xff) .
			$val;
		}
	}



	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Write XMP Data
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	//http://xmpphptoolkit.sourceforge.net/


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Add Text
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function addText($text, $pos = '20x20', $padding = 0, $fontColor = '#fff', $fontSize = 12, $angle = 0, $font = null)
		# Author:     Jarrod Oberto
		# Date:       18-11-09
		# Purpose:    Add text to an image
		# Param in:
		# Param out:
		# Reference:  http://php.net/manual/en/function.imagettftext.php
		# Notes:      Make sure you supply the font.
		#
	{

		// *** Convert color
		$rgbArray = $this->formatColor($fontColor);
		$r = $rgbArray['r'];
		$g = $rgbArray['g'];
		$b = $rgbArray['b'];

		// *** Get text font
		$font = $this->getTextFont($font);

		// *** Get text size
		$textSizeArray = $this->getTextSize($fontSize, $angle, $font, $text);
		$textWidth = $textSizeArray['width'];
		$textHeight = $textSizeArray['height'];

		// *** Find co-ords to place text
		$posArray = $this->calculatePosition($pos, $padding, $textWidth, $textHeight, false);
		$x = $posArray['width'];
		$y = $posArray['height'];

		$fontColor = imagecolorallocate($this->imageResized, $r, $g, $b);

		// *** Add text
		imagettftext($this->imageResized, $fontSize, $angle, $x, $y, $fontColor, $font, $text);
	}

	## --------------------------------------------------------

	private function getTextFont($font)
	{
		// *** Font path (shou
		$fontPath = dirname(__FILE__) . '/' . $this->fontDir;


		// *** The below is/may be needed depending on your version (see ref)
		putenv('GDFONTPATH=' . realpath('.'));

		// *** Check if the passed in font exsits...
		if ($font == null || ! file_exists($font))
		{

			// *** ...If not, default to this font.
			$font = $fontPath . '/arimo.ttf';

			// *** Check our default font exists...
			if ( ! file_exists($font))
			{

				// *** If not, return false
				if ($this->debug)
				{
					throw new Exception('Font not found');
				}
				else
				{
					return false;
				}
			}
		}

		return $font;

	}

	## --------------------------------------------------------

	private function getTextSize($fontSize, $angle, $font, $text)
	{

		// *** Define box (so we can get the width)
		$box = @imageTTFBbox($fontSize, $angle, $font, $text);

		// ***  Get width of text from dimensions
		$textWidth = abs($box[4] - $box[0]);

		// ***  Get height of text from dimensions (should also be same as $fontSize)
		$textHeight = abs($box[5] - $box[1]);

		return array( 'height' => $textHeight, 'width' => $textWidth );
	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  Add Watermark
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	public function addWatermark($watermarkImage, $pos, $padding = 0, $opacity = 0)
		# Author:     Jarrod Oberto
		# Date:       18-11-09
		# Purpose:    Add watermark image
		# Param in:   (str) $watermark: The watermark image
		#       (str) $pos: Could be a pre-determined position such as:
		#           tl = top left,
		#           t  = top (middle),
		#           tr = top right,
		#           l  = left,
		#           m  = middle,
		#           r  = right,
		#           bl = bottom left,
		#           b  = bottom (middle),
		#           br = bottom right
		#         Or, it could be a co-ordinate position such as: 50x100
		#
		#       (int) $padding: If using a pre-determined position you can
		#         adjust the padding from the edges by passing an amount
		#         in pixels. If using co-ordinates, this value is ignored.
		# Param out:
		# Reference:  http://www.php.net/manual/en/image.examples-watermark.php
		# Notes:      Based on example in reference.
		#
		#
	{

		// Load the stamp and the photo to apply the watermark to
		$stamp = $this->openImage($watermarkImage);    # stamp
		$im = $this->imageResized;            # photo

		// *** Get stamps width and height
		$sx = imagesx($stamp);
		$sy = imagesy($stamp);

		// *** Find co-ords to place image
		$posArray = $this->calculatePosition($pos, $padding, $sx, $sy);
		$x = $posArray['width'];
		$y = $posArray['height'];

		// *** Set watermark opacity
		if (fix_strtolower(strrchr($watermarkImage, '.')) == '.png')
		{

			$opacity = $this->invertTransparency($opacity, 100);
			$this->filterOpacity($stamp, $opacity);
		}

		// Copy the watermark image onto our photo
		imagecopy($im, $stamp, $x, $y, 0, 0, imagesx($stamp), imagesy($stamp));

	}

	## --------------------------------------------------------

	private function calculatePosition($pos, $padding, $assetWidth, $assetHeight, $upperLeft = true)
		#
		# Author:   Jarrod Oberto
		# Date:   08-05-11
		# Purpose:  Calculate the x, y pixel cordinates of the asset to place
		# Params in:  (str) $pos: Either something like: "tl", "l", "br" or an
		#         exact position like: "100x50"
		#       (int) $padding: The amount of padding from the edge. Only
		#         used for the predefined $pos.
		#       (int) $assetWidth: The width of the asset to add to the image
		#       (int) $assetHeight: The height of the asset to add to the image
		#       (bol) $upperLeft: if true, the asset will be positioned based
		#         on the upper left x, y coords. If false, it means you're
		#         using the lower left as the basepoint and this will
		#         convert it to the upper left position
		# Params out:
		# NOTE: this is done from the UPPER left corner!! But will convert lower
		#   left basepoints to upper left if $upperleft is set to false
		#
		#
	{
		$pos = fix_strtolower($pos);

		// *** If co-ords have been entered
		if (strstr($pos, 'x'))
		{
			$pos = str_replace(' ', '', $pos);

			$xyArray = explode('x', $pos);
			list($width, $height) = $xyArray;

		}
		else
		{

			switch ($pos)
			{
				case 'tl':
					$width = 0 + $padding;
					$height = 0 + $padding;
					break;

				case 't':
					$width = ($this->width / 2) - ($assetWidth / 2);
					$height = 0 + $padding;
					break;

				case 'tr':
					$width = $this->width - $assetWidth - $padding;
					$height = 0 + $padding;;
					break;

				case 'l':
					$width = 0 + $padding;
					$height = ($this->height / 2) - ($assetHeight / 2);
					break;

				case 'm':
					$width = ($this->width / 2) - ($assetWidth / 2);
					$height = ($this->height / 2) - ($assetHeight / 2);
					break;

				case 'r':
					$width = $this->width - $assetWidth - $padding;
					$height = ($this->height / 2) - ($assetHeight / 2);
					break;

				case 'bl':
					$width = 0 + $padding;
					$height = $this->height - $assetHeight - $padding;
					break;

				case 'b':
					$width = ($this->width / 2) - ($assetWidth / 2);
					$height = $this->height - $assetHeight - $padding;
					break;

				case 'br':
					$width = $this->width - $assetWidth - $padding;
					$height = $this->height - $assetHeight - $padding;
					break;

				default:
					$width = 0;
					$height = 0;
					break;
			}
		}

		if ( ! $upperLeft)
		{
			$height = $height + $assetHeight;
		}

		return array( 'width' => $width, 'height' => $height );
	}


	## --------------------------------------------------------

	private function filterOpacity(&$img, $opacity = 75)
		#
		# Author:     aiden dot mail at freemail dot hu
		# Author date:  29-03-08 08:16
		# Date added:   08-05-11
		# Purpose:    Change opacity of image
		# Params in:    $img: Image resource id
		#         (int) $opacity: the opacity amount: 0-100, 100 being not opaque.
		# Params out:   (bool) true on success, else false
		# Ref:      http://www.php.net/manual/en/function.imagefilter.php#82162
		# Notes:      png only
		#
	{

		if ( ! isset($opacity))
		{
			return false;
		}

		if ($opacity == 100)
		{
			return true;
		}

		$opacity /= 100;

		//get image width and height
		$w = imagesx($img);
		$h = imagesy($img);

		//turn alpha blending off
		imagealphablending($img, false);

		//find the most opaque pixel in the image (the one with the smallest alpha value)
		$minalpha = 127;
		for ($x = 0; $x < $w; $x++)
		{
			for ($y = 0; $y < $h; $y++)
			{
				$alpha = (imagecolorat($img, $x, $y) >> 24) & 0xFF;
				if ($alpha < $minalpha)
				{
					$minalpha = $alpha;
				}
			}
		}

		//loop through image pixels and modify alpha for each
		for ($x = 0; $x < $w; $x++)
		{
			for ($y = 0; $y < $h; $y++)
			{
				//get current alpha value (represents the TANSPARENCY!)
				$colorxy = imagecolorat($img, $x, $y);
				$alpha = ($colorxy >> 24) & 0xFF;
				//calculate new alpha
				if ($minalpha !== 127)
				{
					$alpha = 127 + 127 * $opacity * ($alpha - 127) / (127 - $minalpha);
				}
				else
				{
					$alpha += 127 * $opacity;
				}
				//get the color index with new alpha
				$alphacolorxy = imagecolorallocatealpha($img, ($colorxy >> 16) & 0xFF, ($colorxy >> 8) & 0xFF, $colorxy & 0xFF, $alpha);
				//set pixel with the new color + opacity
				if ( ! imagesetpixel($img, $x, $y, $alphacolorxy))
				{

					return false;
				}
			}
		}

		return true;
	}

## --------------------------------------------------------

	private function openImage($file)
		# Author:     Jarrod Oberto
		# Date:       27-02-08
		# Purpose:
		# Param in:
		# Param out:  n/a
		# Reference:
		# Notes:
		#
	{

		if ( ! file_exists($file) && ! $this->checkStringStartsWith('http://', $file) && ! $this->checkStringStartsWith('https://', $file) )
		{
			if ($this->debug)
			{
				throw new Exception('Image not found.');
			}
			else
			{
				throw new Exception();
			}
		};

		// *** Get extension / image type
		$extension = mime_content_type($file);
		$extension = fix_strtolower($extension);
		$extension = str_replace('image/', '', $extension);
		switch ($extension)
		{
			case 'jpg':
			case 'jpeg':
				$img = @imagecreatefromjpeg($file);
				break;
			case 'gif':
				$img = @imagecreatefromgif($file);
				break;
			case 'png':
				$img = @imagecreatefrompng($file);
				break;
			case 'bmp':
				$img = @$this->imagecreatefrombmp($file);
				break;
			case 'psd':
			case 'vnd.adobe.photoshop':
				$img = @$this->imagecreatefrompsd($file);
				break;


			// ... etc

			default:
				$img = false;
				break;
		}

		return $img;
	}

## --------------------------------------------------------

	public function reset()
		#
		# Author:   Jarrod Oberto
		# Date:   30-08-11
		# Purpose:  Reset the resource (allow further editing)
		# Params in:
		# Params out:
		# Notes:
		#
	{
		$this->__construct($this->fileName);
	}

## --------------------------------------------------------

	public function saveImage($savePath, $imageQuality = "100")
		# Author:     Jarrod Oberto
		# Date:       27-02-08
		# Purpose:    Saves the image
		# Param in:   $savePath: Where to save the image including filename:
		#             $imageQuality: image quality you want the image saved at 0-100
		# Param out:  n/a
		# Reference:
		# Notes:    * gif doesn't have a quality parameter
		#       * jpg has a quality setting 0-100 (100 being the best)
		#       * png has a quality setting 0-9 (0 being the best)
		#
		#             * bmp files have no native support for bmp files. We use a
		#       third party class to save as bmp.
	{

		// *** Perform a check or two.
		if ( ! is_resource($this->imageResized))
		{
			if ($this->debug)
			{
				throw new Exception('saveImage: This is not a resource.');
			}
			else
			{
				throw new Exception();
			}
		}
		$fileInfoArray = pathInfo($savePath);
		clearstatcache();
		if ( ! is_writable($fileInfoArray['dirname']))
		{
			if ($this->debug)
			{
				throw new Exception('The path is not writable. Please check your permissions.');
			}
			else
			{
				throw new Exception();
			}
		}

		// *** Get extension
		$extension = strrchr($savePath, '.');
		$extension = fix_strtolower($extension);

		$error = '';

		switch ($extension)
		{
			case '.jpg':
			case '.jpeg':
				$this->checkInterlaceImage($this->isInterlace);
				if (imagetypes() & IMG_JPG)
				{
					imagejpeg($this->imageResized, $savePath, $imageQuality);
				}
				else
				{
					$error = 'jpg';
				}
				break;

			case '.gif':
				$this->checkInterlaceImage($this->isInterlace);
				if (imagetypes() & IMG_GIF)
				{
					imagegif($this->imageResized, $savePath);
				}
				else
				{
					$error = 'gif';
				}
				break;

			case '.png':
				// *** Scale quality from 0-100 to 0-9
				$scaleQuality = round(($imageQuality / 100) * 9);

				// *** Invert qualit setting as 0 is best, not 9
				$invertScaleQuality = 9 - $scaleQuality;

				$this->checkInterlaceImage($this->isInterlace);
				if (imagetypes() & IMG_PNG)
				{
					imagepng($this->imageResized, $savePath, $invertScaleQuality);
				}
				else
				{
					$error = 'png';
				}
				break;

			case '.bmp':
				file_put_contents($savePath, $this->GD2BMPstring($this->imageResized));
				break;


			// ... etc

			default:
				// *** No extension - No save.
				$this->errorArray[] = 'This file type (' . $extension . ') is not supported. File not saved.';
				break;
		}

		//imagedestroy($this->imageResized);

		// *** Display error if a file type is not supported.
		if ($error != '')
		{
			$this->errorArray[] = $error . ' support is NOT enabled. File not saved.';
		}
	}

## --------------------------------------------------------

	public function displayImage($fileType = 'jpg', $imageQuality = "100")
		# Author:     Jarrod Oberto
		# Date:       18-11-09
		# Purpose:    Display images directly to the browser
		# Param in:   The image type you want to display
		# Param out:
		# Reference:
		# Notes:
		#
	{

		if ( ! is_resource($this->imageResized))
		{
			if ($this->debug)
			{
				throw new Exception('saveImage: This is not a resource.');
			}
			else
			{
				throw new Exception();
			}
		}

		switch ($fileType)
		{
			case 'jpg':
			case 'jpeg':
				header('Content-type: image/jpeg');
				imagejpeg($this->imageResized, '', $imageQuality);
				break;
			case 'gif':
				header('Content-type: image/gif');
				imagegif($this->imageResized);
				break;
			case 'png':
				header('Content-type: image/png');

				// *** Scale quality from 0-100 to 0-9
				$scaleQuality = round(($imageQuality / 100) * 9);

				// *** Invert qualit setting as 0 is best, not 9
				$invertScaleQuality = 9 - $scaleQuality;

				imagepng($this->imageResized, '', $invertScaleQuality);
				break;
			case 'bmp':
				echo 'bmp file format is not supported.';
				break;

			// ... etc

			default:
				// *** No extension - No save.
				break;
		}


		//imagedestroy($this->imageResized);
	}

## --------------------------------------------------------

	public function setTransparency($bool)
		# Sep 2011
	{
		$this->keepTransparency = $bool;
	}

## --------------------------------------------------------

	public function setFillColor($value)
		# Sep 2011
		# Param in:   (mixed) $value: (array) Could be an array of RGB
		#               (str) Could be hex #ffffff or #fff, fff, ffffff
		#
		# If the keepTransparency is set to false, then no transparency is to be used.
		# This is ideal when you want to save as jpg.
		#
		# this method allows you to set the background color to use instead of
		# transparency.
		#
	{
		$colorArray = $this->formatColor($value);
		$this->fillColorArray = $colorArray;
	}

## --------------------------------------------------------

	public function setCropFromTop($value)
		# Sep 2011
	{
		$this->cropFromTopPercent = $value;
	}

## --------------------------------------------------------

	public function testGDInstalled()
		# Author:     Jarrod Oberto
		# Date:       27-02-08
		# Purpose:    Test to see if GD is installed
		# Param in:   n/a
		# Param out:  (bool) True is gd extension loaded otherwise false
		# Reference:
		# Notes:
		#
	{
		if (extension_loaded('gd') && function_exists('gd_info'))
		{
			$gdInstalled = true;
		}
		else
		{
			$gdInstalled = false;
		}

		return $gdInstalled;
	}

## --------------------------------------------------------

	public function testEXIFInstalled()
		# Author:     Jarrod Oberto
		# Date:       08-05-11
		# Purpose:    Test to see if EXIF is installed
		# Param in:   n/a
		# Param out:  (bool) True is exif extension loaded otherwise false
		# Reference:
		# Notes:
		#
	{
		if (extension_loaded('exif'))
		{
			$exifInstalled = true;
		}
		else
		{
			$exifInstalled = false;
		}

		return $exifInstalled;
	}

## --------------------------------------------------------

	public function testIsImage($image)
		# Author:     Jarrod Oberto
		# Date:       27-02-08
		# Purpose:    Test if file is an image
		# Param in:   n/a
		# Param out:  n/a
		# Reference:
		# Notes:
		#
	{
		if ($image)
		{
			$fileIsImage = true;
		}
		else
		{
			$fileIsImage = false;
		}

		return $fileIsImage;
	}

## --------------------------------------------------------

	public function testFunct()
		# Author:     Jarrod Oberto
		# Date:       27-02-08
		# Purpose:    Test Function
		# Param in:   n/a
		# Param out:  n/a
		# Reference:
		# Notes:
		#
	{
		echo $this->height;
	}

## --------------------------------------------------------

	public function setForceStretch($value)
		# Author:     Jarrod Oberto
		# Date:       23-12-10
		# Purpose:
		# Param in:   (bool) $value
		# Param out:  n/a
		# Reference:
		# Notes:
		#
	{
		$this->forceStretch = $value;
	}

## --------------------------------------------------------

	public function setFile($fileName)
		# Author:     Jarrod Oberto
		# Date:       28-02-08
		# Purpose:
		# Param in:   n/a
		# Param out:  n/a
		# Reference:
		# Notes:
		#
	{
		self::__construct($fileName);
	}

## --------------------------------------------------------

	public function getFileName()
		# Author:     Jarrod Oberto
		# Date:       10-09-08
		# Purpose:
		# Param in:   n/a
		# Param out:  n/a
		# Reference:
		# Notes:
		#
	{
		return $this->fileName;
	}

## --------------------------------------------------------

	public function getHeight()
	{
		return $this->height;
	}

## --------------------------------------------------------

	public function getWidth()
	{
		return $this->width;
	}

## --------------------------------------------------------

	public function getOriginalHeight()
	{
		return $this->heightOriginal;
	}

## --------------------------------------------------------

	public function getOriginalWidth()
	{
		return $this->widthOriginal;
	}

## --------------------------------------------------------

	public function getErrors()
		# Author:     Jarrod Oberto
		# Date:       19-11-09
		# Purpose:    Returns the error array
		# Param in:   n/a
		# Param out:  Array of errors
		# Reference:
		# Notes:
		#
	{
		return $this->errorArray;
	}

## --------------------------------------------------------

	private function checkInterlaceImage($isEnabled)
		# jpg will use progressive (they don't use interace)
	{
		if ($isEnabled)
		{
			imageinterlace($this->imageResized, $isEnabled);
		}
	}

## --------------------------------------------------------

	protected function formatColor($value)
		# Author:     Jarrod Oberto
		# Date:       09-05-11
		# Purpose:    Determine color method passed in and return color as RGB
		# Param in:   (mixed) $value: (array) Could be an array of RGB
		#               (str) Could be hex #ffffff or #fff, fff, ffffff
		# Param out:
		# Reference:
		# Notes:
		#
	{
		$rgbArray = array();

		// *** If it's an array it should be R, G, B
		if (is_array($value))
		{

			if (key($value) == 0 && count($value) == 3)
			{

				$rgbArray['r'] = $value[0];
				$rgbArray['g'] = $value[1];
				$rgbArray['b'] = $value[2];

			}
			else
			{
				$rgbArray = $value;
			}
		}
		else
		{
			if (fix_strtolower($value) == 'transparent')
			{

				$rgbArray = array(
					'r' => 255,
					'g' => 255,
					'b' => 255,
					'a' => 127
				);

			}
			else
			{

				// *** ...Else it should be hex. Let's make it RGB
				$rgbArray = $this->hex2dec($value);
			}
		}

		return $rgbArray;
	}

	## --------------------------------------------------------

	function hex2dec($hex)
		# Purpose:  Convert #hex color to RGB
	{
		$color = str_replace('#', '', $hex);

		if (strlen($color) == 3)
		{
			$color = $color . $color;
		}

		$rgb = array(
			'r' => hexdec(substr($color, 0, 2)),
			'g' => hexdec(substr($color, 2, 2)),
			'b' => hexdec(substr($color, 4, 2)),
			'a' => 0
		);

		return $rgb;
	}

	## --------------------------------------------------------

	private function createImageColor($colorArray)
	{
		$r = $colorArray['r'];
		$g = $colorArray['g'];
		$b = $colorArray['b'];

		return imagecolorallocate($this->imageResized, $r, $g, $b);
	}

	## --------------------------------------------------------

	private function testColorExists($colorArray)
	{
		$r = $colorArray['r'];
		$g = $colorArray['g'];
		$b = $colorArray['b'];

		if (imagecolorexact($this->imageResized, $r, $g, $b) == -1)
		{
			return false;
		}
		else
		{
			return true;
		}
	}

	## --------------------------------------------------------

	private function findUnusedGreen()
		# Purpose:  We find a green color suitable to use like green-screen effect.
		#     Therefore, the color must not exist in the image.
	{
		$green = 255;

		do
		{

			$greenChroma = array( 0, $green, 0 );
			$colorArray = $this->formatColor($greenChroma);
			$match = $this->testColorExists($colorArray);
			$green--;

		} while ($match == false && $green > 0);

		// *** If no match, just bite the bullet and use green value of 255
		if ( ! $match)
		{
			$greenChroma = array( 0, $green, 0 );
		}

		return $greenChroma;
	}

	## --------------------------------------------------------

	private function findUnusedBlue()
		# Purpose:  We find a green color suitable to use like green-screen effect.
		#     Therefore, the color must not exist in the image.
	{
		$blue = 255;

		do
		{

			$blueChroma = array( 0, 0, $blue );
			$colorArray = $this->formatColor($blueChroma);
			$match = $this->testColorExists($colorArray);
			$blue--;

		} while ($match == false && $blue > 0);

		// *** If no match, just bite the bullet and use blue value of 255
		if ( ! $match)
		{
			$blueChroma = array( 0, 0, $blue );
		}

		return $blueChroma;
	}

	## --------------------------------------------------------

	private function invertTransparency($value, $originalMax, $invert = true)
		# Purpose:  This does two things:
		#       1) Convert the range from 0-127 to 0-100
		#       2) Inverts value to 100 is not transparent while 0 is fully
		#          transparent (like Photoshop)
	{
		// *** Test max range
		if ($value > $originalMax)
		{
			$value = $originalMax;
		}

		// *** Test min range
		if ($value < 0)
		{
			$value = 0;
		}

		if ($invert)
		{
			return $originalMax - (($value / 100) * $originalMax);
		}
		else
		{
			return ($value / 100) * $originalMax;
		}
	}

	## --------------------------------------------------------

	private function transparentImage($src)
	{
		// *** making images with white bg transparent
		$r1 = 0;
		$g1 = 255;
		$b1 = 0;
		for ($x = 0; $x < imagesx($src); ++$x)
		{
			for ($y = 0; $y < imagesy($src); ++$y)
			{
				$color = imagecolorat($src, $x, $y);
				$r = ($color >> 16) & 0xFF;
				$g = ($color >> 8) & 0xFF;
				$b = $color & 0xFF;
				for ($i = 0; $i < 270; $i++)
				{
					//if ($r . $g . $b == ($r1 + $i) . ($g1 + $i) . ($b1 + $i)) {
					if ($r == 0 && $g == 255 && $b == 0)
					{
						//if ($g == 255) {
						$trans_colour = imagecolorallocatealpha($src, 0, 0, 0, 127);
						imagefill($src, $x, $y, $trans_colour);
					}
				}
			}
		}

		return $src;
	}

	## --------------------------------------------------------

	function checkStringStartsWith($needle, $haystack)
		# Check if a string starts with a specific pattern
	{
		return (substr($haystack, 0, strlen($needle)) == $needle);
	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  BMP SUPPORT (SAVING) - James Heinrich
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	private function GD2BMPstring(&$gd_image)
		# Author:     James Heinrich
		# Purpose:    Save file as type bmp
		# Param in:   The image canvas (passed as ref)
		# Param out:
		# Reference:
		# Notes:    This code was stripped out of two external files
		#       (phpthumb.bmp.php,phpthumb.functions.php) and added below to
		#       avoid dependancies.
		#
	{
		$imageX = ImageSX($gd_image);
		$imageY = ImageSY($gd_image);

		$BMP = '';
		for ($y = ($imageY - 1); $y >= 0; $y--)
		{
			$thisline = '';
			for ($x = 0; $x < $imageX; $x++)
			{
				$argb = $this->GetPixelColor($gd_image, $x, $y);
				$thisline .= chr($argb['blue']) . chr($argb['green']) . chr($argb['red']);
			}
			while (strlen($thisline) % 4)
			{
				$thisline .= "\x00";
			}
			$BMP .= $thisline;
		}

		$bmpSize = strlen($BMP) + 14 + 40;
		// BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp
		$BITMAPFILEHEADER = 'BM';                                    // WORD    bfType;
		$BITMAPFILEHEADER .= $this->LittleEndian2String($bmpSize, 4); // DWORD   bfSize;
		$BITMAPFILEHEADER .= $this->LittleEndian2String(0, 2); // WORD    bfReserved1;
		$BITMAPFILEHEADER .= $this->LittleEndian2String(0, 2); // WORD    bfReserved2;
		$BITMAPFILEHEADER .= $this->LittleEndian2String(54, 4); // DWORD   bfOffBits;

		// BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp
		$BITMAPINFOHEADER = $this->LittleEndian2String(40, 4); // DWORD  biSize;
		$BITMAPINFOHEADER .= $this->LittleEndian2String($imageX, 4); // LONG   biWidth;
		$BITMAPINFOHEADER .= $this->LittleEndian2String($imageY, 4); // LONG   biHeight;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(1, 2); // WORD   biPlanes;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(24, 2); // WORD   biBitCount;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD  biCompression;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD  biSizeImage;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(2835, 4); // LONG   biXPelsPerMeter;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(2835, 4); // LONG   biYPelsPerMeter;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD  biClrUsed;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD  biClrImportant;

		return $BITMAPFILEHEADER . $BITMAPINFOHEADER . $BMP;
	}

## --------------------------------------------------------

	private function GetPixelColor(&$img, $x, $y)
		# Author:     James Heinrich
		# Purpose:
		# Param in:
		# Param out:
		# Reference:
		# Notes:
		#
	{
		if ( ! is_resource($img))
		{
			return false;
		}

		return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
	}

## --------------------------------------------------------

	private function LittleEndian2String($number, $minbytes = 1)
		# Author:     James Heinrich
		# Purpose:    BMP SUPPORT (SAVING)
		# Param in:
		# Param out:
		# Reference:
		# Notes:
		#
	{
		$intstring = '';
		while ($number > 0)
		{
			$intstring = $intstring . chr($number & 255);
			$number >>= 8;
		}

		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  BMP SUPPORT (READING)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	private function ImageCreateFromBMP($filename)
		# Author:     DHKold
		# Date:     The 15th of June 2005
		# Version:    2.0B
		# Purpose:    To create an image from a BMP file.
		# Param in:   BMP file to open.
		# Param out:  Return a resource like the other ImageCreateFrom functions
		# Reference:  http://us3.php.net/manual/en/function.imagecreate.php#53879
		# Bug fix:    Author:   domelca at terra dot es
		#       Date:   06 March 2008
		#       Fix:    Correct 16bit BMP support
		# Notes:
		#
	{

		//Ouverture du fichier en mode binaire
		if ( ! $f1 = fopen($filename, "rb"))
		{
			return false;
		}

		//1 : Chargement des ent�tes FICHIER
		$FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1, 14));
		if ($FILE['file_type'] != 19778)
		{
			return false;
		}

		//2 : Chargement des ent�tes BMP
		$BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel' .
			'/Vcompression/Vsize_bitmap/Vhoriz_resolution' .
			'/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40));
		$BMP['colors'] = pow(2, $BMP['bits_per_pixel']);

		if ($BMP['size_bitmap'] == 0)
		{
			$BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
		}

		$BMP['bytes_per_pixel'] = $BMP['bits_per_pixel'] / 8;
		$BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']);
		$BMP['decal'] = ($BMP['width'] * $BMP['bytes_per_pixel'] / 4);
		$BMP['decal'] -= floor($BMP['width'] * $BMP['bytes_per_pixel'] / 4);
		$BMP['decal'] = 4 - (4 * $BMP['decal']);

		if ($BMP['decal'] == 4)
		{
			$BMP['decal'] = 0;
		}

		//3 : Chargement des couleurs de la palette
		$PALETTE = array();
		if ($BMP['colors'] < 16777216)
		{
			$PALETTE = unpack('V' . $BMP['colors'], fread($f1, $BMP['colors'] * 4));
		}

		//4 : Cr�ation de l'image
		$IMG = fread($f1, $BMP['size_bitmap']);
		$VIDE = chr(0);

		$res = imagecreatetruecolor($BMP['width'], $BMP['height']);
		$P = 0;
		$Y = $BMP['height'] - 1;
		while ($Y >= 0)
		{
			$X = 0;
			while ($X < $BMP['width'])
			{
				if ($BMP['bits_per_pixel'] == 24)
				{
					$COLOR = unpack("V", substr($IMG, $P, 3) . $VIDE);
				}
				elseif ($BMP['bits_per_pixel'] == 16)
				{

					/*
           * BMP 16bit fix
           * =================
           *
           * Ref: http://us3.php.net/manual/en/function.imagecreate.php#81604
           *
           * Notes:
           * "don't work with bmp 16 bits_per_pixel. change pixel
           * generator for this."
           *
           */

					// *** Original code (don't work)
					//$COLOR = unpack("n",substr($IMG,$P,2));
					//$COLOR[1] = $PALETTE[$COLOR[1]+1];

					$COLOR = unpack("v", substr($IMG, $P, 2));
					$blue = ($COLOR[1] & 0x001f) << 3;
					$green = ($COLOR[1] & 0x07e0) >> 3;
					$red = ($COLOR[1] & 0xf800) >> 8;
					$COLOR[1] = $red * 65536 + $green * 256 + $blue;

				}
				elseif ($BMP['bits_per_pixel'] == 8)
				{
					$COLOR = unpack("n", $VIDE . substr($IMG, $P, 1));
					$COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
				}
				elseif ($BMP['bits_per_pixel'] == 4)
				{
					$COLOR = unpack("n", $VIDE . substr($IMG, floor($P), 1));
					if (($P * 2) % 2 == 0)
					{
						$COLOR[1] = ($COLOR[1] >> 4);
					}
					else
					{
						$COLOR[1] = ($COLOR[1] & 0x0F);
					}
					$COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
				}
				elseif ($BMP['bits_per_pixel'] == 1)
				{
					$COLOR = unpack("n", $VIDE . substr($IMG, floor($P), 1));
					if (($P * 8) % 8 == 0)
					{
						$COLOR[1] = $COLOR[1] >> 7;
					}
					elseif (($P * 8) % 8 == 1)
					{
						$COLOR[1] = ($COLOR[1] & 0x40) >> 6;
					}
					elseif (($P * 8) % 8 == 2)
					{
						$COLOR[1] = ($COLOR[1] & 0x20) >> 5;
					}
					elseif (($P * 8) % 8 == 3)
					{
						$COLOR[1] = ($COLOR[1] & 0x10) >> 4;
					}
					elseif (($P * 8) % 8 == 4)
					{
						$COLOR[1] = ($COLOR[1] & 0x8) >> 3;
					}
					elseif (($P * 8) % 8 == 5)
					{
						$COLOR[1] = ($COLOR[1] & 0x4) >> 2;
					}
					elseif (($P * 8) % 8 == 6)
					{
						$COLOR[1] = ($COLOR[1] & 0x2) >> 1;
					}
					elseif (($P * 8) % 8 == 7)
					{
						$COLOR[1] = ($COLOR[1] & 0x1);
					}
					$COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
				}
				else
				{
					return false;
				}

				imagesetpixel($res, $X, $Y, $COLOR[1]);
				$X++;
				$P += $BMP['bytes_per_pixel'];
			}

			$Y--;
			$P += $BMP['decal'];
		}
		//Fermeture du fichier
		fclose($f1);

		return $res;
	}


	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
  PSD SUPPORT (READING)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/

	private function imagecreatefrompsd($fileName)
		# Author:     Tim de Koning
		# Version:    1.3
		# Purpose:    To create an image from a PSD file.
		# Param in:   PSD file to open.
		# Param out:  Return a resource like the other ImageCreateFrom functions
		# Reference:  http://www.kingsquare.nl/phppsdreader
		# Notes:
		#
	{
		if (file_exists($this->psdReaderPath))
		{


			include_once($this->psdReaderPath);

			$psdReader = new PhpPsdReader($fileName);

			if (isset($psdReader->infoArray['error']))
			{
				return '';
			}
			else
			{
				return $psdReader->getImage();
			}
		}
		else
		{
			return false;
		}
	}

## --------------------------------------------------------

	public function __destruct()
	{
		if (is_resource($this->imageResized))
		{
			imagedestroy($this->imageResized);
		}
	}

## --------------------------------------------------------

}


/*
 *    Example with some API calls (outdated):
 *
 *
 *      ===============================
 *      Compulsary
 *      ===============================
 *
 *      include("classes/resize_class.php");
 *
 *      // *** Initialise object
 *      $magicianObj = new resize('images/cars/large/a.jpg');
 *
 *      // *** Turn off stretching (optional)
 *      $magicianObj -> setForceStretch(false);
 *
 *      // *** Resize object
 *      $magicianObj -> resizeImage(150, 100, 0);
 *
 *      ===============================
 *      Image options - can run none, one, or all.
 *      ===============================
 *
 *      //  *** Add watermark
 *        $magicianObj -> addWatermark('stamp.png');
 *
 *          // *** Add text
 *      $magicianObj -> addText('testing...');
 *
 *      ===============================
 *      Output options - can run one, or the other, or both.
 *      ===============================
 *
 *      // *** Save image to disk
 *      $magicianObj -> saveImage('images/cars/large/b.jpg', 100);
 *
 *          // *** Or output to screen (params in can be jpg, gif, png)
 *      $magicianObj -> displayImage('png');
 *
 *      ===============================
 *      Return options - return errors. nice for debuggin.
 *      ===============================
 *
 *      // *** Return error array
 *      $errorArray = $magicianObj -> getErrors();
 *
 *
 *      ===============================
 *      Cleanup options - not really neccessary, but good practice
 *      ===============================
 *
 *      // *** Free used memory
 *      $magicianObj -> __destruct();
 */

Youez - 2016 - github.com/yon3zu
LinuXploit