How i can resize Images with imagescale in PHP












-1















i tried to resize an image with following method:



code



$thumbimg = $img->resizeImage($thumb, 200, 200);

public function resizeImage($imagePath,$new_width,$new_height) {

$fileName = pathinfo($imagePath,PATHINFO_FILENAME);
$ext = pathinfo($imagePath,PATHINFO_EXTENSION);
$fullPath = pathinfo($imagePath,PATHINFO_DIRNAME)."/".$fileName.'.'.$ext;
if (file_exists($fullPath)) {
return $fullPath;
}
$image = $this->openImage($imagePath);
if ($image == false) {
return null;
}
$width = imagesx($image);
$height = imagesy($image);
$imageResized = imagecreatetruecolor($width, $height);

if ($imageResized == false) {
return null;
}
$image = imagecreatetruecolor($width , $height);

$imageResized = imagescale($image,$new_width,$new_height);
touch($fullPath);
$write = imagepng($imageResized,$fullPath);
if (!$write) {
imagedestroy($imageResized);
return null;
}
imagedestroy($imageResized);
return $fullPath;
}


Actual its saves my images in the original width and height. But why? Whats wrong?










share|improve this question




















  • 1





    Have you checked your logs for error messages?

    – Difster
    Dec 31 '18 at 11:30











  • We don't even know $this->openImage(). And it's off-topic (why isn't code working).

    – digijay
    Dec 31 '18 at 11:40













  • yes, no errors @Difster

    – Daniel Richter
    Dec 31 '18 at 11:42






  • 1





    Rather add code to your question by using the edit button. And most probably you don't get errors because they are suppressed by @, remove them.

    – digijay
    Dec 31 '18 at 11:46








  • 1





    Please note that file systems can be case sensitive, so using strtolower() might not be the best idea. You could actually end up changing a correct path to a non-existing one.

    – Arjan
    Dec 31 '18 at 11:47
















-1















i tried to resize an image with following method:



code



$thumbimg = $img->resizeImage($thumb, 200, 200);

public function resizeImage($imagePath,$new_width,$new_height) {

$fileName = pathinfo($imagePath,PATHINFO_FILENAME);
$ext = pathinfo($imagePath,PATHINFO_EXTENSION);
$fullPath = pathinfo($imagePath,PATHINFO_DIRNAME)."/".$fileName.'.'.$ext;
if (file_exists($fullPath)) {
return $fullPath;
}
$image = $this->openImage($imagePath);
if ($image == false) {
return null;
}
$width = imagesx($image);
$height = imagesy($image);
$imageResized = imagecreatetruecolor($width, $height);

if ($imageResized == false) {
return null;
}
$image = imagecreatetruecolor($width , $height);

$imageResized = imagescale($image,$new_width,$new_height);
touch($fullPath);
$write = imagepng($imageResized,$fullPath);
if (!$write) {
imagedestroy($imageResized);
return null;
}
imagedestroy($imageResized);
return $fullPath;
}


Actual its saves my images in the original width and height. But why? Whats wrong?










share|improve this question




















  • 1





    Have you checked your logs for error messages?

    – Difster
    Dec 31 '18 at 11:30











  • We don't even know $this->openImage(). And it's off-topic (why isn't code working).

    – digijay
    Dec 31 '18 at 11:40













  • yes, no errors @Difster

    – Daniel Richter
    Dec 31 '18 at 11:42






  • 1





    Rather add code to your question by using the edit button. And most probably you don't get errors because they are suppressed by @, remove them.

    – digijay
    Dec 31 '18 at 11:46








  • 1





    Please note that file systems can be case sensitive, so using strtolower() might not be the best idea. You could actually end up changing a correct path to a non-existing one.

    – Arjan
    Dec 31 '18 at 11:47














-1












-1








-1








i tried to resize an image with following method:



code



$thumbimg = $img->resizeImage($thumb, 200, 200);

public function resizeImage($imagePath,$new_width,$new_height) {

$fileName = pathinfo($imagePath,PATHINFO_FILENAME);
$ext = pathinfo($imagePath,PATHINFO_EXTENSION);
$fullPath = pathinfo($imagePath,PATHINFO_DIRNAME)."/".$fileName.'.'.$ext;
if (file_exists($fullPath)) {
return $fullPath;
}
$image = $this->openImage($imagePath);
if ($image == false) {
return null;
}
$width = imagesx($image);
$height = imagesy($image);
$imageResized = imagecreatetruecolor($width, $height);

if ($imageResized == false) {
return null;
}
$image = imagecreatetruecolor($width , $height);

$imageResized = imagescale($image,$new_width,$new_height);
touch($fullPath);
$write = imagepng($imageResized,$fullPath);
if (!$write) {
imagedestroy($imageResized);
return null;
}
imagedestroy($imageResized);
return $fullPath;
}


Actual its saves my images in the original width and height. But why? Whats wrong?










share|improve this question
















i tried to resize an image with following method:



code



$thumbimg = $img->resizeImage($thumb, 200, 200);

public function resizeImage($imagePath,$new_width,$new_height) {

$fileName = pathinfo($imagePath,PATHINFO_FILENAME);
$ext = pathinfo($imagePath,PATHINFO_EXTENSION);
$fullPath = pathinfo($imagePath,PATHINFO_DIRNAME)."/".$fileName.'.'.$ext;
if (file_exists($fullPath)) {
return $fullPath;
}
$image = $this->openImage($imagePath);
if ($image == false) {
return null;
}
$width = imagesx($image);
$height = imagesy($image);
$imageResized = imagecreatetruecolor($width, $height);

if ($imageResized == false) {
return null;
}
$image = imagecreatetruecolor($width , $height);

$imageResized = imagescale($image,$new_width,$new_height);
touch($fullPath);
$write = imagepng($imageResized,$fullPath);
if (!$write) {
imagedestroy($imageResized);
return null;
}
imagedestroy($imageResized);
return $fullPath;
}


Actual its saves my images in the original width and height. But why? Whats wrong?







php image






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 11:28









Sanu0786

544715




544715










asked Dec 31 '18 at 11:24









Daniel RichterDaniel Richter

117




117








  • 1





    Have you checked your logs for error messages?

    – Difster
    Dec 31 '18 at 11:30











  • We don't even know $this->openImage(). And it's off-topic (why isn't code working).

    – digijay
    Dec 31 '18 at 11:40













  • yes, no errors @Difster

    – Daniel Richter
    Dec 31 '18 at 11:42






  • 1





    Rather add code to your question by using the edit button. And most probably you don't get errors because they are suppressed by @, remove them.

    – digijay
    Dec 31 '18 at 11:46








  • 1





    Please note that file systems can be case sensitive, so using strtolower() might not be the best idea. You could actually end up changing a correct path to a non-existing one.

    – Arjan
    Dec 31 '18 at 11:47














  • 1





    Have you checked your logs for error messages?

    – Difster
    Dec 31 '18 at 11:30











  • We don't even know $this->openImage(). And it's off-topic (why isn't code working).

    – digijay
    Dec 31 '18 at 11:40













  • yes, no errors @Difster

    – Daniel Richter
    Dec 31 '18 at 11:42






  • 1





    Rather add code to your question by using the edit button. And most probably you don't get errors because they are suppressed by @, remove them.

    – digijay
    Dec 31 '18 at 11:46








  • 1





    Please note that file systems can be case sensitive, so using strtolower() might not be the best idea. You could actually end up changing a correct path to a non-existing one.

    – Arjan
    Dec 31 '18 at 11:47








1




1





Have you checked your logs for error messages?

– Difster
Dec 31 '18 at 11:30





Have you checked your logs for error messages?

– Difster
Dec 31 '18 at 11:30













We don't even know $this->openImage(). And it's off-topic (why isn't code working).

– digijay
Dec 31 '18 at 11:40







We don't even know $this->openImage(). And it's off-topic (why isn't code working).

– digijay
Dec 31 '18 at 11:40















yes, no errors @Difster

– Daniel Richter
Dec 31 '18 at 11:42





yes, no errors @Difster

– Daniel Richter
Dec 31 '18 at 11:42




1




1





Rather add code to your question by using the edit button. And most probably you don't get errors because they are suppressed by @, remove them.

– digijay
Dec 31 '18 at 11:46







Rather add code to your question by using the edit button. And most probably you don't get errors because they are suppressed by @, remove them.

– digijay
Dec 31 '18 at 11:46






1




1





Please note that file systems can be case sensitive, so using strtolower() might not be the best idea. You could actually end up changing a correct path to a non-existing one.

– Arjan
Dec 31 '18 at 11:47





Please note that file systems can be case sensitive, so using strtolower() might not be the best idea. You could actually end up changing a correct path to a non-existing one.

– Arjan
Dec 31 '18 at 11:47












1 Answer
1






active

oldest

votes


















0














If $imagePath refers to an existing image, then $fullPath will refer to that same file. So either the file exists, in which case it is returned, or the file does not exist, in which case you can't open the image and null is returned. Either way, the image resize code is not used.






share|improve this answer
























  • aaaah thx. i'll try this.

    – Daniel Richter
    Dec 31 '18 at 11:46











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53986879%2fhow-i-can-resize-images-with-imagescale-in-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If $imagePath refers to an existing image, then $fullPath will refer to that same file. So either the file exists, in which case it is returned, or the file does not exist, in which case you can't open the image and null is returned. Either way, the image resize code is not used.






share|improve this answer
























  • aaaah thx. i'll try this.

    – Daniel Richter
    Dec 31 '18 at 11:46
















0














If $imagePath refers to an existing image, then $fullPath will refer to that same file. So either the file exists, in which case it is returned, or the file does not exist, in which case you can't open the image and null is returned. Either way, the image resize code is not used.






share|improve this answer
























  • aaaah thx. i'll try this.

    – Daniel Richter
    Dec 31 '18 at 11:46














0












0








0







If $imagePath refers to an existing image, then $fullPath will refer to that same file. So either the file exists, in which case it is returned, or the file does not exist, in which case you can't open the image and null is returned. Either way, the image resize code is not used.






share|improve this answer













If $imagePath refers to an existing image, then $fullPath will refer to that same file. So either the file exists, in which case it is returned, or the file does not exist, in which case you can't open the image and null is returned. Either way, the image resize code is not used.







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 31 '18 at 11:44









ArjanArjan

8,37612132




8,37612132













  • aaaah thx. i'll try this.

    – Daniel Richter
    Dec 31 '18 at 11:46



















  • aaaah thx. i'll try this.

    – Daniel Richter
    Dec 31 '18 at 11:46

















aaaah thx. i'll try this.

– Daniel Richter
Dec 31 '18 at 11:46





aaaah thx. i'll try this.

– Daniel Richter
Dec 31 '18 at 11:46


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53986879%2fhow-i-can-resize-images-with-imagescale-in-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas