[wp-trac] [WordPress Trac] #28561: thumbnail when upload image
WordPress Trac
noreply at wordpress.org
Tue Jun 17 11:13:48 UTC 2014
#28561: thumbnail when upload image
--------------------------+------------------------------
Reporter: Stefan Oliwa | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 3.9.1
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Changes (by SergeyBiryukov):
* component: General => Media
Old description:
> Stop working after updates;
> One of our staff member report to me bug: problem with images in IE11.
> I didn't notice that in firefox or chrome because images was resize to
> width and height set in img tag => <img src="some image" width="300"
> height="180" alt.. >
> but physical size of image is different the image have 1900 pixels width
> and 1028 pixels height, and was weight approx 550kb, its really slow down
> a website when we listing wordpress posts with feature image (which is so
> big right now) and our case study.
>
> I fix this by adding own resizing function and simply class, I declare in
> blog
>
> instead of:
>
> the_post_thumbnail('medium', array('class' => 'media-object'));
>
> this:
>
> $get_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID));
> $local_small = Stefano_Resizer($get_url,300, 170);
>
> and in my theme functions.php:
>
> /RESIZE IMAGE
>
> class ResizeThat
> {
> var $image;
> var $image_type;
> function load($filename)
> {
> $image_info = getimagesize($filename);
> $this->image_type = $image_info[2];
> if ($this->image_type == IMAGETYPE_JPEG)
> {
> $this->image = imagecreatefromjpeg($filename);
> }
> elseif ($this->image_type == IMAGETYPE_GIF)
> {
> $this->image = imagecreatefromgif($filename);
> }
> elseif ($this->image_type == IMAGETYPE_PNG)
> {
> $this->image = imagecreatefrompng($filename);
> }
> }
>
> function save($filename, $image_type = IMAGETYPE_JPEG, $compression = 64,
> $permissions = null)
> {
> if ($image_type == IMAGETYPE_JPEG)
> {
> imagejpeg($this->image, $filename, $compression);
> }
> elseif ($image_type == IMAGETYPE_GIF)
> {
> imagegif($this->image, $filename);
> }
> elseif ($image_type == IMAGETYPE_PNG)
> {
> imagepng($this->image, $filename);
> }
>
> if ($permissions != null)
> {
> chmod($filename, $permissions);
> }
> }
>
> function output($image_type = IMAGETYPE_JPEG)
> {
> if ($image_type == IMAGETYPE_JPEG)
> {
> imagejpeg($this->image);
> }
> elseif ($image_type == IMAGETYPE_GIF)
> {
> imagegif($this->image);
> }
> elseif ($image_type == IMAGETYPE_PNG)
> {
> imagepng($this->image);
> }
> }
>
> function getWidth()
> {
> return imagesx($this->image);
> }
>
> function getHeight()
> {
> return imagesy($this->image);
> }
>
> function resizeToHeight($height)
> {
> $ratio = $height / $this->getHeight();
> $width = $this->getWidth() * $ratio;
> $this->resize($width, $height);
> }
>
> function resizeToWidth($width)
> {
> $ratio = $width / $this->getWidth();
> $height = $this->getheight() * $ratio;
> $this->resize($width, $height);
> }
>
> function scale($scale)
> {
> $width = $this->getWidth() * $scale / 100;
> $height = $this->getheight() * $scale / 100;
> $this->resize($width, $height);
> }
>
> function resize($width, $height)
> {
> $new_image = imagecreatetruecolor($width, $height);
> imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width,
> $height, $this->getWidth() , $this->getHeight());
> $this->image = $new_image;
> }
> }
>
> function get_basename($filename)
> {
> return preg_replace('/^.+[\\\\\\/]/', '', $filename);
> }
>
> function Stefano_Resizer($get_remote,$get_width, $get_height) {
> $full_path = getcwd();
> $ar = explode("wp-", $full_path);
> $root = $ar[0];
> $get_local = '/wp-content/uploads/images/'.get_basename($get_remote);
> $get_local_file = $root .'/wp-
> content/uploads/images/'.get_basename($get_remote);
> $image = new ResizeThat();
> if(file_exists ($get_local_file)){
> return $get_local;
> } else {
> $image->load($get_remote);
> $image->resizeToWidth($get_width);
> //$image->resizeToHeight($get_height);
> $image->save($get_local_file);
> return $get_local;
> }
> }
>
> its work and make a copy of listed images into declare folder of Stefano
> function.
>
> Would You fix that please?
> We don't like add any functions because we use widely Wordpress and
> maintaining a code that way would be problematic in a future.
> Btw. my head of development didn't allow to add new functionality so i
> try rise a problem here.
>
> Kind regards
> Stefan Oliwa
> Web Developer and Clifton Group PLC.
New description:
Stop working after updates;
One of our staff member report to me bug: problem with images in IE11.
I didn't notice that in firefox or chrome because images was resize to
width and height set in img tag => `<img src="some image" width="300"
height="180" alt.. >`
but physical size of image is different the image have 1900 pixels width
and 1028 pixels height, and was weight approx 550kb, its really slow down
a website when we listing wordpress posts with feature image (which is so
big right now) and our case study.
I fix this by adding own resizing function and simply class, I declare in
blog
instead of:
{{{
the_post_thumbnail('medium', array('class' => 'media-object'));
}}}
this:
{{{
$get_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID));
$local_small = Stefano_Resizer($get_url,300, 170);
}}}
and in my theme functions.php:
{{{
/RESIZE IMAGE
class ResizeThat
{
var $image;
var $image_type;
function load($filename)
{
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if ($this->image_type == IMAGETYPE_JPEG)
{
$this->image = imagecreatefromjpeg($filename);
}
elseif ($this->image_type == IMAGETYPE_GIF)
{
$this->image = imagecreatefromgif($filename);
}
elseif ($this->image_type == IMAGETYPE_PNG)
{
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type = IMAGETYPE_JPEG, $compression = 64,
$permissions = null)
{
if ($image_type == IMAGETYPE_JPEG)
{
imagejpeg($this->image, $filename, $compression);
}
elseif ($image_type == IMAGETYPE_GIF)
{
imagegif($this->image, $filename);
}
elseif ($image_type == IMAGETYPE_PNG)
{
imagepng($this->image, $filename);
}
if ($permissions != null)
{
chmod($filename, $permissions);
}
}
function output($image_type = IMAGETYPE_JPEG)
{
if ($image_type == IMAGETYPE_JPEG)
{
imagejpeg($this->image);
}
elseif ($image_type == IMAGETYPE_GIF)
{
imagegif($this->image);
}
elseif ($image_type == IMAGETYPE_PNG)
{
imagepng($this->image);
}
}
function getWidth()
{
return imagesx($this->image);
}
function getHeight()
{
return imagesy($this->image);
}
function resizeToHeight($height)
{
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width, $height);
}
function resizeToWidth($width)
{
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width, $height);
}
function scale($scale)
{
$width = $this->getWidth() * $scale / 100;
$height = $this->getheight() * $scale / 100;
$this->resize($width, $height);
}
function resize($width, $height)
{
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width,
$height, $this->getWidth() , $this->getHeight());
$this->image = $new_image;
}
}
function get_basename($filename)
{
return preg_replace('/^.+[\\\\\\/]/', '', $filename);
}
function Stefano_Resizer($get_remote,$get_width, $get_height) {
$full_path = getcwd();
$ar = explode("wp-", $full_path);
$root = $ar[0];
$get_local = '/wp-content/uploads/images/'.get_basename($get_remote);
$get_local_file = $root .'/wp-
content/uploads/images/'.get_basename($get_remote);
$image = new ResizeThat();
if(file_exists ($get_local_file)){
return $get_local;
} else {
$image->load($get_remote);
$image->resizeToWidth($get_width);
//$image->resizeToHeight($get_height);
$image->save($get_local_file);
return $get_local;
}
}
}}}
its work and make a copy of listed images into declare folder of Stefano
function.
Would You fix that please?
We don't like add any functions because we use widely Wordpress and
maintaining a code that way would be problematic in a future.
Btw. my head of development didn't allow to add new functionality so i try
rise a problem here.
Kind regards
Stefan Oliwa
Web Developer and Clifton Group PLC.
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28561#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list