Jump to content

need help to modify php code

- - - - -

  • Please log in to reply
No replies to this topic

#1
cyber_phoenix

cyber_phoenix

    Newbie

  • Members
  • Pip
  • 1 posts
its a code for thombnail creation it has a max width and height and it doesent allow uploads smaller than that please help i want to create thumbnails 140x180 how can i do it ?
here is the php code

	$id = wp_insert_attachment($attachment, $file, $post);

			



			$imagesize = getimagesize($file);

			$imagedata['width'] = $imagesize['0'];

			$imagedata['height'] = $imagesize['1'];

			list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);

			$imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";

			$imagedata['file'] = $file;

		

			add_post_meta($id, '_wp_attachment_metadata', $imagedata);

			$url = str_replace(get_bloginfo('url'),'',$url);


			$MaxWidth = 182;  //设置图片宽度界限

			$MaxHeight = 110; //设置图片高度界限


			if(($imagedata['width']/$imagedata['height'])>($MaxWidth/$MaxHeight)){

				$maxsize=($imagedata['width']*$MaxHeight)/$imagedata['height'];


			}else{

				

				$thumbnailwidth=$MaxWidth;

				$thumbnailheight=$MaxWidth*$imagedata['height']/$imagedata['width'];

				if($thumbnailwidth>$thumbnailheight)

					$maxsize=$thumbnailwidth;

				else

					$maxsize=$thumbnailheight;


			}





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users