how can we minus 15 pixel from fitting image in this code ?

Thread Solved

Join Date: Dec 2009
Posts: 29
Reputation: fuchsia555 is an unknown quantity at this point 
Solved Threads: 0
fuchsia555 fuchsia555 is offline Offline
Light Poster

how can we minus 15 pixel from fitting image in this code ?

 
0
  #1
Dec 13th, 2009
hi
how can we minus 15 pixel from bottom height in fitting for create thumbnails from original image in this code ? i mean how can tell php that capture from original image the ( all width ) and ( all height - 15 pixel from bottom )


  1. # #create thumb
  2. # $thumb = gd_fit($image,$settings['thumbxy']);
  3.  
  4.  
  5.  
  6. # function gd_fit(&$image, $target) {
  7. #
  8. # //takes the larger size of the width and height and applies the
  9. # //formula accordingly...this is so this script will work
  10. # //dynamically with any size image
  11. #
  12. # $width = gd_width($image);
  13. # $height = gd_height($image);
  14. #
  15. # if ($width > $height) {
  16. # $percentage = ($target / $width);
  17. # } else {
  18. # $percentage = ($target / $height);
  19. # }
  20. #
  21. # //gets the new value and applies the percentage, then rounds the value
  22. # $width = round($width * $percentage);
  23. # $height = round($height * $percentage);
  24. #
  25. # //returns the new sizes in html image tag format...this is so you
  26. # //can plug this function inside an image tag
  27. #
  28. # return gd_resize($image,$width,$height);
  29. #
  30. # }
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,545
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 203
Sponsor
ardav's Avatar
ardav ardav is online now Online
Anthrax Poster
 
0
  #2
Dec 13th, 2009
Try this - I messed around with it for a while, but I'm sure it could be further optimized - perhaps with just the one imagecopyresampled - but my head's fried.

  1. <?php
  2. function CutThumb($img){
  3. //set variables
  4. $crop = 15;
  5. $thumb_w = 100;
  6. $thumb_h = 100;
  7. //get info from original image
  8. list($w, $h) = getimagesize($img);
  9. //make image a resource for use in functions
  10. $img_r = imagecreatefromjpeg($img);
  11. //make image containers for functions
  12. $cut = imagecreatetruecolor($w,$h-$crop);
  13. $thumb = imagecreatetruecolor($thumb_w,$thumb_h);
  14. //crop the original image
  15. imagecopyresampled($cut,$img_r,0,0,0,0,$w,$h,$w,$h-$crop);
  16. //resize the image
  17. imagecopyresampled($thumb,$cut,0,0,0,0,$thumb_w,$thumb_h,$w,$h-$crop);
  18. //release memory
  19. imagedestroy($img_r);
  20. imagedestroy($cut);
  21. //return image
  22. return $thumb;
  23. }
  24.  
  25. //Create the thumbnail - this could be in any file if the function above is included
  26. $MyCutThumb = CutThumb("burton.jpg");
  27. // Display image
  28. header('Content-type: image/jpeg');
  29. imagejpeg($MyCutThumb);
  30. ?>

BTW - I left out any "constrain proportions" code.
Last edited by ardav; Dec 13th, 2009 at 6:27 pm.
Twpsyn cythraul. Cawr y dom tarw. Gwybod dim, gofyn dim.
Reply With Quote Quick reply to this message  
Join Date: Dec 2009
Posts: 29
Reputation: fuchsia555 is an unknown quantity at this point 
Solved Threads: 0
fuchsia555 fuchsia555 is offline Offline
Light Poster
 
0
  #3
Dec 13th, 2009
hi dear ardav
Thanks for reply
but it would crop the original image , i just need it without affecting in the original image ?

i have the code above that my script working with it's using function gd_fit , it's fitting that image with variables , so can we try to edit this code to add $crop = 15 and minus it from height ? i don't know how to do it exactly
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,545
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 203
Sponsor
ardav's Avatar
ardav ardav is online now Online
Anthrax Poster
 
0
  #4
Dec 14th, 2009
Have to be honest - I don't really understand exactly what you want:

Do you just want to resize the image (height only)?
e.g. just take 15px off the height and don't worry about stretching the width

Do you just want to resize the height and keep the width in proportion?
e.g. take 15 px off the height of the image and scale the width accordingly


Do you need to crop the image? I assume not from your last post.
Twpsyn cythraul. Cawr y dom tarw. Gwybod dim, gofyn dim.
Reply With Quote Quick reply to this message  
Join Date: Dec 2009
Posts: 29
Reputation: fuchsia555 is an unknown quantity at this point 
Solved Threads: 0
fuchsia555 fuchsia555 is offline Offline
Light Poster
 
0
  #5
Dec 14th, 2009
Thanks Dear ardav for reply

i just want to crop 15 pixel from the thumbnails only not the original image , why ? because all images i upload have my own watermark on the bottom this watermark size 15 pixel in the bottom , and i just want that watermark disappear in ( thumbnails only)
can i send you the script to take a look ?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,545
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 203
Sponsor
ardav's Avatar
ardav ardav is online now Online
Anthrax Poster
 
0
  #6
Dec 14th, 2009
Originally Posted by fuchsia555 View Post
Thanks Dear ardav for reply

i just want to crop 15 pixel from the thumbnails only not the original image , why ? because all images i upload have my own watermark on the bottom this watermark size 15 pixel in the bottom , and i just want that watermark disappear in ( thumbnails only)
can i send you the script to take a look ?
By all means, as long as it is posted to the forum. I do not accept PMs. Anyway, I can't promise to help and perhaps another member can give better advice.


What we need to know is the nature of your thumbnail - is it set as a %age of a width or height or is it set to a certain pixel height or width. AND is it "constrained" (scaled to proportion)?

Your solution will be similar to the one I suggested, except that the resizing is completed first and then the cropping (opposite to my suggestion).
Twpsyn cythraul. Cawr y dom tarw. Gwybod dim, gofyn dim.
Reply With Quote Quick reply to this message  
Join Date: Dec 2009
Posts: 29
Reputation: fuchsia555 is an unknown quantity at this point 
Solved Threads: 0
fuchsia555 fuchsia555 is offline Offline
Light Poster
 
0
  #7
Dec 14th, 2009
hi this is the script i'm using
http://rapidshare.com/files/320757609/im1_1.zip.html

i think that
creating thumbnail code in upload.php ( $thumb = gd_fit($image,$settings['thumbxy']); )
and functions located in includes folder , and gd_fit function that thumbnail using in dpi_ext.php
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,545
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 203
Sponsor
ardav's Avatar
ardav ardav is online now Online
Anthrax Poster
 
0
  #8
Dec 14th, 2009
Sorry F, I'm not going to download them. If you want to post the relevant bits, we'll have a look.
Twpsyn cythraul. Cawr y dom tarw. Gwybod dim, gofyn dim.
Reply With Quote Quick reply to this message  
Join Date: Dec 2009
Posts: 29
Reputation: fuchsia555 is an unknown quantity at this point 
Solved Threads: 0
fuchsia555 fuchsia555 is offline Offline
Light Poster
 
0
  #9
Dec 14th, 2009
ok dear i will copy codes that i think involved with the issue

here that in uploud.php
  1. #create thumb
  2. $thumb = gd_fit($image,$settings['thumbxy']);
  3.  
  4. #Accomodate image options
  5. if(isset($_REQUEST['border']) || isset($_POST['border']))
  6. gd_rectangle($image,0,0,gd_width($image)-1,gd_height($image)-1,"000000");
  7. if(isset($_REQUEST['bordert']) || isset($_POST['bordert']))
  8. gd_rectangle($thumb,0,0,gd_width($thumb)-1,gd_height($thumb)-1,"000000");
  9.  
  10.  
  11. #save thmb first
  12. imagejpeg($thumb,"$th/$id.jpg",$settings['thumbuality']);
  13. imagedestroy($thumb);
  14. #then save actual jpeg
  15. imagejpeg($image,"$im/$id.jpg",$settings['quality']);
  16. imagedestroy($image);
  17.  
  18. $iptc = new iptc("$im/$id.jpg");
  19. if($cimg[0] == 1) {
  20. #it is gif keep in data
  21. write_file("$im/$id.jpg",load_file("$th/$id.jpg"));
  22. write_file("$im/$id.gif",$cimg[1]);
  23. $iptc->set(DPI_GIF,"GIF");
  24. }

functions that in dpi_ext.php (and think it's involved with the issue

  1.  
  2.  
  3. function gd_fit(&$image, $target) {
  4.  
  5. //takes the larger size of the width and height and applies the
  6. //formula accordingly...this is so this script will work
  7. //dynamically with any size image
  8.  
  9. $width = gd_width($image);
  10. $height = gd_height($image);
  11.  
  12. if ($width > $height) {
  13. $percentage = ($target / $width);
  14. } else {
  15. $percentage = ($target / $height);
  16. }
  17.  
  18. //gets the new value and applies the percentage, then rounds the value
  19. $width = round($width * $percentage);
  20. $height = round($height * $percentage);
  21.  
  22. //returns the new sizes in html image tag format...this is so you
  23. //can plug this function inside an image tag and just get the
  24.  
  25. return gd_resize($image,$width,$height);
  26.  
  27. }
  28. function gd_getfit(&$image, $target) {
  29.  
  30. //takes the larger size of the width and height and applies the
  31. //formula accordingly...this is so this script will work
  32. //dynamically with any size image
  33.  
  34. $width = gd_width($image);
  35. $height = gd_height($image);
  36.  
  37. if ($width > $height) {
  38. $percentage = ($target / $width);
  39. } else {
  40. $percentage = ($target / $height);
  41. }
  42.  
  43. //gets the new value and applies the percentage, then rounds the value
  44. $width = round($width * $percentage);
  45. $height = round($height * $percentage);
  46.  
  47. //returns the new sizes in html image tag format...this is so you
  48. //can plug this function inside an image tag and just get the
  49.  
  50. return Array('width'=>$width,'height'=>$height);
  51.  
  52. }
  53.  
  54. function gd_width(&$image) {
  55. return imagesx($image);
  56. }
  57. function gd_height(&$image) {
  58. return imagesy($image);
  59. }
  60.  
  61. function gd_imagewidth($fname) {
  62. list($width, $height) = getimagesize($fname);
  63. return $width;
  64. }
  65. function gd_imageheight($fname) {
  66. list($width, $height) = getimagesize($fname);
  67. return $height;
  68. }
  69.  
  70. function gd_fit_bg(&$img,$fit=100,$color="FFFFFF") {
  71. $w = imageSX($img);
  72. $h = imageSY($img);
  73. $img2 = gd_newimage($fit,$fit);
  74. gd_bar($img2,0,0,$fit,$fit,$color);
  75.  
  76. $x = ($fit-$w)/2;
  77. $y = ($fit-$h)/2;
  78.  
  79. imagecopy($img2, $img, $x,$y, 0, 0, $w, $h);
  80. return $img2;
  81. }
  82.  
  83. function gd_resize(&$image,$w,$h) {
  84. $ret=@imagecreatetruecolor($w, $h);
  85. @imagecopyresampled ($ret,$image, 0, 0, 0, 0, $w, $h, imagesx($image), imagesy($image));
  86.  
  87. return $ret;
  88. }

other functions in dpi_ext.php
  1.  
  2. function dpi_supported($file) {
  3. $DPI_IMAGE_TYPES = Array(1,2,3,10);
  4. $size = @getimagesize($file);
  5. if(!$size) return false;
  6. return in_array($size[2],$DPI_IMAGE_TYPES) ? $size[2] : false;
  7. }
  8.  
  9.  
  10. function scanlines_h(&$image,$line_gap=1,$opacity=100) {
  11. $w = imagesx($image);
  12. $h = imagesy($image);
  13. $ret = imagecreatetruecolor($w,$h);
  14. $line_gap++;
  15.  
  16. for ($y = 1; $y < $h; $y += $line_gap)
  17. imagecopymerge($ret, $image, 0, $y, 0, $y, $w, 1,$opacity);
  18.  
  19. return $ret;
  20. }
  21. function scanlines_v(&$image,$line_gap=1,$opacity=100) {
  22. $w = imagesx($image);
  23. $h = imagesy($image);
  24. $ret = imagecreatetruecolor($w,$h);
  25. $line_gap++;
  26.  
  27. for ($x = 1; $x < $w; $x += $line_gap)
  28. imagecopymerge($ret, $image, $x, 0, $x, 0, 1, $h,$opacity);
  29.  
  30. return $ret;
  31. }
  32. function shear_r(&$image,$pers=50,$bgcolor="FFFFFF") {
  33. $w = imagesx($image);
  34. $h = imagesy($image);
  35. $ret = imagecreatetruecolor($w,$h);
  36. gd_bar($ret,0,0,$w,$h,$bgcolor);
  37. $z=0;
  38. $pers = 100-$pers;
  39. $pers /=100;
  40. $p1 = $h * $pers;
  41.  
  42. $gap = $p1 / $w;
  43.  
  44. for ($x = 0; $x < $w; $x++,$z+=$gap)
  45. imagecopyresampled (
  46. $ret, #resource dst_im,
  47. $image, #resource src_im,
  48. $x, #int dstX,
  49. ($h-($h-$z))/2, #int dstY,
  50. $x, #int srcX,
  51. 0, #int srcY,
  52. 1, #int dstW,
  53. $h-$z, #int dstH,
  54. 1, #int srcW,
  55. $h #int srcH
  56. );
  57.  
  58. return $ret;
  59. }
  60. function shear_l(&$image,$pers=50,$bgcolor="FFFFFF") {
  61. $w = imagesx($image);
  62. $h = imagesy($image);
  63. $ret = imagecreatetruecolor($w,$h);
  64. gd_bar($ret,0,0,$w,$h,$bgcolor);
  65. $z=0;
  66. $pers = 100-$pers;
  67. $pers /=100;
  68. $p1 = $h * $pers;
  69.  
  70. $gap = $p1 / $w;
  71.  
  72. for ($x = $w-1; $x >= 0; $x--,$z+=$gap)
  73. imagecopyresampled (
  74. $ret, #resource dst_im,
  75. $image, #resource src_im,
  76. $x, #int dstX,
  77. ($h-($h-$z))/2, #int dstY,
  78. $x, #int srcX,
  79. 0, #int srcY,
  80. 1, #int dstW,
  81. $h-$z, #int dstH,
  82. 1, #int srcW,
  83. $h #int srcH
  84. );
  85.  
  86. return $ret;
  87. }
  88.  
  89. function load_dpi_image($name) {
  90. $name = str_replace(".jpg","",$name);
  91. @list($u,$d) = @explode("_",$name);
  92.  
  93. $decdate = @hexdec($d);
  94. return @imagecreatefromstring(load_file(IMAGE_DIR.'/images/'.@date("Y/F/d",$decdate)."/$name.jpg"));
  95. }
  96.  
  97.  
  98. function gd_flip_h(&$image) {
  99. $ret = gd_newimage(imagesx($image),imagesy($image));
  100. $w = imagesx($image);
  101. $h = imagesy($image);
  102. for ($x = 0; $x < $w; $x++)
  103. imagecopy($ret, $image, $w - $x - 1, 0, $x, 0, 1, $h);
  104.  
  105. return $ret;
  106. }
  107. function gd_flip_v(&$image) {
  108. $ret = gd_newimage(imagesx($image),imagesy($image));
  109. $w = imagesx($image);
  110. $h = imagesy($image);
  111. for ($x = 0; $x < $h; $x++)
  112. imagecopy($ret, $image, 0, $h - $x - 1, 0, $x, $w, 1);
  113. return $ret;
  114. }
  115. function gd_rotate(&$img,$ang=90,$col="FFFFFF") {
  116. $col = gd_hexgd($img,$col);
  117. return imagerotate($img,$ang,$col);
  118. }
  119.  
  120. function gd_3db_watermark(&$img,$filepath) {
  121.  
  122. $w = imageSX($img);
  123. $h = imageSY($img);
  124. $img2 = imagecreatefromstring(load_file($filepath));
  125. $ww = imageSX($img2);
  126. $wh = imageSY($img2);
  127. $x = ($w-$ww)/2;
  128. $y = ($h-$wh)/2;
  129.  
  130. imagecopy($img, $img2, $x, $y, 0, 0, $ww, $wh);
  131. return $img;
  132. }
  133. function gd_set_bg(&$img,$color="FFFFFF") {
  134. $w = imageSX($img);
  135. $h = imageSY($img);
  136. $img2 = gd_newimage($w,$h);
  137. gd_bar($img2,0,0,$w,$h,$color);
  138. imagecopy($img2, $img, 0, 0, 0, 0, $w, $h);
  139. return $img2;
  140. }
  141.  
  142. function gd_hexgd(&$image,$hex) {
  143. $R = hexdec(@$hex{0}.@$hex{1});
  144. $G = hexdec(@$hex{2}.@$hex{3});
  145. $B = hexdec(@$hex{4}.@$hex{5});
  146.  
  147. return imagecolorallocate ($image, $R, $G, $B);
  148. }
  149. function gd_bar(&$image,$x=0,$y=0,$width,$height,$color="FFFFFF") {
  150. return imagefilledrectangle ($image, $x, $y, $x+$width, $y+$height, gd_hexgd($image,$color));
  151. }
  152.  
  153. function gd_text(&$image,$x,$y,$text,$color="000000",$font=2) {
  154.  
  155. //return imagettftext ( $image, 14, 0, $x, $y, gd_hexgd($image,$color), "./arial.ttf", $text);
  156.  
  157. return imagestring ($image, $font, $x, $y, $text, gd_hexgd($image,$color));
  158. }
  159. function gd_loadfont($fname) {
  160. $f = "./templates/gdf/$fname.gdf";
  161. if(!file_exists($f)) {
  162. echo "file not found - $f<br />";
  163. return false;
  164. }
  165. $fn = @imageloadfont($f);
  166. if($fn === FALSE) return false;
  167. return $fn;
  168. }
  169. function gd_textwidth($font=1,$text) {
  170. $ret= 0;
  171. if($text=='') return 0;
  172. return (imagefontwidth($font) * strlen($text));// - (imagefontwidth($font)/2);
  173. }
  174. function gd_textheight($font=1) {
  175. return imagefontheight($font);
  176. }
  177.  
  178. function gd_copy(&$image,$x,$y,$w,$h) {
  179. $ret=imagecreatetruecolor($w, $h);
  180. imagecopy($ret,$image, 0, 0, $x, $y, $w, $h);
  181.  
  182. return $ret;
  183. }
  184. function gd_paste(&$from,$to,$x=0,$y=0) {
  185. return imagecopymerge($to, $from, $x, $x, 0, 0, imagesx($from), imagesy($from), 100);
  186. }
  187.  
  188.  
  189. function gd_newimage($width,$height) {
  190. return imagecreatetruecolor($width, $height);
  191. }
  192. function gd_pixeltrans(&$image,$color) {
  193. return imagecolortransparent ($image, gd_hexgd($image,$color));
  194. }
  195.  
  196. function gd_line(&$image,$x,$y,$x2,$y2,$color="000000") {
  197. return imageline($image, $x,$y,$x2,$y2,gd_hexgd($image,$color));
  198. }
  199. function gd_rectangle(&$image,$x,$y,$w,$h,$color="000000") {
  200. $col = gd_hexgd($image,$color);
  201.  
  202. imageline($image, $x,$y,$x,$y+$h,$col); //left
  203. imageline($image, $x,$y,$x+$w,$y,$col); //top
  204. imageline($image, $x+$w,$y,$x+$w,$y+$h,$col); //right
  205. imageline($image, $x,$y+$h,$x+$w,$y+$h,$col); //bottom
  206.  
  207. return $image;
  208.  
  209. }
  210. function gd_filledellipse(&$image,$x,$y,$w,$h,$color="ff0000") {
  211. $col = gd_hexgd($image,$color);
  212. imagefilledellipse ( $image, $x, $y, $w, $h, $col);
  213. }
  214. function gd_ellipse(&$image,$x,$y,$w,$h,$color="ff0000") {
  215. $col = gd_hexgd($image,$color);
  216. imageellipse ( $image, $x, $y, $w, $h, $col);
  217. }
  218. function gd_loadimage($fname) { //ignore ext e.g. for xbm and xpm load jpg
  219. $arr = explode(".",$fname);
  220. $ext = strtolower($arr[count($arr)-1]);
  221. $func = 'imagecreatefrom';
  222. switch($ext) {
  223. case 'jpg' :
  224. case 'jpeg':
  225. case 'jpe' : $func .= 'jpeg'; break;
  226. case 'png' : $func .= 'png'; break;
  227. case 'gif' : $func .= 'gif'; break;
  228. case 'xbm' : $func .= 'xbm'; break;
  229. case 'wbmp': $func .= 'wbmp'; break;
  230.  
  231. /*case 'gif' : $func .= 'jpeg'; break;
  232. case 'xbm' : $func .= 'jpeg'; break;
  233. case 'xpm' : $func .= 'jpeg'; break;
  234. case 'wbmp': $func .= 'wbmp'; break;
  235. case 'bmp' : $func .= 'jpeg'; break;
  236. case 'ico' : $func .= 'png'; break;
  237. case 'cur' : $func .= 'jpeg'; break;
  238. case 'ani' : $func .= 'jpeg'; break;
  239. case 'txt' : $func .= 'jpeg'; break;*/
  240.  
  241.  
  242.  
  243. }
  244. if(!function_exists($func))
  245. return false;
  246.  
  247. $res = @$func($fname);;
  248. if(!$res)
  249. $res = @imagecreatefromjpeg($fname);
  250. if(!$res) return false;
  251.  
  252. return $res;
  253.  
  254. }
  255. function gd_loadimage_orig($fname) {
  256. if(!file_exists($fname)) return false;
  257.  
  258. $arr = explode(".",$fname);
  259. $ext = strtolower($arr[count($arr)-1]);
  260.  
  261. if($ext=='jpe' or $ext == 'jpg') $ext = 'jpeg';
  262.  
  263. $func = "imagecreatefrom$ext";
  264.  
  265. if(!function_exists($func))
  266. return false;
  267.  
  268. //return $func($fname,$ext=='ico'?16:'',$ext=='ico'?32:100);
  269. return $func($fname);
  270.  
  271. }
  272.  
  273.  
  274. function write_jpeg(&$image,$fname,$quality=100) {
  275. if (function_exists("imagejpeg"))
  276. return @imagejpeg($image,$fname,$quality);
  277. return false;
  278. }
  279. function write_png(&$image,$fname,$comp=9) {
  280. if (function_exists("imagejpng"))
  281. if (function_exists("imagejpng"))
  282. return @imagepng($image,$fname,$comp);
  283. return false;
  284. }
  285. function write_gif(&$image,$fname) {
  286. if (function_exists("imagegif"))
  287. return @imagegif($image,$fname);
  288. return false;
  289. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,545
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 203
Sponsor
ardav's Avatar
ardav ardav is online now Online
Anthrax Poster
 
0
  #10
Dec 14th, 2009
Firstly, have you contacted the author of the script to troubleshoot?
Secondly, do you really need all this functionality or are you just wanting to crop 15px off the thumbnail? If so, this script (or library!) is totally overkill.

To be honest, trawling through all that code is a pain. I'm afraid I don't have the time for all that. Sorry.
Twpsyn cythraul. Cawr y dom tarw. Gwybod dim, gofyn dim.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 842 | Replies: 17
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC