简体   繁体   English

裁剪图像旋转并保存-PHP

[英]crop image rotate and save - php

I want to rotate my crop image and then save. 我想旋转我的裁剪图像,然后保存。 But its not working. 但是它不起作用。

<?php

 $newNamePrefix = $newname;
        $manipulator = new ImageManipulator($_FILES['blogo']['tmp_name']);

        $width  = $manipulator->getWidth();
        $height = $manipulator->getHeight();

        $min= min($width ,$height);
        $max= max($width ,$height);

        $n=$min/800;
        $d=$max/$n;
        $newImage = $manipulator->resample($d,$d);
        $newImage2 =  $newImage->crop(0, 0, 800, 600);

        // saving file to uploads folder
        $manipulator->save('uploads/stores/'.$formData['url'] .'/'.  $newNamePrefix.$fileExtension );
        return $newname.$fileExtension;

?>

I tried this below code but it didn't work. 我在下面的代码中尝试了此方法,但是没有用。

    $degrees = 90;
    $filename = $newImage2;
    $source = imagecreatefromjpeg( $filename );
    $rotate = imagerotate( $source, $degrees, 0 );
    $fileName = 'uploads/stores/'.$formData['url'] .'/'.  $newNamePrefix.$fileExtension;
    // Output
    imagejpeg( $rotate, $fileName, 100 );

If i use $filename = $_FILES['blogo']['tmp_name'] it works but if i use $filename = $newImage2; 如果我使用$filename = $_FILES['blogo']['tmp_name']可以使用,但是如果我使用$filename = $newImage2; then it doesn't. 那不是。 I am doing this first time so I have no idea whats the right way to do it. 我是第一次这样做,所以我不知道正确的方法是什么。

It is because $_FILES['blogo']['tmp_name'] is a valid name whereas $newImage2 is not... Try to do something like: 这是因为$ _FILES ['blogo'] ['tmp_name']是有效名称,而$ newImage2不是...请尝试执行以下操作:

echo $newImage2;

And you will understand what I mean. 您将理解我的意思。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM